Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 05e87d2

Browse filesBrowse files
committed
uucore: custom_tz_fmt: Improve TZ environment variable handling
iana_time_zone::get_timezone doesn't cover all cases, so we need to handle some of the timezone parsing manually. Also add a bunch of TODO, this function is by no means complete. (change similar to uutils#7597 for this file)
1 parent a423041 commit 05e87d2
Copy full SHA for 05e87d2

File tree

1 file changed

+17
-2
lines changed
Filter options

1 file changed

+17
-2
lines changed

‎src/uucore/src/lib/features/custom_tz_fmt.rs

Copy file name to clipboardExpand all lines: src/uucore/src/lib/features/custom_tz_fmt.rs
+17-2Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,27 @@ use iana_time_zone::get_timezone;
1010
/// Get the alphabetic abbreviation of the current timezone.
1111
///
1212
/// For example, "UTC" or "CET" or "PDT"
13+
//
14+
/// We need this function even for local dates as chrono(_tz) does not provide a
15+
/// way to convert Local to a fully specified timezone with abbreviation
16+
/// (<https://github.com/chronotope/chrono-tz/issues/13>).
17+
//
18+
// TODO(#7659): This should take into account the date to be printed.
19+
// - Timezone abbreviation depends on daylight savings.
20+
// - We should do no special conversion for UTC dates.
21+
// - If our custom logic fails, but chrono obtained a non-UTC local timezone
22+
// from the system, we should not just return UTC.
1323
fn timezone_abbreviation() -> String {
24+
// We need this logic as `iana_time_zone::get_timezone` does not look
25+
// at TZ variable: https://github.com/strawlab/iana-time-zone/issues/118.
1426
let tz = match std::env::var("TZ") {
15-
// TODO Support other time zones...
27+
// TODO: This is not fully exhaustive, we should understand how to handle
28+
// invalid TZ values and more complex POSIX-specified values:
29+
// https://www.gnu.org/software/libc/manual/html_node/TZ-Variable.html
1630
Ok(s) if s == "UTC0" || s.is_empty() => Tz::Etc__UTC,
31+
Ok(s) => s.parse().unwrap_or(Tz::Etc__UTC),
1732
_ => match get_timezone() {
18-
Ok(tz_str) => tz_str.parse().unwrap(),
33+
Ok(tz_str) => tz_str.parse().unwrap_or(Tz::Etc__UTC),
1934
Err(_) => Tz::Etc__UTC,
2035
},
2136
};

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.