From 57cf0f1b2329c2f160b2d5e44568097cf9e5045c Mon Sep 17 00:00:00 2001 From: PatriotRossii Date: Wed, 24 Mar 2021 17:36:13 +0500 Subject: [PATCH 1/3] Update determine_time_zone according to GNU manual --- src/output/table.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/output/table.rs b/src/output/table.rs index 50c7de7..f0172e6 100644 --- a/src/output/table.rs +++ b/src/output/table.rs @@ -292,9 +292,21 @@ impl Environment { fn determine_time_zone() -> TZResult { if let Ok(file) = env::var("TZ") { - TimeZone::from_file(format!("/usr/share/zoneinfo/{}", file)) - } - else { + TimeZone::from_file({ + if file.starts_with("/") { + file + } else { + format!("/usr/share/zoneinfo/{}", { + if file.starts_with(":") { + // Unwrap is panic-free here because we've checked if file starts with colon + file.strip_prefix(":").unwrap() + } else { + file.as_str() + } + }) + } + }) + } else { TimeZone::from_file("/etc/localtime") } } From 5743e6d8e3a763fadca2a745e118f4939213282c Mon Sep 17 00:00:00 2001 From: PatriotRossii Date: Wed, 24 Mar 2021 19:05:38 +0500 Subject: [PATCH 2/3] Replace strip_prefix with replace --- src/output/table.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/output/table.rs b/src/output/table.rs index f0172e6..7396d1e 100644 --- a/src/output/table.rs +++ b/src/output/table.rs @@ -298,10 +298,9 @@ fn determine_time_zone() -> TZResult { } else { format!("/usr/share/zoneinfo/{}", { if file.starts_with(":") { - // Unwrap is panic-free here because we've checked if file starts with colon - file.strip_prefix(":").unwrap() + file.replace(":", "") } else { - file.as_str() + file } }) } From 4e5e2ce8f0960c043a47cc6b99bf28ab9aa3f749 Mon Sep 17 00:00:00 2001 From: PatriotRossii Date: Thu, 25 Mar 2021 11:20:11 +0500 Subject: [PATCH 3/3] Replace "replace" with "replacen" --- src/output/table.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/output/table.rs b/src/output/table.rs index 7396d1e..7013207 100644 --- a/src/output/table.rs +++ b/src/output/table.rs @@ -298,7 +298,7 @@ fn determine_time_zone() -> TZResult { } else { format!("/usr/share/zoneinfo/{}", { if file.starts_with(":") { - file.replace(":", "") + file.replacen(":", "", 1) } else { file }