Skip to content

Commit 6ba55a0

Browse files
committed
Fix the various warnings
1 parent b439960 commit 6ba55a0

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

src/lib.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl From<RegexError> for ParseDurationError {
8989
/// assert!(matches!(from_str("invalid"), Err(ParseDurationError::InvalidInput)));
9090
/// ```
9191
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)
9393
}
9494

9595
/// 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
189189
if captures_processed == 0 {
190190
Err(ParseDurationError::InvalidInput)
191191
} else {
192-
let time_now = Local::now().date().naive_local();
192+
let time_now = Local::now().date_naive();
193193
let date_duration = date - time_now;
194194

195195
Ok(total_duration + date_duration)
@@ -201,7 +201,7 @@ mod tests {
201201

202202
use super::ParseDurationError;
203203
use super::{from_str, from_str_at_date};
204-
use chrono::{Date, Duration, Local, NaiveDate};
204+
use chrono::{Duration, Local, NaiveDate};
205205

206206
#[test]
207207
fn test_years() {
@@ -328,13 +328,13 @@ mod tests {
328328
println!("{result:?}");
329329
match result {
330330
Err(ParseDurationError::InvalidInput) => assert!(true),
331-
_ => assert!(false),
331+
_ => panic!(),
332332
}
333333

334334
let result = from_str("invalid 1");
335335
match result {
336336
Err(ParseDurationError::InvalidInput) => assert!(true),
337-
_ => assert!(false),
337+
_ => panic!(),
338338
}
339339
// Fails for now with a panic
340340
/* let result = from_str("777777777777777771m");
@@ -346,8 +346,8 @@ mod tests {
346346

347347
#[test]
348348
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();
351351
let days_diff = (date - now).num_days();
352352

353353
assert_eq!(
@@ -363,7 +363,7 @@ mod tests {
363363

364364
#[test]
365365
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();
367367
assert!(matches!(
368368
from_str_at_date(date, "invalid"),
369369
Err(ParseDurationError::InvalidInput)

tests/simple.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use chrono::{Duration, Local, NaiveDate, Utc};
1+
use chrono::{Duration, Utc};
22
use humantime_to_duration::{from_str, from_str_at_date, ParseDurationError};
33

44
#[test]
@@ -128,7 +128,7 @@ fn test_display_should_fail() {
128128

129129
#[test]
130130
fn test_from_str_at_date_day() {
131-
let today = Utc::today().naive_utc();
131+
let today = Utc::now().date_naive();
132132
let yesterday = today - Duration::days(1);
133133
assert_eq!(
134134
from_str_at_date(yesterday, "2 days").unwrap(),
@@ -138,7 +138,7 @@ fn test_from_str_at_date_day() {
138138

139139
#[test]
140140
fn test_invalid_input_at_date() {
141-
let today = Utc::today().naive_utc();
141+
let today = Utc::now().date_naive();
142142
let result = from_str_at_date(today, "foobar");
143143
println!("{result:?}");
144144
assert_eq!(result, Err(ParseDurationError::InvalidInput));

0 commit comments

Comments
 (0)