@@ -10,13 +10,12 @@ use clap::builder::ValueParser;
1010use uucore:: display:: Quotable ;
1111use uucore:: fs:: display_permissions;
1212use uucore:: fsext:: {
13- BirthTime , FsMeta , MetadataTimeField , StatFs , metadata_get_time, pretty_filetype,
14- pretty_fstype , read_fs_list, statfs,
13+ FsMeta , MetadataTimeField , StatFs , metadata_get_time, pretty_filetype, pretty_fstype ,
14+ read_fs_list, statfs,
1515} ;
1616use uucore:: libc:: mode_t;
1717use uucore:: { entries, format_usage, show_error, show_warning} ;
1818
19- use chrono:: { DateTime , Local } ;
2019use clap:: { Arg , ArgAction , ArgMatches , Command } ;
2120use std:: borrow:: Cow ;
2221use std:: ffi:: { OsStr , OsString } ;
@@ -29,6 +28,7 @@ use std::{env, fs};
2928use std:: collections:: HashMap ;
3029use thiserror:: Error ;
3130use uucore:: locale:: { get_message, get_message_with_args} ;
31+ use uucore:: time:: { format_system_time, system_time_to_sec} ;
3232
3333#[ derive( Debug , Error ) ]
3434enum StatError {
@@ -1030,7 +1030,10 @@ impl Stater {
10301030 'w' => OutputType :: Str ( pretty_time ( meta, MetadataTimeField :: Birth ) ) ,
10311031
10321032 // time of file birth, seconds since Epoch; 0 if unknown
1033- 'W' => OutputType :: Unsigned ( meta. birth ( ) . unwrap_or_default ( ) . 0 ) ,
1033+ 'W' => OutputType :: Integer (
1034+ metadata_get_time ( meta, MetadataTimeField :: Birth )
1035+ . map_or ( 0 , |x| system_time_to_sec ( x) . 0 ) ,
1036+ ) ,
10341037
10351038 // time of last access, human-readable
10361039 'x' => OutputType :: Str ( pretty_time ( meta, MetadataTimeField :: Access ) ) ,
@@ -1040,21 +1043,9 @@ impl Stater {
10401043 'y' => OutputType :: Str ( pretty_time ( meta, MetadataTimeField :: Modification ) ) ,
10411044 // time of last data modification, seconds since Epoch
10421045 'Y' => {
1043- let sec = meta. mtime ( ) ;
1044- let nsec = meta. mtime_nsec ( ) ;
1045- let tm = DateTime :: from_timestamp ( sec, nsec as u32 ) . unwrap_or_default ( ) ;
1046- let tm: DateTime < Local > = tm. into ( ) ;
1047- match tm. timestamp_nanos_opt ( ) {
1048- None => {
1049- let micros = tm. timestamp_micros ( ) ;
1050- let secs = micros as f64 / 1_000_000.0 ;
1051- OutputType :: Float ( secs)
1052- }
1053- Some ( ns) => {
1054- let secs = ns as f64 / 1_000_000_000.0 ;
1055- OutputType :: Float ( secs)
1056- }
1057- }
1046+ let ( sec, nsec) = metadata_get_time ( meta, MetadataTimeField :: Modification )
1047+ . map_or ( ( 0 , 0 ) , system_time_to_sec) ;
1048+ OutputType :: Float ( sec as f64 + nsec as f64 / 1_000_000_000.0 )
10581049 }
10591050 // time of last status change, human-readable
10601051 'z' => OutputType :: Str ( pretty_time ( meta, MetadataTimeField :: Change ) ) ,
@@ -1297,7 +1288,7 @@ const PRETTY_DATETIME_FORMAT: &str = "%Y-%m-%d %H:%M:%S.%N %z";
12971288fn pretty_time ( meta : & Metadata , md_time_field : MetadataTimeField ) -> String {
12981289 if let Some ( time) = metadata_get_time ( meta, md_time_field) {
12991290 let mut tmp = Vec :: new ( ) ;
1300- if uucore :: time :: format_system_time ( & mut tmp, time, PRETTY_DATETIME_FORMAT , false ) . is_ok ( ) {
1291+ if format_system_time ( & mut tmp, time, PRETTY_DATETIME_FORMAT , false ) . is_ok ( ) {
13011292 return String :: from_utf8 ( tmp) . unwrap ( ) ;
13021293 }
13031294 }
0 commit comments