@@ -10,7 +10,8 @@ use clap::builder::ValueParser;
1010use uucore:: display:: Quotable ;
1111use uucore:: fs:: display_permissions;
1212use uucore:: fsext:: {
13- BirthTime , FsMeta , StatFs , pretty_filetype, pretty_fstype, read_fs_list, statfs,
13+ BirthTime , FsMeta , MetadataTimeField , StatFs , metadata_get_time, pretty_filetype,
14+ pretty_fstype, read_fs_list, statfs,
1415} ;
1516use uucore:: libc:: mode_t;
1617use uucore:: { entries, format_usage, show_error, show_warning} ;
@@ -1026,21 +1027,17 @@ impl Stater {
10261027 }
10271028
10281029 // time of file birth, human-readable; - if unknown
1029- 'w' => {
1030- OutputType :: Str ( meta. birth ( ) . map_or ( String :: from ( "-" ) , |( sec, nsec) | {
1031- pretty_time ( sec as i64 , nsec as i64 )
1032- } ) )
1033- }
1030+ 'w' => OutputType :: Str ( pretty_time ( meta, MetadataTimeField :: Birth ) ) ,
10341031
10351032 // time of file birth, seconds since Epoch; 0 if unknown
10361033 'W' => OutputType :: Unsigned ( meta. birth ( ) . unwrap_or_default ( ) . 0 ) ,
10371034
10381035 // time of last access, human-readable
1039- 'x' => OutputType :: Str ( pretty_time ( meta. atime ( ) , meta . atime_nsec ( ) ) ) ,
1036+ 'x' => OutputType :: Str ( pretty_time ( meta, MetadataTimeField :: Access ) ) ,
10401037 // time of last access, seconds since Epoch
10411038 'X' => OutputType :: Integer ( meta. atime ( ) ) ,
10421039 // time of last data modification, human-readable
1043- 'y' => OutputType :: Str ( pretty_time ( meta. mtime ( ) , meta . mtime_nsec ( ) ) ) ,
1040+ 'y' => OutputType :: Str ( pretty_time ( meta, MetadataTimeField :: Modification ) ) ,
10441041 // time of last data modification, seconds since Epoch
10451042 'Y' => {
10461043 let sec = meta. mtime ( ) ;
@@ -1060,7 +1057,7 @@ impl Stater {
10601057 }
10611058 }
10621059 // time of last status change, human-readable
1063- 'z' => OutputType :: Str ( pretty_time ( meta. ctime ( ) , meta . ctime_nsec ( ) ) ) ,
1060+ 'z' => OutputType :: Str ( pretty_time ( meta, MetadataTimeField :: Change ) ) ,
10641061 // time of last status change, seconds since Epoch
10651062 'Z' => OutputType :: Integer ( meta. ctime ( ) ) ,
10661063 'R' => {
@@ -1295,14 +1292,16 @@ pub fn uu_app() -> Command {
12951292 )
12961293}
12971294
1298- const PRETTY_DATETIME_FORMAT : & str = "%Y-%m-%d %H:%M:%S.%f %z" ;
1299-
1300- fn pretty_time ( sec : i64 , nsec : i64 ) -> String {
1301- // Return the date in UTC
1302- let tm = DateTime :: from_timestamp ( sec, nsec as u32 ) . unwrap_or_default ( ) ;
1303- let tm: DateTime < Local > = tm. into ( ) ;
1295+ const PRETTY_DATETIME_FORMAT : & str = "%Y-%m-%d %H:%M:%S.%N %z" ;
13041296
1305- tm. format ( PRETTY_DATETIME_FORMAT ) . to_string ( )
1297+ fn pretty_time ( meta : & Metadata , md_time_field : MetadataTimeField ) -> String {
1298+ if let Some ( time) = metadata_get_time ( meta, md_time_field) {
1299+ let mut tmp = Vec :: new ( ) ;
1300+ if uucore:: time:: format_system_time ( & mut tmp, time, PRETTY_DATETIME_FORMAT , false ) . is_ok ( ) {
1301+ return String :: from_utf8 ( tmp) . unwrap ( ) ;
1302+ }
1303+ }
1304+ "-" . to_string ( )
13061305}
13071306
13081307#[ cfg( test) ]
0 commit comments