Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ Update comparison with the `time` crate in the Jiff documentation.
* [#502](https://github.com/BurntSushi/jiff/issues/502):
Enable some non-default features for the Rust Playground deployment.

Bug fixes:

* [#486](https://github.com/BurntSushi/jiff/issues/486):
Make `%^c` result in uppercase strings where appropriate.


0.2.19 (2026-02-05)
===================
Expand Down
32 changes: 24 additions & 8 deletions src/fmt/strtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -668,11 +668,15 @@ pub trait Custom: Sized {
fn format_datetime<W: Write>(
&self,
config: &Config<Self>,
_ext: &Extension,
ext: &Extension,
tm: &BrokenDownTime,
wtr: &mut W,
) -> Result<(), Error> {
tm.format_with_config(config, "%Y M%m %-d, %a %H:%M:%S", wtr)
if matches!(ext.flag, Some(Flag::Uppercase)) {
tm.format_with_config(config, "%Y M%m %-d, %^a %H:%M:%S", wtr)
} else {
tm.format_with_config(config, "%Y M%m %-d, %a %H:%M:%S", wtr)
}
}

/// Called when formatting a datetime with the `%x` flag.
Expand Down Expand Up @@ -708,11 +712,15 @@ pub trait Custom: Sized {
fn format_12hour_time<W: Write>(
&self,
config: &Config<Self>,
_ext: &Extension,
ext: &Extension,
tm: &BrokenDownTime,
wtr: &mut W,
) -> Result<(), Error> {
tm.format_with_config(config, "%-I:%M:%S %p", wtr)
if matches!(ext.flag, Some(Flag::Uppercase)) {
tm.format_with_config(config, "%-I:%M:%S %^p", wtr)
} else {
tm.format_with_config(config, "%-I:%M:%S %p", wtr)
}
}
}

Expand Down Expand Up @@ -791,11 +799,15 @@ impl Custom for PosixCustom {
fn format_datetime<W: Write>(
&self,
config: &Config<Self>,
_ext: &Extension,
ext: &Extension,
tm: &BrokenDownTime,
wtr: &mut W,
) -> Result<(), Error> {
tm.format_with_config(config, "%a %b %e %H:%M:%S %Y", wtr)
if matches!(ext.flag, Some(Flag::Uppercase)) {
tm.format_with_config(config, "%^a %^b %e %H:%M:%S %Y", wtr)
} else {
tm.format_with_config(config, "%a %b %e %H:%M:%S %Y", wtr)
}
}

fn format_date<W: Write>(
Expand All @@ -821,11 +833,15 @@ impl Custom for PosixCustom {
fn format_12hour_time<W: Write>(
&self,
config: &Config<Self>,
_ext: &Extension,
ext: &Extension,
tm: &BrokenDownTime,
wtr: &mut W,
) -> Result<(), Error> {
tm.format_with_config(config, "%I:%M:%S %p", wtr)
if matches!(ext.flag, Some(Flag::Uppercase)) {
tm.format_with_config(config, "%I:%M:%S %^p", wtr)
} else {
tm.format_with_config(config, "%I:%M:%S %p", wtr)
}
}
}

Expand Down
22 changes: 22 additions & 0 deletions src/fmt/strtime/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1421,6 +1421,28 @@ mod tests {
);
}

#[test]
fn ok_format_compound_uppercase() {
let f = |fmt: &str, date: DateTime| format(fmt, date).unwrap();

insta::assert_snapshot!(
f("%^c", date(2024, 7, 14).at(0, 0, 0, 0)),
@"2024 M07 14, SUN 00:00:00",
);
insta::assert_snapshot!(
f("%^x", date(2024, 7, 14).at(0, 0, 0, 0)),
@"2024 M07 14",
);
insta::assert_snapshot!(
f("%^X", date(2024, 7, 14).at(8, 30, 0, 0)),
@"08:30:00",
);
insta::assert_snapshot!(
f("%^r", date(2024, 7, 14).at(8, 30, 0, 0)),
@"8:30:00 AM",
);
}

#[test]
fn ok_format_posix_locale() {
let f = |fmt: &str, date: DateTime| {
Expand Down