Make nanoseconds available to times

The information was always in the Metadata struct; exa just never used it.
This commit is contained in:
Benjamin Sago 2017-07-05 23:07:27 +01:00
parent 5bdf6304bb
commit aa5b1867dd
4 changed files with 33 additions and 18 deletions

View File

@ -166,7 +166,11 @@ pub struct DeviceIDs {
/// One of a files timestamps (created, accessed, or modified).
pub struct Time(pub time_t);
#[derive(Copy, Clone)]
pub struct Time {
pub seconds: time_t,
pub nanoseconds: time_t,
}
/// A files status in a Git repository. Whether a file is in a repository or

View File

@ -273,23 +273,35 @@ impl<'dir> File<'dir> {
}
}
/// This files last modified timestamp.
pub fn modified_time(&self) -> f::Time {
f::Time(self.metadata.mtime())
f::Time {
seconds: self.metadata.mtime(),
nanoseconds: self.metadata.mtime_nsec()
}
}
/// This files created timestamp.
pub fn created_time(&self) -> f::Time {
f::Time(self.metadata.ctime())
f::Time {
seconds: self.metadata.ctime(),
nanoseconds: self.metadata.ctime_nsec()
}
}
/// This files last accessed timestamp.
pub fn accessed_time(&self) -> f::Time {
f::Time(self.metadata.atime())
f::Time {
seconds: self.metadata.atime(),
nanoseconds: self.metadata.atime_nsec()
}
}
/// This file's 'type'.
/// This files type.
///
/// This is used in the leftmost column of the permissions column.
/// Although the file type can usually be guessed from the colour of the
/// file, `ls` puts this character there, so people will expect it.
/// This is used a the leftmost character of the permissions column.
/// The file type can usually be guessed from the colour of the file, but
/// ls puts this character there.
pub fn type_char(&self) -> f::Type {
if self.is_file() {
f::Type::File
@ -341,7 +353,7 @@ impl<'dir> File<'dir> {
}
}
/// Whether this file's extension is any of the strings that get passed in.
/// Whether this files extension is any of the strings that get passed in.
///
/// This will always return `false` if the file has no extension.
pub fn extension_is_one_of(&self, choices: &[&str]) -> bool {

View File

@ -6,18 +6,17 @@ use output::colours::Colours;
use output::time::TimeFormat;
#[allow(trivial_numeric_casts)]
impl f::Time {
pub fn render(&self, colours: &Colours,
pub fn render(self, colours: &Colours,
tz: &Option<TimeZone>,
style: &TimeFormat) -> TextCell {
if let Some(ref tz) = *tz {
let datestamp = style.format_zoned(self.0 as i64, tz);
let datestamp = style.format_zoned(self, tz);
TextCell::paint(colours.date, datestamp)
}
else {
let datestamp = style.format_local(self.0 as i64);
let datestamp = style.format_local(self);
TextCell::paint(colours.date, datestamp)
}
}

View File

@ -2,7 +2,7 @@ use datetime::{LocalDateTime, TimeZone, DatePiece};
use datetime::fmt::DateFormat;
use locale;
use fs::fields::time_t;
use fs::fields::Time;
#[derive(Debug, Clone)]
@ -28,8 +28,8 @@ impl TimeFormat {
}
#[allow(trivial_numeric_casts)]
pub fn format_local(&self, time: time_t) -> String {
let date = LocalDateTime::at(time as i64);
pub fn format_local(&self, time: Time) -> String {
let date = LocalDateTime::at(time.seconds as i64);
if self.is_recent(date) {
self.date_and_time.format(&date, &self.locale)
@ -40,8 +40,8 @@ impl TimeFormat {
}
#[allow(trivial_numeric_casts)]
pub fn format_zoned(&self, time: time_t, zone: &TimeZone) -> String {
let date = zone.to_zoned(LocalDateTime::at(time as i64));
pub fn format_zoned(&self, time: Time, zone: &TimeZone) -> String {
let date = zone.to_zoned(LocalDateTime::at(time.seconds as i64));
if self.is_recent(date) {
self.date_and_time.format(&date, &self.locale)