Просмотр исходного кода

Update determine_time_zone function to check TZ

Instead of defaulting immediately to /etc/filename for the timezone, we can first check whether the TZ environment variable is set. If so, we can pull the corresponding timezone file from /usr/share/zoneinfo. Closes #453.
Karey Higuera 5 лет назад
Родитель
Сommit
e8d69fc5e8
1 измененных файлов с 7 добавлено и 1 удалено
  1. 7 1
      src/output/table.rs

+ 7 - 1
src/output/table.rs

@@ -1,4 +1,5 @@
 use std::cmp::max;
+use std::env;
 use std::fmt;
 use std::ops::Deref;
 use std::sync::{Mutex, MutexGuard};
@@ -286,7 +287,12 @@ impl Environment {
 }
 
 fn determine_time_zone() -> TZResult<TimeZone> {
-    TimeZone::from_file("/etc/localtime")
+    let tz = env::var("TZ");
+    if tz.is_err() {
+        return TimeZone::from_file("/etc/localtime");
+    } else {
+        return TimeZone::from_file(format!("/usr/share/zoneinfo/{}", tz.unwrap()));
+    }
 }