Quellcode durchsuchen

Use only the time zone data present on the system

Thinking about it, it doesn't make sense to use an *external* time zone source when the program we want to compare it to, ls, uses the system one. So just use the system one.

Also, handle the case where the time zone data file can't be loaded by showing the files in UTC rather than falling over and quitting.
Ben S vor 10 Jahren
Ursprung
Commit
ee4c09dd30
4 geänderte Dateien mit 29 neuen und 51 gelöschten Zeilen
  1. 0 24
      Cargo.lock
  2. 0 3
      Cargo.toml
  3. 0 1
      src/main.rs
  4. 29 23
      src/output/details.rs

+ 0 - 24
Cargo.lock

@@ -18,7 +18,6 @@ dependencies = [
  "unicode-width 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
  "unicode-width 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
  "users 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "users 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "zoneinfo_compiled 0.2.1 (git+https://github.com/rust-datetime/zoneinfo-compiled.git)",
  "zoneinfo_compiled 0.2.1 (git+https://github.com/rust-datetime/zoneinfo-compiled.git)",
- "zoneinfo_data 0.1.0 (git+https://github.com/rust-datetime/zoneinfo-data.git)",
 ]
 ]
 
 
 [[package]]
 [[package]]
@@ -216,19 +215,6 @@ dependencies = [
  "unicode-width 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
  "unicode-width 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 ]
 
 
-[[package]]
-name = "phf"
-version = "0.7.14"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-dependencies = [
- "phf_shared 0.7.14 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
-[[package]]
-name = "phf_shared"
-version = "0.7.14"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-
 [[package]]
 [[package]]
 name = "pkg-config"
 name = "pkg-config"
 version = "0.3.8"
 version = "0.3.8"
@@ -336,13 +322,3 @@ dependencies = [
  "datetime 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
  "datetime 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 ]
 
 
-[[package]]
-name = "zoneinfo_data"
-version = "0.1.0"
-source = "git+https://github.com/rust-datetime/zoneinfo-data.git#6807bb6be1a444f8133dd62c3af5d1dcffb46bee"
-dependencies = [
- "datetime 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
- "locale 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
- "phf 0.7.14 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-

+ 0 - 3
Cargo.toml

@@ -35,8 +35,5 @@ lto = true
 version = "0.3.2"
 version = "0.3.2"
 optional = true
 optional = true
 
 
-[dependencies.zoneinfo_data]
-git = "https://github.com/rust-datetime/zoneinfo-data.git"
-
 [dependencies.zoneinfo_compiled]
 [dependencies.zoneinfo_compiled]
 git = "https://github.com/rust-datetime/zoneinfo-compiled.git"
 git = "https://github.com/rust-datetime/zoneinfo-compiled.git"

+ 0 - 1
src/main.rs

@@ -15,7 +15,6 @@ extern crate term_grid;
 extern crate unicode_width;
 extern crate unicode_width;
 extern crate users;
 extern crate users;
 extern crate zoneinfo_compiled;
 extern crate zoneinfo_compiled;
-extern crate zoneinfo_data;
 
 
 #[cfg(feature="git")] extern crate git2;
 #[cfg(feature="git")] extern crate git2;
 #[macro_use] extern crate lazy_static;
 #[macro_use] extern crate lazy_static;

+ 29 - 23
src/output/details.rs

@@ -83,7 +83,6 @@ use datetime::fmt::DateFormat;
 use datetime::{LocalDateTime, DatePiece};
 use datetime::{LocalDateTime, DatePiece};
 use datetime::TimeZone;
 use datetime::TimeZone;
 use zoneinfo_compiled::{CompiledData, Result as TZResult};
 use zoneinfo_compiled::{CompiledData, Result as TZResult};
-use zoneinfo_data::ZoneinfoData;
 
 
 use locale;
 use locale;
 
 
@@ -157,7 +156,7 @@ pub struct Environment<U: Users+Groups> {
 
 
     /// The computer's current time zone. This gets used to determine how to
     /// The computer's current time zone. This gets used to determine how to
     /// offset files' timestamps.
     /// offset files' timestamps.
-    tz: TimeZone,
+    tz: Option<TimeZone>,
 
 
     /// Mapping cache of user IDs to usernames.
     /// Mapping cache of user IDs to usernames.
     users: Mutex<U>,
     users: Mutex<U>,
@@ -165,33 +164,24 @@ pub struct Environment<U: Users+Groups> {
 
 
 impl Default for Environment<UsersCache> {
 impl Default for Environment<UsersCache> {
     fn default() -> Self {
     fn default() -> Self {
-        use std::process::exit;
+        let tz = determine_time_zone();
 
 
-        let tz = match determine_time_zone() {
-            Ok(tz) => tz,
-            Err(e) => {
-                println!("Unable to determine time zone: {}", e);
-                exit(1);
-            },
-        };
+        if let Err(ref e) = tz {
+            println!("Unable to determine time zone: {}", e);
+        }
 
 
         Environment {
         Environment {
             current_year: LocalDateTime::now().year(),
             current_year: LocalDateTime::now().year(),
             numeric:      locale::Numeric::load_user_locale().unwrap_or_else(|_| locale::Numeric::english()),
             numeric:      locale::Numeric::load_user_locale().unwrap_or_else(|_| locale::Numeric::english()),
             time:         locale::Time::load_user_locale().unwrap_or_else(|_| locale::Time::english()),
             time:         locale::Time::load_user_locale().unwrap_or_else(|_| locale::Time::english()),
-            tz:           tz,
+            tz:           tz.ok(),
             users:        Mutex::new(UsersCache::new()),
             users:        Mutex::new(UsersCache::new()),
         }
         }
     }
     }
 }
 }
 
 
 fn determine_time_zone() -> TZResult<TimeZone> {
 fn determine_time_zone() -> TZResult<TimeZone> {
-    if let Some(system_zone) = TimeZone::system() {
-        Ok(system_zone)
-    }
-    else {
-        TimeZone::from_file("/etc/localtime")
-    }
+    TimeZone::from_file("/etc/localtime")
 }
 }
 
 
 impl Details {
 impl Details {
@@ -597,16 +587,34 @@ impl<'a, U: Users+Groups+'a> Table<'a, U> {
 
 
     #[allow(trivial_numeric_casts)]
     #[allow(trivial_numeric_casts)]
     fn render_time(&self, timestamp: f::Time) -> TextCell {
     fn render_time(&self, timestamp: f::Time) -> TextCell {
-        let date = self.env.tz.to_zoned(LocalDateTime::at(timestamp.0 as i64));
+        // TODO(ogham): This method needs some serious de-duping!
+        // zoned and local times have different types at the moment,
+        // so it's tricky.
+
+        if let Some(ref tz) = self.env.tz {
+            let date = tz.to_zoned(LocalDateTime::at(timestamp.0 as i64));
 
 
-        let datestamp = if date.year() == self.env.current_year {
+            let datestamp = if date.year() == self.env.current_year {
                 DATE_AND_TIME.format(&date, &self.env.time)
                 DATE_AND_TIME.format(&date, &self.env.time)
             }
             }
             else {
             else {
                 DATE_AND_YEAR.format(&date, &self.env.time)
                 DATE_AND_YEAR.format(&date, &self.env.time)
             };
             };
 
 
-        TextCell::paint(self.opts.colours.date, datestamp)
+            TextCell::paint(self.opts.colours.date, datestamp)
+        }
+        else {
+            let date = LocalDateTime::at(timestamp.0 as i64);
+
+            let datestamp = if date.year() == self.env.current_year {
+                DATE_AND_TIME.format(&date, &self.env.time)
+            }
+            else {
+                DATE_AND_YEAR.format(&date, &self.env.time)
+            };
+
+            TextCell::paint(self.opts.colours.date, datestamp)
+        }
     }
     }
 
 
     fn render_git_status(&self, git: f::Git) -> TextCell {
     fn render_git_status(&self, git: f::Git) -> TextCell {
@@ -750,8 +758,6 @@ pub mod test {
     impl Default for Environment<MockUsers> {
     impl Default for Environment<MockUsers> {
         fn default() -> Self {
         fn default() -> Self {
             use locale;
             use locale;
-            use datetime::TimeZone;
-            use zoneinfo_data::ZoneinfoData;
             use users::mock::MockUsers;
             use users::mock::MockUsers;
             use std::sync::Mutex;
             use std::sync::Mutex;
 
 
@@ -759,7 +765,7 @@ pub mod test {
                 current_year: 1234,
                 current_year: 1234,
                 numeric:      locale::Numeric::english(),
                 numeric:      locale::Numeric::english(),
                 time:         locale::Time::english(),
                 time:         locale::Time::english(),
-                tz:           TimeZone::get("Europe/London").unwrap(),
+                tz:           None,
                 users:        Mutex::new(MockUsers::with_current_uid(0)),
                 users:        Mutex::new(MockUsers::with_current_uid(0)),
             }
             }
         }
         }