1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

ls: Simplify TimeStyle::format

Also, the comment does not fully apply anymore, so we can leave
it more open-ended to figure out how to support locale.
This commit is contained in:
Nicolas Boichat 2025-06-01 19:36:58 +02:00
parent 986bdf545d
commit 5d75e28b87

View file

@ -292,22 +292,18 @@ impl TimeStyle {
let mut out = StdIoWrite(out); let mut out = StdIoWrite(out);
let config = jiff::fmt::strtime::Config::new().lenient(true); let config = jiff::fmt::strtime::Config::new().lenient(true);
match (self, recent) { let fmt = match (self, recent) {
(Self::FullIso, _) => { (Self::FullIso, _) => "%Y-%m-%d %H:%M:%S.%f %z",
tm.format_with_config(&config, "%Y-%m-%d %H:%M:%S.%f %z", &mut out) (Self::LongIso, _) => "%Y-%m-%d %H:%M",
} (Self::Iso, true) => "%m-%d %H:%M",
(Self::LongIso, _) => tm.format_with_config(&config, "%Y-%m-%d %H:%M", &mut out), (Self::Iso, false) => "%Y-%m-%d ",
(Self::Iso, true) => tm.format_with_config(&config, "%m-%d %H:%M", &mut out), // TODO: Using correct locale string is not implemented.
(Self::Iso, false) => tm.format_with_config(&config, "%Y-%m-%d ", &mut out), (Self::Locale, true) => "%b %e %H:%M",
// spell-checker:ignore (word) datetime (Self::Locale, false) => "%b %e %Y",
//In this version of chrono translating can be done (Self::Format(fmt), _) => fmt,
//The function is chrono::datetime::DateTime::format_localized };
//However it's currently still hard to get the current pure-rust-locale
//So it's not yet implemented tm.format_with_config(&config, fmt, &mut out)
(Self::Locale, true) => tm.format_with_config(&config, "%b %e %H:%M", &mut out),
(Self::Locale, false) => tm.format_with_config(&config, "%b %e %Y", &mut out),
(Self::Format(fmt), _) => tm.format_with_config(&config, fmt, &mut out),
}
} }
} }