mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 20:17:45 +00:00
stat: fix birth/created time transformation
This commit is contained in:
parent
25d4fb71ca
commit
9416709c9c
1 changed files with 4 additions and 2 deletions
|
@ -24,7 +24,7 @@ impl BirthTime for Metadata {
|
||||||
fn pretty_birth(&self) -> String {
|
fn pretty_birth(&self) -> String {
|
||||||
self.created()
|
self.created()
|
||||||
.ok()
|
.ok()
|
||||||
.and_then(|t| t.elapsed().ok())
|
.and_then(|t| t.duration_since(std::time::UNIX_EPOCH).ok())
|
||||||
.map(|e| pretty_time(e.as_secs() as i64, e.subsec_nanos() as i64))
|
.map(|e| pretty_time(e.as_secs() as i64, e.subsec_nanos() as i64))
|
||||||
.unwrap_or("-".to_owned())
|
.unwrap_or("-".to_owned())
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ impl BirthTime for Metadata {
|
||||||
fn birth(&self) -> String {
|
fn birth(&self) -> String {
|
||||||
self.created()
|
self.created()
|
||||||
.ok()
|
.ok()
|
||||||
.and_then(|t| t.elapsed().ok())
|
.and_then(|t| t.duration_since(std::time::UNIX_EPOCH).ok())
|
||||||
.map(|e| format!("{}", e.as_secs()))
|
.map(|e| format!("{}", e.as_secs()))
|
||||||
.unwrap_or("0".to_owned())
|
.unwrap_or("0".to_owned())
|
||||||
}
|
}
|
||||||
|
@ -46,6 +46,8 @@ macro_rules! has {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn pretty_time(sec: i64, nsec: i64) -> String {
|
pub fn pretty_time(sec: i64, nsec: i64) -> String {
|
||||||
|
// sec == seconds since UNIX_EPOCH
|
||||||
|
// nsec == nanoseconds since (UNIX_EPOCH + sec)
|
||||||
let tm = time::at(Timespec::new(sec, nsec as i32));
|
let tm = time::at(Timespec::new(sec, nsec as i32));
|
||||||
let res = time::strftime("%Y-%m-%d %H:%M:%S.%f %z", &tm).unwrap();
|
let res = time::strftime("%Y-%m-%d %H:%M:%S.%f %z", &tm).unwrap();
|
||||||
if res.ends_with(" -0000") {
|
if res.ends_with(" -0000") {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue