66// spell-checker:ignore (chrono) Datelike Timelike ; (format) DATEFILE MMDDhhmm ; (vars) datetime datetimes
77
88use chrono:: format:: { Item , StrftimeItems } ;
9- use chrono:: { DateTime , FixedOffset , Local , Offset , TimeDelta , TimeZone , Utc } ;
9+ use chrono:: { DateTime , FixedOffset , Local , Offset , TimeDelta , Utc } ;
1010#[ cfg( windows) ]
1111use chrono:: { Datelike , Timelike } ;
12- use chrono_tz:: { OffsetName , Tz } ;
1312use clap:: { crate_version, Arg , ArgAction , Command } ;
14- use iana_time_zone:: get_timezone;
1513#[ cfg( all( unix, not( target_os = "macos" ) , not( target_os = "redox" ) ) ) ]
1614use libc:: { clock_settime, timespec, CLOCK_REALTIME } ;
1715use std:: fs:: File ;
1816use std:: io:: { BufRead , BufReader } ;
1917use std:: path:: PathBuf ;
18+ use uucore:: custom_tz_fmt:: custom_time_format;
2019use uucore:: display:: Quotable ;
2120use uucore:: error:: FromIo ;
2221use uucore:: error:: { UResult , USimpleError } ;
@@ -274,21 +273,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
274273 for date in dates {
275274 match date {
276275 Ok ( date) => {
277- // TODO - Revisit when chrono 0.5 is released. https://github.com/chronotope/chrono/issues/970
278- let tz = match std:: env:: var ( "TZ" ) {
279- // TODO Support other time zones...
280- Ok ( s) if s == "UTC0" || s. is_empty ( ) => Tz :: Etc__UTC ,
281- _ => match get_timezone ( ) {
282- Ok ( tz_str) => tz_str. parse ( ) . unwrap ( ) ,
283- Err ( _) => Tz :: Etc__UTC ,
284- } ,
285- } ;
286- let offset = tz. offset_from_utc_date ( & Utc :: now ( ) . date_naive ( ) ) ;
287- let tz_abbreviation = offset. abbreviation ( ) ;
288- // GNU `date` uses `%N` for nano seconds, however crate::chrono uses `%f`
289- let format_string = & format_string
290- . replace ( "%N" , "%f" )
291- . replace ( "%Z" , tz_abbreviation. unwrap_or ( "UTC" ) ) ;
276+ let format_string = custom_time_format ( format_string) ;
292277 // Refuse to pass this string to chrono as it is crashing in this crate
293278 if format_string. contains ( "%#z" ) {
294279 return Err ( USimpleError :: new (
@@ -298,7 +283,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
298283 }
299284 // Hack to work around panic in chrono,
300285 // TODO - remove when a fix for https://github.com/chronotope/chrono/issues/623 is released
301- let format_items = StrftimeItems :: new ( format_string) ;
286+ let format_items = StrftimeItems :: new ( format_string. as_str ( ) ) ;
302287 if format_items. clone ( ) . any ( |i| i == Item :: Error ) {
303288 return Err ( USimpleError :: new (
304289 1 ,
0 commit comments