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.
This commit is contained in:
Karey Higuera 2020-08-26 18:19:49 -05:00
parent 78ba0b8973
commit e8d69fc5e8

View File

@ -1,4 +1,5 @@
use std::cmp::max; use std::cmp::max;
use std::env;
use std::fmt; use std::fmt;
use std::ops::Deref; use std::ops::Deref;
use std::sync::{Mutex, MutexGuard}; use std::sync::{Mutex, MutexGuard};
@ -286,7 +287,12 @@ impl Environment {
} }
fn determine_time_zone() -> TZResult<TimeZone> { 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()));
}
} }