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