mirror of
https://github.com/Llewellynvdm/exa.git
synced 2024-12-27 10:22:40 +00:00
Use correct metadata for created time
This commit is contained in:
parent
35bf32abb9
commit
b0da0c9055
@ -5,6 +5,7 @@ use std::io::Error as IOError;
|
||||
use std::io::Result as IOResult;
|
||||
use std::os::unix::fs::{MetadataExt, PermissionsExt, FileTypeExt};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::time::{UNIX_EPOCH, Duration};
|
||||
|
||||
use fs::dir::Dir;
|
||||
use fs::fields as f;
|
||||
@ -296,27 +297,18 @@ impl<'dir> File<'dir> {
|
||||
}
|
||||
|
||||
/// This file’s last modified timestamp.
|
||||
pub fn modified_time(&self) -> f::Time {
|
||||
f::Time {
|
||||
seconds: self.metadata.mtime(),
|
||||
nanoseconds: self.metadata.mtime_nsec()
|
||||
}
|
||||
}
|
||||
|
||||
/// This file’s created timestamp.
|
||||
pub fn created_time(&self) -> f::Time {
|
||||
f::Time {
|
||||
seconds: self.metadata.ctime(),
|
||||
nanoseconds: self.metadata.ctime_nsec()
|
||||
}
|
||||
pub fn modified_time(&self) -> Duration {
|
||||
self.metadata.modified().unwrap().duration_since(UNIX_EPOCH).unwrap()
|
||||
}
|
||||
|
||||
/// This file’s last accessed timestamp.
|
||||
pub fn accessed_time(&self) -> f::Time {
|
||||
f::Time {
|
||||
seconds: self.metadata.atime(),
|
||||
nanoseconds: self.metadata.atime_nsec()
|
||||
}
|
||||
pub fn accessed_time(&self) -> Duration {
|
||||
self.metadata.accessed().unwrap().duration_since(UNIX_EPOCH).unwrap()
|
||||
}
|
||||
|
||||
/// This file’s created timestamp.
|
||||
pub fn created_time(&self) -> Duration {
|
||||
self.metadata.created().unwrap().duration_since(UNIX_EPOCH).unwrap()
|
||||
}
|
||||
|
||||
/// This file’s ‘type’.
|
||||
|
@ -23,6 +23,7 @@ mod size;
|
||||
pub use self::size::Colours as SizeColours;
|
||||
|
||||
mod times;
|
||||
pub use self::times::Render as TimeRender;
|
||||
// times does too
|
||||
|
||||
mod users;
|
||||
|
@ -1,13 +1,18 @@
|
||||
use datetime::TimeZone;
|
||||
use ansi_term::Style;
|
||||
|
||||
use fs::fields as f;
|
||||
use output::cell::TextCell;
|
||||
use output::time::TimeFormat;
|
||||
|
||||
|
||||
impl f::Time {
|
||||
pub fn render(self, style: Style,
|
||||
pub trait Render {
|
||||
fn render(self, style: Style,
|
||||
tz: &Option<TimeZone>,
|
||||
format: &TimeFormat) -> TextCell;
|
||||
}
|
||||
|
||||
impl Render for std::time::Duration {
|
||||
fn render(self, style: Style,
|
||||
tz: &Option<TimeZone>,
|
||||
format: &TimeFormat) -> TextCell {
|
||||
|
||||
|
@ -12,6 +12,7 @@ use users::UsersCache;
|
||||
|
||||
use style::Colours;
|
||||
use output::cell::TextCell;
|
||||
use output::render::TimeRender;
|
||||
use output::time::TimeFormat;
|
||||
use fs::{File, fields as f};
|
||||
use fs::feature::git::GitCache;
|
||||
|
@ -1,12 +1,12 @@
|
||||
//! Timestamp formatting.
|
||||
|
||||
use std::time::Duration;
|
||||
|
||||
use datetime::{LocalDateTime, TimeZone, DatePiece, TimePiece};
|
||||
use datetime::fmt::DateFormat;
|
||||
use locale;
|
||||
use std::cmp;
|
||||
|
||||
use fs::fields::Time;
|
||||
|
||||
|
||||
/// Every timestamp in exa needs to be rendered by a **time format**.
|
||||
/// Formatting times is tricky, because how a timestamp is rendered can
|
||||
@ -51,7 +51,7 @@ pub enum TimeFormat {
|
||||
// timestamps are separate types.
|
||||
|
||||
impl TimeFormat {
|
||||
pub fn format_local(&self, time: Time) -> String {
|
||||
pub fn format_local(&self, time: Duration) -> String {
|
||||
match *self {
|
||||
TimeFormat::DefaultFormat(ref fmt) => fmt.format_local(time),
|
||||
TimeFormat::ISOFormat(ref iso) => iso.format_local(time),
|
||||
@ -60,7 +60,7 @@ impl TimeFormat {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn format_zoned(&self, time: Time, zone: &TimeZone) -> String {
|
||||
pub fn format_zoned(&self, time: Duration, zone: &TimeZone) -> String {
|
||||
match *self {
|
||||
TimeFormat::DefaultFormat(ref fmt) => fmt.format_zoned(time, zone),
|
||||
TimeFormat::ISOFormat(ref iso) => iso.format_zoned(time, zone),
|
||||
@ -128,8 +128,8 @@ impl DefaultFormat {
|
||||
}
|
||||
|
||||
#[allow(trivial_numeric_casts)]
|
||||
fn format_local(&self, time: Time) -> String {
|
||||
let date = LocalDateTime::at(time.seconds as i64);
|
||||
fn format_local(&self, time: Duration) -> String {
|
||||
let date = LocalDateTime::at(time.as_secs() as i64);
|
||||
|
||||
if self.is_recent(date) {
|
||||
self.date_and_time.format(&date, &self.locale)
|
||||
@ -140,8 +140,8 @@ impl DefaultFormat {
|
||||
}
|
||||
|
||||
#[allow(trivial_numeric_casts)]
|
||||
fn format_zoned(&self, time: Time, zone: &TimeZone) -> String {
|
||||
let date = zone.to_zoned(LocalDateTime::at(time.seconds as i64));
|
||||
fn format_zoned(&self, time: Duration, zone: &TimeZone) -> String {
|
||||
let date = zone.to_zoned(LocalDateTime::at(time.as_secs() as i64));
|
||||
|
||||
if self.is_recent(date) {
|
||||
self.date_and_time.format(&date, &self.locale)
|
||||
@ -154,16 +154,16 @@ impl DefaultFormat {
|
||||
|
||||
|
||||
#[allow(trivial_numeric_casts)]
|
||||
fn long_local(time: Time) -> String {
|
||||
let date = LocalDateTime::at(time.seconds as i64);
|
||||
fn long_local(time: Duration) -> String {
|
||||
let date = LocalDateTime::at(time.as_secs() as i64);
|
||||
format!("{:04}-{:02}-{:02} {:02}:{:02}",
|
||||
date.year(), date.month() as usize, date.day(),
|
||||
date.hour(), date.minute())
|
||||
}
|
||||
|
||||
#[allow(trivial_numeric_casts)]
|
||||
fn long_zoned(time: Time, zone: &TimeZone) -> String {
|
||||
let date = zone.to_zoned(LocalDateTime::at(time.seconds as i64));
|
||||
fn long_zoned(time: Duration, zone: &TimeZone) -> String {
|
||||
let date = zone.to_zoned(LocalDateTime::at(time.as_secs() as i64));
|
||||
format!("{:04}-{:02}-{:02} {:02}:{:02}",
|
||||
date.year(), date.month() as usize, date.day(),
|
||||
date.hour(), date.minute())
|
||||
@ -171,23 +171,23 @@ fn long_zoned(time: Time, zone: &TimeZone) -> String {
|
||||
|
||||
|
||||
#[allow(trivial_numeric_casts)]
|
||||
fn full_local(time: Time) -> String {
|
||||
let date = LocalDateTime::at(time.seconds as i64);
|
||||
fn full_local(time: Duration) -> String {
|
||||
let date = LocalDateTime::at(time.as_secs() as i64);
|
||||
format!("{:04}-{:02}-{:02} {:02}:{:02}:{:02}.{:09}",
|
||||
date.year(), date.month() as usize, date.day(),
|
||||
date.hour(), date.minute(), date.second(), time.nanoseconds)
|
||||
date.hour(), date.minute(), date.second(), time.subsec_nanos())
|
||||
}
|
||||
|
||||
#[allow(trivial_numeric_casts)]
|
||||
fn full_zoned(time: Time, zone: &TimeZone) -> String {
|
||||
fn full_zoned(time: Duration, zone: &TimeZone) -> String {
|
||||
use datetime::Offset;
|
||||
|
||||
let local = LocalDateTime::at(time.seconds as i64);
|
||||
let local = LocalDateTime::at(time.as_secs() as i64);
|
||||
let date = zone.to_zoned(local);
|
||||
let offset = Offset::of_seconds(zone.offset(local) as i32).expect("Offset out of range");
|
||||
format!("{:04}-{:02}-{:02} {:02}:{:02}:{:02}.{:09} {:+03}{:02}",
|
||||
date.year(), date.month() as usize, date.day(),
|
||||
date.hour(), date.minute(), date.second(), time.nanoseconds,
|
||||
date.hour(), date.minute(), date.second(), time.subsec_nanos(),
|
||||
offset.hours(), offset.minutes().abs())
|
||||
}
|
||||
|
||||
@ -214,8 +214,8 @@ impl ISOFormat {
|
||||
}
|
||||
|
||||
#[allow(trivial_numeric_casts)]
|
||||
fn format_local(&self, time: Time) -> String {
|
||||
let date = LocalDateTime::at(time.seconds as i64);
|
||||
fn format_local(&self, time: Duration) -> String {
|
||||
let date = LocalDateTime::at(time.as_secs() as i64);
|
||||
|
||||
if self.is_recent(date) {
|
||||
format!("{:02}-{:02} {:02}:{:02}",
|
||||
@ -229,8 +229,8 @@ impl ISOFormat {
|
||||
}
|
||||
|
||||
#[allow(trivial_numeric_casts)]
|
||||
fn format_zoned(&self, time: Time, zone: &TimeZone) -> String {
|
||||
let date = zone.to_zoned(LocalDateTime::at(time.seconds as i64));
|
||||
fn format_zoned(&self, time: Duration, zone: &TimeZone) -> String {
|
||||
let date = zone.to_zoned(LocalDateTime::at(time.as_secs() as i64));
|
||||
|
||||
if self.is_recent(date) {
|
||||
format!("{:02}-{:02} {:02}:{:02}",
|
||||
|
Loading…
Reference in New Issue
Block a user