diff --git a/src/fs/file.rs b/src/fs/file.rs index 35b2940..5745208 100644 --- a/src/fs/file.rs +++ b/src/fs/file.rs @@ -325,37 +325,36 @@ impl<'dir> File<'dir> { } } - /// This file’s last modified timestamp. - /// If the file's time is invalid, assume it was modified at the epoch - pub fn modified_time(&self) -> SystemTime { - self.metadata.modified().unwrap_or(UNIX_EPOCH) + /// This file’s last modified timestamp, if available on this platform. + pub fn modified_time(&self) -> Option { + self.metadata.modified().ok() } - /// This file’s last changed timestamp. - pub fn changed_time(&self) -> SystemTime { + /// This file’s last changed timestamp, if available on this platform. + pub fn changed_time(&self) -> Option { let (mut sec, mut nsec) = (self.metadata.ctime(), self.metadata.ctime_nsec()); - if sec < 0 { // yeah right - if nsec > 0 { - sec += 1; - nsec = nsec - 1_000_000_000; - } - UNIX_EPOCH - Duration::new(sec.abs() as u64, nsec.abs() as u32) - } else { - UNIX_EPOCH + Duration::new(sec as u64, nsec as u32) - } + Some( + if sec < 0 { + if nsec > 0 { + sec += 1; + nsec = nsec - 1_000_000_000; + } + UNIX_EPOCH - Duration::new(sec.abs() as u64, nsec.abs() as u32) + } else { + UNIX_EPOCH + Duration::new(sec as u64, nsec as u32) + } + ) } - /// This file’s last accessed timestamp. - /// If the file's time is invalid, assume it was accessed at the epoch - pub fn accessed_time(&self) -> SystemTime { - self.metadata.accessed().unwrap_or(UNIX_EPOCH) + /// This file’s last accessed timestamp, if available on this platform. + pub fn accessed_time(&self) -> Option { + self.metadata.accessed().ok() } - /// This file’s created timestamp. - /// If the file's time is invalid, assume it was created at the epoch - pub fn created_time(&self) -> SystemTime { - self.metadata.created().unwrap_or(UNIX_EPOCH) + /// This file’s created timestamp, if available on this platform. + pub fn created_time(&self) -> Option { + self.metadata.created().ok() } /// This file’s ‘type’. diff --git a/src/output/render/times.rs b/src/output/render/times.rs index 2b3d000..135be35 100644 --- a/src/output/render/times.rs +++ b/src/output/render/times.rs @@ -11,18 +11,21 @@ pub trait Render { format: &TimeFormat) -> TextCell; } -impl Render for std::time::SystemTime { +impl Render for Option { fn render(self, style: Style, tz: &Option, format: &TimeFormat) -> TextCell { - if let Some(ref tz) = *tz { - let datestamp = format.format_zoned(self, tz); - TextCell::paint(style, datestamp) - } - else { - let datestamp = format.format_local(self); - TextCell::paint(style, datestamp) - } + let datestamp = if let Some(time) = self { + if let Some(ref tz) = tz { + format.format_zoned(time, tz) + } else { + format.format_local(time) + } + } else { + String::from("-") + }; + + TextCell::paint(style, datestamp) } } diff --git a/src/output/time.rs b/src/output/time.rs index 13a6a1d..b168c6b 100644 --- a/src/output/time.rs +++ b/src/output/time.rs @@ -147,9 +147,6 @@ impl DefaultFormat { #[allow(trivial_numeric_casts)] fn format_local(&self, time: SystemTime) -> String { - if time == UNIX_EPOCH { - return "-".to_string(); - } let date = LocalDateTime::at(systemtime_epoch(time)); if self.is_recent(date) { @@ -164,10 +161,6 @@ impl DefaultFormat { #[allow(trivial_numeric_casts)] fn format_zoned(&self, time: SystemTime, zone: &TimeZone) -> String { - if time == UNIX_EPOCH { - return "-".to_string(); - } - let date = zone.to_zoned(LocalDateTime::at(systemtime_epoch(time))); if self.is_recent(date) {