@@ -190,17 +190,19 @@ pub fn parse(input: &mut &str) -> ModalResult<Vec<Item>> {
190190 Ok ( items)
191191}
192192
193+ #[ allow( clippy:: too_many_arguments) ]
193194fn new_date (
194195 year : i32 ,
195196 month : u32 ,
196197 day : u32 ,
197198 hour : u32 ,
198199 minute : u32 ,
199200 second : u32 ,
201+ nano : u32 ,
200202 offset : FixedOffset ,
201203) -> Option < DateTime < FixedOffset > > {
202204 let newdate = NaiveDate :: from_ymd_opt ( year, month, day)
203- . and_then ( |naive| naive. and_hms_opt ( hour, minute, second) ) ?;
205+ . and_then ( |naive| naive. and_hms_nano_opt ( hour, minute, second, nano ) ) ?;
204206
205207 Some ( DateTime :: < FixedOffset > :: from_local ( newdate, offset) )
206208}
@@ -220,7 +222,8 @@ fn with_timezone_restore(
220222 . with_year ( copy. year ( ) ) ?
221223 . with_hour ( copy. hour ( ) ) ?
222224 . with_minute ( copy. minute ( ) ) ?
223- . with_second ( copy. second ( ) ) ?;
225+ . with_second ( copy. second ( ) ) ?
226+ . with_nanosecond ( copy. nanosecond ( ) ) ?;
224227 Some ( x)
225228}
226229
@@ -274,6 +277,7 @@ fn at_date_inner(date: Vec<Item>, at: DateTime<FixedOffset>) -> Option<DateTime<
274277 d. hour ( ) ,
275278 d. minute ( ) ,
276279 d. second ( ) ,
280+ d. nanosecond ( ) ,
277281 * d. offset ( ) ,
278282 ) ?;
279283 }
@@ -299,6 +303,7 @@ fn at_date_inner(date: Vec<Item>, at: DateTime<FixedOffset>) -> Option<DateTime<
299303 hour,
300304 minute,
301305 second as u32 ,
306+ ( second. fract ( ) * 10f64 . powi ( 9 ) ) . round ( ) as u32 ,
302307 offset,
303308 ) ?;
304309 }
@@ -320,6 +325,7 @@ fn at_date_inner(date: Vec<Item>, at: DateTime<FixedOffset>) -> Option<DateTime<
320325 hour,
321326 minute,
322327 second as u32 ,
328+ ( second. fract ( ) * 10f64 . powi ( 9 ) ) . round ( ) as u32 ,
323329 offset,
324330 ) ?;
325331 }
@@ -495,6 +501,16 @@ mod tests {
495501 test_eq_fmt( "%Y-%m-%d %H:%M:%S %:z" , "Jul 17 06:14:49 2024 GMT" ) ,
496502 ) ;
497503
504+ assert_eq ! (
505+ "2024-07-17 06:14:49.567 +00:00" ,
506+ test_eq_fmt( "%Y-%m-%d %H:%M:%S%.f %:z" , "Jul 17 06:14:49.567 2024 GMT" ) ,
507+ ) ;
508+
509+ assert_eq ! (
510+ "2024-07-17 06:14:49.567 +00:00" ,
511+ test_eq_fmt( "%Y-%m-%d %H:%M:%S%.f %:z" , "Jul 17 06:14:49,567 2024 GMT" ) ,
512+ ) ;
513+
498514 assert_eq ! (
499515 "2024-07-17 06:14:49 -03:00" ,
500516 test_eq_fmt( "%Y-%m-%d %H:%M:%S %:z" , "Jul 17 06:14:49 2024 BRT" ) ,
0 commit comments