@@ -103,43 +103,11 @@ thread_local! {
103103pub struct Rfc3339 ;
104104
105105impl FormatTime for Rfc3339 {
106- #[ allow(
107- clippy:: many_single_char_names,
108- clippy:: cast_possible_truncation,
109- clippy:: cast_possible_wrap,
110- clippy:: cast_sign_loss,
111- reason = "variable names match the Howard Hinnant civil date algorithm; casts are safe by algorithm invariants"
112- ) ]
113106 fn format_time ( & self , w : & mut Writer < ' _ > ) -> std:: fmt:: Result {
114- let now = std:: time:: SystemTime :: now ( ) ;
115- let dur = now
116- . duration_since ( std:: time:: UNIX_EPOCH )
117- . unwrap_or_default ( ) ;
118- let secs = dur. as_secs ( ) ;
119- let micros = dur. subsec_micros ( ) ;
120-
121- // Convert epoch seconds to date/time components
122- let days = ( secs / 86400 ) as i64 ;
123- let time_of_day = secs % 86400 ;
124- let hours = time_of_day / 3600 ;
125- let minutes = ( time_of_day % 3600 ) / 60 ;
126- let seconds = time_of_day % 60 ;
127-
128- // Civil date from days since epoch (algorithm from Howard Hinnant)
129- let z = days + 719_468 ;
130- let era = ( if z >= 0 { z } else { z - 146_096 } ) / 146_097 ;
131- let doe = ( z - era * 146_097 ) as u64 ;
132- let yoe = ( doe - doe / 1460 + doe / 36524 - doe / 146_096 ) / 365 ;
133- let y = yoe as i64 + era * 400 ;
134- let doy = doe - ( 365 * yoe + yoe / 4 - yoe / 100 ) ;
135- let mp = ( 5 * doy + 2 ) / 153 ;
136- let d = doy - ( 153 * mp + 2 ) / 5 + 1 ;
137- let m = if mp < 10 { mp + 3 } else { mp - 9 } ;
138- let y = if m <= 2 { y + 1 } else { y } ;
139-
140107 write ! (
141108 w,
142- "{y:04}-{m:02}-{d:02}T{hours:02}:{minutes:02}:{seconds:02}.{micros:06}Z" ,
109+ "{}" ,
110+ humantime:: format_rfc3339_micros( std:: time:: SystemTime :: now( ) )
143111 )
144112 }
145113}
0 commit comments