@@ -212,6 +212,7 @@ mod tests {
212
212
213
213
#[ cfg( test) ]
214
214
mod offsets {
215
+ use chrono:: FixedOffset ;
215
216
use chrono:: { Local , NaiveDate } ;
216
217
217
218
use crate :: parse_datetime;
@@ -258,12 +259,25 @@ mod tests {
258
259
259
260
#[ test]
260
261
fn test_datetime_with_offset ( ) {
261
- let actual = parse_datetime ( "1997-01-19 08:17:48 +0 " ) . unwrap ( ) ;
262
+ let actual = parse_datetime ( "1997-01-19 08:17:48 +2 " ) . unwrap ( ) ;
262
263
let expected = NaiveDate :: from_ymd_opt ( 1997 , 1 , 19 )
263
264
. unwrap ( )
264
265
. and_hms_opt ( 8 , 17 , 48 )
265
266
. unwrap ( )
266
- . and_utc ( ) ;
267
+ . and_local_timezone ( FixedOffset :: east_opt ( 2 * 3600 ) . unwrap ( ) )
268
+ . unwrap ( ) ;
269
+ assert_eq ! ( actual, expected) ;
270
+ }
271
+
272
+ #[ test]
273
+ fn test_datetime_with_timezone ( ) {
274
+ let actual = parse_datetime ( "1997-01-19 08:17:48 BRT" ) . unwrap ( ) ;
275
+ let expected = NaiveDate :: from_ymd_opt ( 1997 , 1 , 19 )
276
+ . unwrap ( )
277
+ . and_hms_opt ( 8 , 17 , 48 )
278
+ . unwrap ( )
279
+ . and_local_timezone ( FixedOffset :: west_opt ( 3 * 3600 ) . unwrap ( ) )
280
+ . unwrap ( ) ;
267
281
assert_eq ! ( actual, expected) ;
268
282
}
269
283
}
@@ -652,7 +666,7 @@ mod tests {
652
666
assert_eq ! (
653
667
parse_datetime( "28 feb 2023 + 1 day" )
654
668
. unwrap( )
655
- . format( "%+ " )
669
+ . format( "%Y-%m-%dT%H:%M:%S%:z " )
656
670
. to_string( ) ,
657
671
"2023-03-01T00:00:00+00:00"
658
672
) ;
@@ -664,15 +678,15 @@ mod tests {
664
678
assert_eq ! (
665
679
parse_datetime( "2024-01-31 + 1 month" )
666
680
. unwrap( )
667
- . format( "%+ " )
681
+ . format( "%Y-%m-%dT%H:%M:%S%:z " )
668
682
. to_string( ) ,
669
683
"2024-03-02T00:00:00+00:00" ,
670
684
) ;
671
685
672
686
assert_eq ! (
673
687
parse_datetime( "2024-02-29 + 1 month" )
674
688
. unwrap( )
675
- . format( "%+ " )
689
+ . format( "%Y-%m-%dT%H:%M:%S%:z " )
676
690
. to_string( ) ,
677
691
"2024-03-29T00:00:00+00:00" ,
678
692
) ;
0 commit comments