diff --git a/src/file.rs b/src/file.rs index a053521..e851405 100644 --- a/src/file.rs +++ b/src/file.rs @@ -10,14 +10,13 @@ use std::path::{Component, Path, PathBuf}; use unicode_width::UnicodeWidthStr; use dir::Dir; -use output::column::TimeType; use self::fields as f; -// Constant table copied from https://doc.rust-lang.org/src/std/sys/unix/ext/fs.rs.html#11-259 -// which is currently unstable and lacks vision for stabilization, -// see https://github.com/rust-lang/rust/issues/27712 +/// Constant table copied from https://doc.rust-lang.org/src/std/sys/unix/ext/fs.rs.html#11-259 +/// which is currently unstable and lacks vision for stabilization, +/// see https://github.com/rust-lang/rust/issues/27712 #[allow(dead_code)] mod modes { use std::os::unix::raw; @@ -281,15 +280,16 @@ impl<'dir> File<'dir> { } } - /// One of this file's timestamps, as a number in seconds. - pub fn timestamp(&self, time_type: TimeType) -> f::Time { - let time_in_seconds = match time_type { - TimeType::FileAccessed => self.metadata.atime(), - TimeType::FileModified => self.metadata.mtime(), - TimeType::FileCreated => self.metadata.ctime(), - }; + pub fn modified_time(&self) -> f::Time { + f::Time(self.metadata.mtime()) + } - f::Time(time_in_seconds) + pub fn created_time(&self) -> f::Time { + f::Time(self.metadata.ctime()) + } + + pub fn accessed_time(&self) -> f::Time { + f::Time(self.metadata.mtime()) } /// This file's 'type'. diff --git a/src/output/column.rs b/src/output/column.rs index c0a87d5..c2b8568 100644 --- a/src/output/column.rs +++ b/src/output/column.rs @@ -99,15 +99,15 @@ impl Columns { } if self.time_types.modified { - columns.push(Column::Timestamp(TimeType::FileModified)); + columns.push(Column::Timestamp(TimeType::Modified)); } if self.time_types.created { - columns.push(Column::Timestamp(TimeType::FileCreated)); + columns.push(Column::Timestamp(TimeType::Created)); } if self.time_types.accessed { - columns.push(Column::Timestamp(TimeType::FileAccessed)); + columns.push(Column::Timestamp(TimeType::Accessed)); } if cfg!(feature="git") { @@ -152,13 +152,13 @@ impl Default for SizeFormat { pub enum TimeType { /// The file’s accessed time (`st_atime`). - FileAccessed, + Accessed, /// The file’s modified time (`st_mtime`). - FileModified, + Modified, /// The file’s creation time (`st_ctime`). - FileCreated, + Created, } impl TimeType { @@ -166,9 +166,9 @@ impl TimeType { /// Returns the text to use for a column’s heading in the columns output. pub fn header(&self) -> &'static str { match *self { - TimeType::FileAccessed => "Date Accessed", - TimeType::FileModified => "Date Modified", - TimeType::FileCreated => "Date Created", + TimeType::Accessed => "Date Accessed", + TimeType::Modified => "Date Modified", + TimeType::Created => "Date Created", } } } diff --git a/src/output/details.rs b/src/output/details.rs index 95886ad..7e9775f 100644 --- a/src/output/details.rs +++ b/src/output/details.rs @@ -486,16 +486,20 @@ impl Table where U: Users { } fn display(&mut self, file: &File, column: &Column, xattrs: bool) -> Cell { + use output::column::TimeType::*; + match *column { - Column::Permissions => self.render_permissions(file.permissions(), xattrs), - Column::FileSize(fmt) => self.render_size(file.size(), fmt), - Column::Timestamp(t) => self.render_time(file.timestamp(t)), - Column::HardLinks => self.render_links(file.links()), - Column::Inode => self.render_inode(file.inode()), - Column::Blocks => self.render_blocks(file.blocks()), - Column::User => self.render_user(file.user()), - Column::Group => self.render_group(file.group()), - Column::GitStatus => self.render_git_status(file.git_status()), + Column::Permissions => self.render_permissions(file.permissions(), xattrs), + Column::FileSize(fmt) => self.render_size(file.size(), fmt), + Column::Timestamp(Modified) => self.render_time(file.modified_time()), + Column::Timestamp(Created) => self.render_time(file.created_time()), + Column::Timestamp(Accessed) => self.render_time(file.accessed_time()), + Column::HardLinks => self.render_links(file.links()), + Column::Inode => self.render_inode(file.inode()), + Column::Blocks => self.render_blocks(file.blocks()), + Column::User => self.render_user(file.user()), + Column::Group => self.render_group(file.group()), + Column::GitStatus => self.render_git_status(file.git_status()), } }