@@ -27,14 +27,12 @@ use std::{
2727use std:: { collections:: HashSet , io:: IsTerminal } ;
2828
2929use ansi_width:: ansi_width;
30- use chrono:: { DateTime , Local , TimeDelta , TimeZone , Utc } ;
31- use chrono_tz:: { OffsetName , Tz } ;
30+ use chrono:: { DateTime , Local , TimeDelta } ;
3231use clap:: {
3332 builder:: { NonEmptyStringValueParser , PossibleValue , ValueParser } ,
3433 crate_version, Arg , ArgAction , Command ,
3534} ;
3635use glob:: { MatchOptions , Pattern } ;
37- use iana_time_zone:: get_timezone;
3836use lscolors:: LsColors ;
3937use term_grid:: { Direction , Filling , Grid , GridOptions } ;
4038
@@ -60,6 +58,7 @@ use uucore::libc::{S_IXGRP, S_IXOTH, S_IXUSR};
6058use uucore:: line_ending:: LineEnding ;
6159use uucore:: quoting_style:: { self , escape_name, QuotingStyle } ;
6260use uucore:: {
61+ custom_tz_fmt,
6362 display:: Quotable ,
6463 error:: { set_exit_code, UError , UResult } ,
6564 format_usage,
@@ -345,31 +344,6 @@ fn is_recent(time: DateTime<Local>) -> bool {
345344 time + TimeDelta :: try_seconds ( 31_556_952 / 2 ) . unwrap ( ) > Local :: now ( )
346345}
347346
348- /// Get the alphabetic abbreviation of the current timezone.
349- ///
350- /// For example, "UTC" or "CET" or "PDT".
351- fn timezone_abbrev ( ) -> String {
352- let tz = match std:: env:: var ( "TZ" ) {
353- // TODO Support other time zones...
354- Ok ( s) if s == "UTC0" || s. is_empty ( ) => Tz :: Etc__UTC ,
355- _ => match get_timezone ( ) {
356- Ok ( tz_str) => tz_str. parse ( ) . unwrap ( ) ,
357- Err ( _) => Tz :: Etc__UTC ,
358- } ,
359- } ;
360- let offset = tz. offset_from_utc_date ( & Utc :: now ( ) . date_naive ( ) ) ;
361- offset. abbreviation ( ) . unwrap_or ( "UTC" ) . to_string ( )
362- }
363-
364- /// Format the given time according to a custom format string.
365- fn custom_time_format ( fmt : & str , time : DateTime < Local > ) -> String {
366- // TODO Refactor the common code from `ls` and `date` for rendering dates.
367- // TODO - Revisit when chrono 0.5 is released. https://github.com/chronotope/chrono/issues/970
368- // GNU `date` uses `%N` for nano seconds, however the `chrono` crate uses `%f`.
369- let fmt = fmt. replace ( "%N" , "%f" ) . replace ( "%Z" , & timezone_abbrev ( ) ) ;
370- time. format ( & fmt) . to_string ( )
371- }
372-
373347impl TimeStyle {
374348 /// Format the given time according to this time format style.
375349 fn format ( & self , time : DateTime < Local > ) -> String {
@@ -386,7 +360,9 @@ impl TimeStyle {
386360 //So it's not yet implemented
387361 ( Self :: Locale , true ) => time. format ( "%b %e %H:%M" ) . to_string ( ) ,
388362 ( Self :: Locale , false ) => time. format ( "%b %e %Y" ) . to_string ( ) ,
389- ( Self :: Format ( e) , _) => custom_time_format ( e, time) ,
363+ ( Self :: Format ( fmt) , _) => time
364+ . format ( custom_tz_fmt:: custom_time_format ( fmt) . as_str ( ) )
365+ . to_string ( ) ,
390366 }
391367 }
392368}
0 commit comments