提交 8b520edf 编写于 作者: B Ben S

Only display the year if it's last year

Otherwise, just display the hour and minute.
上级 bc7492e7
...@@ -8,7 +8,7 @@ use options::{SizeFormat, TimeType}; ...@@ -8,7 +8,7 @@ use options::{SizeFormat, TimeType};
pub enum Column { pub enum Column {
Permissions, Permissions,
FileSize(SizeFormat), FileSize(SizeFormat),
Timestamp(TimeType), Timestamp(TimeType, i64),
Blocks, Blocks,
User, User,
Group, Group,
...@@ -43,15 +43,15 @@ impl Column { ...@@ -43,15 +43,15 @@ impl Column {
/// to have a header row printed. /// to have a header row printed.
pub fn header(&self) -> &'static str { pub fn header(&self) -> &'static str {
match *self { match *self {
Column::Permissions => "Permissions", Column::Permissions => "Permissions",
Column::FileSize(_) => "Size", Column::FileSize(_) => "Size",
Column::Timestamp(t) => t.header(), Column::Timestamp(t, _) => t.header(),
Column::Blocks => "Blocks", Column::Blocks => "Blocks",
Column::User => "User", Column::User => "User",
Column::Group => "Group", Column::Group => "Group",
Column::HardLinks => "Links", Column::HardLinks => "Links",
Column::Inode => "inode", Column::Inode => "inode",
Column::GitStatus => "Git", Column::GitStatus => "Git",
} }
} }
} }
......
...@@ -13,7 +13,7 @@ use pad::Alignment; ...@@ -13,7 +13,7 @@ use pad::Alignment;
use number_prefix::{binary_prefix, decimal_prefix, Prefixed, Standalone, PrefixNames}; use number_prefix::{binary_prefix, decimal_prefix, Prefixed, Standalone, PrefixNames};
use datetime; use datetime;
use datetime::local::LocalDateTime; use datetime::local::{LocalDateTime, DatePiece};
use column::{Column, Cell}; use column::{Column, Cell};
use column::Column::*; use column::Column::*;
...@@ -99,15 +99,15 @@ impl<'a> File<'a> { ...@@ -99,15 +99,15 @@ impl<'a> File<'a> {
/// Get the data for a column, formatted as a coloured string. /// Get the data for a column, formatted as a coloured string.
pub fn display<U: Users>(&self, column: &Column, users_cache: &mut U) -> Cell { pub fn display<U: Users>(&self, column: &Column, users_cache: &mut U) -> Cell {
match *column { match *column {
Permissions => self.permissions_string(), Permissions => self.permissions_string(),
FileSize(f) => self.file_size(f), FileSize(f) => self.file_size(f),
Timestamp(t) => self.timestamp(t), Timestamp(t, y) => self.timestamp(t, y),
HardLinks => self.hard_links(), HardLinks => self.hard_links(),
Inode => self.inode(), Inode => self.inode(),
Blocks => self.blocks(), Blocks => self.blocks(),
User => self.user(users_cache), User => self.user(users_cache),
Group => self.group(users_cache), Group => self.group(users_cache),
GitStatus => self.git_status(), GitStatus => self.git_status(),
} }
} }
...@@ -303,8 +303,7 @@ impl<'a> File<'a> { ...@@ -303,8 +303,7 @@ impl<'a> File<'a> {
} }
} }
fn timestamp(&self, time_type: TimeType) -> Cell { fn timestamp(&self, time_type: TimeType, current_year: i64) -> Cell {
let format = date_format!("{:Y} {:M} {2>:D} {2>:h}:{02>:m}");
// Need to convert these values from milliseconds into seconds. // Need to convert these values from milliseconds into seconds.
let time_in_seconds = match time_type { let time_in_seconds = match time_type {
...@@ -314,6 +313,14 @@ impl<'a> File<'a> { ...@@ -314,6 +313,14 @@ impl<'a> File<'a> {
} as i64 / 1000; } as i64 / 1000;
let date = LocalDateTime::at(time_in_seconds); let date = LocalDateTime::at(time_in_seconds);
let format = if date.year() == current_year {
date_format!("{2>:D} {:M} {2>:h}:{02>:m}")
}
else {
date_format!("{2>:D} {:M} {4>:Y}")
};
Cell::paint(Blue.normal(), format.format(date).as_slice()) Cell::paint(Blue.normal(), format.format(date).as_slice())
} }
......
...@@ -12,6 +12,8 @@ use std::fmt; ...@@ -12,6 +12,8 @@ use std::fmt;
use getopts; use getopts;
use natord; use natord;
use datetime::local::{LocalDateTime, DatePiece};
use self::Misfire::*; use self::Misfire::*;
/// The *Options* struct represents a parsed version of the user's /// The *Options* struct represents a parsed version of the user's
...@@ -422,16 +424,18 @@ impl Columns { ...@@ -422,16 +424,18 @@ impl Columns {
columns.push(Group); columns.push(Group);
} }
let current_year = LocalDateTime::now().year();
if self.time_types.modified { if self.time_types.modified {
columns.push(Timestamp(TimeType::FileModified)); columns.push(Timestamp(TimeType::FileModified, current_year));
} }
if self.time_types.created { if self.time_types.created {
columns.push(Timestamp(TimeType::FileCreated)); columns.push(Timestamp(TimeType::FileCreated, current_year));
} }
if self.time_types.accessed { if self.time_types.accessed {
columns.push(Timestamp(TimeType::FileAccessed)); columns.push(Timestamp(TimeType::FileAccessed, current_year));
} }
if cfg!(feature="git") { if cfg!(feature="git") {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册