@@ -319,25 +319,27 @@ mod tests {
319
319
320
320
#[ test]
321
321
fn test_months ( ) {
322
+ use crate :: parse_relative_time:: add_months;
323
+
322
324
let now = Utc :: now ( ) ;
323
325
assert_eq ! (
324
326
parse_relative_time_at_date( now, "1 month" ) . unwrap( ) ,
325
- now . checked_add_months ( Months :: new ( 1 ) ) . unwrap( )
327
+ add_months ( now , 1 , false ) . unwrap( ) ,
326
328
) ;
327
329
assert_eq ! (
328
330
parse_relative_time_at_date( now, "this month" ) . unwrap( ) ,
329
331
now. checked_add_months( Months :: new( 0 ) ) . unwrap( )
330
332
) ;
331
333
assert_eq ! (
332
334
parse_relative_time_at_date( now, "1 month and 2 weeks" ) . unwrap( ) ,
333
- now . checked_add_months ( Months :: new ( 1 ) )
335
+ add_months ( now , 1 , false )
334
336
. unwrap( )
335
337
. checked_add_days( Days :: new( 14 ) )
336
338
. unwrap( )
337
339
) ;
338
340
assert_eq ! (
339
341
parse_relative_time_at_date( now, "1 month and 2 weeks ago" ) . unwrap( ) ,
340
- now . checked_sub_months ( Months :: new ( 1 ) )
342
+ add_months ( now , 1 , true )
341
343
. unwrap( )
342
344
. checked_sub_days( Days :: new( 14 ) )
343
345
. unwrap( )
@@ -348,7 +350,7 @@ mod tests {
348
350
) ;
349
351
assert_eq ! (
350
352
parse_relative_time_at_date( now, "month" ) . unwrap( ) ,
351
- now . checked_add_months ( Months :: new ( 1 ) ) . unwrap( )
353
+ add_months ( now , 1 , false ) . unwrap( ) ,
352
354
) ;
353
355
}
354
356
@@ -562,6 +564,8 @@ mod tests {
562
564
563
565
#[ test]
564
566
fn test_duration_parsing ( ) {
567
+ use crate :: parse_relative_time:: add_months;
568
+
565
569
let now = Utc :: now ( ) ;
566
570
assert_eq ! (
567
571
parse_relative_time_at_date( now, "1 year" ) . unwrap( ) ,
@@ -582,25 +586,25 @@ mod tests {
582
586
583
587
assert_eq ! (
584
588
parse_relative_time_at_date( now, "1 month" ) . unwrap( ) ,
585
- now . checked_add_months ( Months :: new ( 1 ) ) . unwrap( )
589
+ add_months ( now , 1 , false ) . unwrap( ) ,
586
590
) ;
587
591
assert_eq ! (
588
592
parse_relative_time_at_date( now, "1 month and 2 weeks" ) . unwrap( ) ,
589
- now . checked_add_months ( Months :: new ( 1 ) )
593
+ add_months ( now , 1 , false )
590
594
. unwrap( )
591
595
. checked_add_days( Days :: new( 14 ) )
592
596
. unwrap( )
593
597
) ;
594
598
assert_eq ! (
595
599
parse_relative_time_at_date( now, "1 month, 2 weeks" ) . unwrap( ) ,
596
- now . checked_add_months ( Months :: new ( 1 ) )
600
+ add_months ( now , 1 , false )
597
601
. unwrap( )
598
602
. checked_add_days( Days :: new( 14 ) )
599
603
. unwrap( )
600
604
) ;
601
605
assert_eq ! (
602
606
parse_relative_time_at_date( now, "1 months 2 weeks" ) . unwrap( ) ,
603
- now . checked_add_months ( Months :: new ( 1 ) )
607
+ add_months ( now , 1 , false )
604
608
. unwrap( )
605
609
. checked_add_days( Days :: new( 14 ) )
606
610
. unwrap( )
@@ -618,7 +622,7 @@ mod tests {
618
622
) ;
619
623
assert_eq ! (
620
624
parse_relative_time_at_date( now, "month" ) . unwrap( ) ,
621
- now . checked_add_months ( Months :: new ( 1 ) ) . unwrap( )
625
+ add_months ( now , 1 , false ) . unwrap( ) ,
622
626
) ;
623
627
624
628
assert_eq ! (
0 commit comments