From 7f480ab06bd6337f898e28cca42a3cc454048e61 Mon Sep 17 00:00:00 2001 From: Ben S Date: Wed, 10 Feb 2016 19:02:20 +0000 Subject: Improve system time zone detection --- src/output/details.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/output') diff --git a/src/output/details.rs b/src/output/details.rs index a6ff7da..cea6bc4 100644 --- a/src/output/details.rs +++ b/src/output/details.rs @@ -82,6 +82,7 @@ use ansi_term::Style; use datetime::fmt::DateFormat; use datetime::{LocalDateTime, DatePiece}; use datetime::TimeZone; +use zoneinfo_compiled::CompiledData; use zoneinfo_data::ZoneinfoData; use locale; @@ -168,12 +169,21 @@ impl Default for Environment { current_year: LocalDateTime::now().year(), numeric: locale::Numeric::load_user_locale().unwrap_or_else(|_| locale::Numeric::english()), time: locale::Time::load_user_locale().unwrap_or_else(|_| locale::Time::english()), - tz: TimeZone::system().expect("Unable to determine time zone"), + tz: determine_time_zone().expect("Unable to determine time zone"), users: Mutex::new(UsersCache::new()), } } } +fn determine_time_zone() -> Result { + if let Some(system_zone) = TimeZone::system() { + Ok(system_zone) + } + else { + TimeZone::from_file("/etc/localtime") + } +} + impl Details { /// Print the details of the given vector of files -- all of which will -- cgit v1.2.3