From ff0e728841f1ac5af28ac024d3f29a60b5788f45 Mon Sep 17 00:00:00 2001 From: Patrick Klitzke Date: Mon, 28 Aug 2023 00:39:16 +0900 Subject: [PATCH] Fixes issues with timezone This pr should fix the issue with the timezones #36. Now all tests are passing. --- src/lib.rs | 4 ++-- tests/simple.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 614b355..cbd84d3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,7 +4,7 @@ // Expose parse_datetime pub mod parse_datetime; -use chrono::{Duration, Local, NaiveDate, Utc}; +use chrono::{Duration, Local, NaiveDate}; use regex::{Error as RegexError, Regex}; use std::error::Error; use std::fmt::{self, Display}; @@ -92,7 +92,7 @@ impl From for ParseDurationError { /// assert!(matches!(from_str("invalid"), Err(ParseDurationError::InvalidInput))); /// ``` pub fn from_str(s: &str) -> Result { - from_str_at_date(Utc::now().date_naive(), s) + from_str_at_date(Local::now().date_naive(), s) } /// Parses a duration string and returns a `Duration` instance, with the duration diff --git a/tests/simple.rs b/tests/simple.rs index a538f9d..3d2afcd 100644 --- a/tests/simple.rs +++ b/tests/simple.rs @@ -1,4 +1,4 @@ -use chrono::{Duration, Utc}; +use chrono::{Duration, Local, Utc}; use parse_datetime::{from_str, from_str_at_date, ParseDurationError}; #[test] @@ -128,7 +128,7 @@ fn test_display_should_fail() { #[test] fn test_from_str_at_date_day() { - let today = Utc::now().date_naive(); + let today = Local::now().date_naive(); let yesterday = today - Duration::days(1); assert_eq!( from_str_at_date(yesterday, "2 days").unwrap(),