Timestamps

This commit is contained in:
Chester Liu 2021-03-26 18:40:22 +08:00
parent aeb4a679e8
commit 31583691d5
2 changed files with 31 additions and 11 deletions

View File

@ -374,6 +374,11 @@ impl<'dir> File<'dir> {
}
}
#[cfg(windows)]
pub fn changed_time(&self) -> Option<SystemTime> {
return self.modified_time()
}
/// This files last accessed timestamp, if available on this platform.
pub fn accessed_time(&self) -> Option<SystemTime> {
self.metadata.accessed().ok()

View File

@ -92,22 +92,18 @@ impl Columns {
}
if self.time_types.modified {
#[cfg(unix)]
columns.push(Column::Timestamp(TimeType::Modified));
}
if self.time_types.changed {
#[cfg(unix)]
columns.push(Column::Timestamp(TimeType::Changed));
}
if self.time_types.created {
#[cfg(unix)]
columns.push(Column::Timestamp(TimeType::Created));
}
if self.time_types.accessed {
#[cfg(unix)]
columns.push(Column::Timestamp(TimeType::Accessed));
}
@ -125,7 +121,6 @@ impl Columns {
pub enum Column {
Permissions,
FileSize,
#[cfg(unix)]
Timestamp(TimeType),
#[cfg(unix)]
Blocks,
@ -179,7 +174,6 @@ impl Column {
match self {
Self::Permissions => "Permissions",
Self::FileSize => "Size",
#[cfg(unix)]
Self::Timestamp(t) => t.header(),
#[cfg(unix)]
Self::Blocks => "Blocks",
@ -328,6 +322,7 @@ impl Environment {
}
}
#[cfg(unix)]
fn determine_time_zone() -> TZResult<TimeZone> {
if let Ok(file) = env::var("TZ") {
TimeZone::from_file(format!("/usr/share/zoneinfo/{}", file))
@ -337,6 +332,31 @@ fn determine_time_zone() -> TZResult<TimeZone> {
}
}
#[cfg(windows)]
fn determine_time_zone() -> TZResult<TimeZone> {
use datetime::zone::{FixedTimespan, FixedTimespanSet, StaticTimeZone, TimeZoneSource};
use std::borrow::Cow;
Ok(TimeZone(TimeZoneSource::Static(&StaticTimeZone {
name: "Unsupported",
fixed_timespans: FixedTimespanSet {
first: FixedTimespan {
offset: 0,
is_dst: false,
name: Cow::Borrowed("ZONE_A"),
},
rest: &[(
1206838800,
FixedTimespan {
offset: 3600,
is_dst: false,
name: Cow::Borrowed("ZONE_B"),
},
)],
},
})))
}
lazy_static! {
static ref ENVIRONMENT: Environment = Environment::load_all();
}
@ -449,20 +469,15 @@ impl<'a, 'f> Table<'a> {
Column::Octal => {
self.octal_permissions(file).render(self.theme.ui.octal)
}
#[cfg(unix)]
Column::Timestamp(TimeType::Modified) => {
file.modified_time().render(self.theme.ui.date, &self.env.tz, self.time_format)
}
#[cfg(unix)]
Column::Timestamp(TimeType::Changed) => {
file.changed_time().render(self.theme.ui.date, &self.env.tz, self.time_format)
}
#[cfg(unix)]
Column::Timestamp(TimeType::Created) => {
file.created_time().render(self.theme.ui.date, &self.env.tz, self.time_format)
}
#[cfg(unix)]
Column::Timestamp(TimeType::Accessed) => {
file.accessed_time().render(self.theme.ui.date, &self.env.tz, self.time_format)
}