@@ -89,7 +89,7 @@ impl From<RegexError> for ParseDurationError {
89
89
/// assert!(matches!(from_str("invalid"), Err(ParseDurationError::InvalidInput)));
90
90
/// ```
91
91
pub fn from_str ( s : & str ) -> Result < Duration , ParseDurationError > {
92
- from_str_at_date ( Utc :: today ( ) . naive_utc ( ) , s)
92
+ from_str_at_date ( Utc :: now ( ) . date_naive ( ) , s)
93
93
}
94
94
95
95
/// Parses a duration string and returns a `Duration` instance, with the duration
@@ -189,7 +189,7 @@ pub fn from_str_at_date(date: NaiveDate, s: &str) -> Result<Duration, ParseDurat
189
189
if captures_processed == 0 {
190
190
Err ( ParseDurationError :: InvalidInput )
191
191
} else {
192
- let time_now = Local :: now ( ) . date ( ) . naive_local ( ) ;
192
+ let time_now = Local :: now ( ) . date_naive ( ) ;
193
193
let date_duration = date - time_now;
194
194
195
195
Ok ( total_duration + date_duration)
@@ -201,7 +201,7 @@ mod tests {
201
201
202
202
use super :: ParseDurationError ;
203
203
use super :: { from_str, from_str_at_date} ;
204
- use chrono:: { Date , Duration , Local , NaiveDate } ;
204
+ use chrono:: { Duration , Local , NaiveDate } ;
205
205
206
206
#[ test]
207
207
fn test_years ( ) {
@@ -328,13 +328,13 @@ mod tests {
328
328
println ! ( "{result:?}" ) ;
329
329
match result {
330
330
Err ( ParseDurationError :: InvalidInput ) => assert ! ( true ) ,
331
- _ => assert ! ( false ) ,
331
+ _ => panic ! ( ) ,
332
332
}
333
333
334
334
let result = from_str ( "invalid 1" ) ;
335
335
match result {
336
336
Err ( ParseDurationError :: InvalidInput ) => assert ! ( true ) ,
337
- _ => assert ! ( false ) ,
337
+ _ => panic ! ( ) ,
338
338
}
339
339
// Fails for now with a panic
340
340
/* let result = from_str("777777777777777771m");
@@ -346,8 +346,8 @@ mod tests {
346
346
347
347
#[ test]
348
348
fn test_from_str_at_date ( ) {
349
- let date = NaiveDate :: from_ymd ( 2014 , 9 , 5 ) ;
350
- let now = Local :: today ( ) . naive_local ( ) ;
349
+ let date = NaiveDate :: from_ymd_opt ( 2014 , 9 , 5 ) . unwrap ( ) ;
350
+ let now = Local :: now ( ) . date_naive ( ) ;
351
351
let days_diff = ( date - now) . num_days ( ) ;
352
352
353
353
assert_eq ! (
@@ -363,7 +363,7 @@ mod tests {
363
363
364
364
#[ test]
365
365
fn test_invalid_input_at_date ( ) {
366
- let date = NaiveDate :: from_ymd ( 2014 , 9 , 5 ) ;
366
+ let date = NaiveDate :: from_ymd_opt ( 2014 , 9 , 5 ) . unwrap ( ) ;
367
367
assert ! ( matches!(
368
368
from_str_at_date( date, "invalid" ) ,
369
369
Err ( ParseDurationError :: InvalidInput )
0 commit comments