From 6c3efb42986c4c4490b76ce577f84bf005c63f8d Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sat, 23 Sep 2023 10:33:38 +0200 Subject: [PATCH 01/10] make parse_timestamp public --- src/parse_timestamp.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/parse_timestamp.rs b/src/parse_timestamp.rs index 732558d..5e42c98 100644 --- a/src/parse_timestamp.rs +++ b/src/parse_timestamp.rs @@ -49,7 +49,7 @@ impl<'a> From> for ParseTimestampError { } } -pub(crate) fn parse_timestamp(s: &str) -> Result { +pub fn parse_timestamp(s: &str) -> Result { let s = s.trim().to_lowercase(); let s = s.as_str(); From 591eff5404efded91846458ab5ce51d79aef7462 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sat, 23 Sep 2023 10:33:56 +0200 Subject: [PATCH 02/10] update of the version --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 31a1147..36d4b72 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ Add this to your `Cargo.toml`: ```toml [dependencies] -parse_datetime = "0.4.0" +parse_datetime = "0.5.1" ``` Then, import the crate and use the `parse_datetime_at_date` function: From adf949ab140b9054dfc4c42e51cf92bbf5629949 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sat, 23 Sep 2023 10:34:54 +0200 Subject: [PATCH 03/10] update of the example --- README.md | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 36d4b72..03e2bcf 100644 --- a/README.md +++ b/README.md @@ -41,13 +41,25 @@ assert_eq!( For DateTime parsing, import the `parse_datetime` module: ```rs -use parse_datetime::parse_datetime::from_str; use chrono::{Local, TimeZone}; +use parse_datetime::parse_relative_time; -let dt = from_str("2021-02-14 06:37:47"); -assert_eq!(dt.unwrap(), Local.with_ymd_and_hms(2021, 2, 14, 6, 37, 47).unwrap()); +let one_minute = parse_relative_time("1 minute").unwrap(); +assert_eq!( + one_minute, + Duration::seconds(60) +); ``` +For timestamp parsing, import the `parse_timpestamp` module: + +```rs +use chrono::{Local, TimeZone}; +use parse_datetime::parse_timpestamp; + +let ts = parse_timestamp("@1234").unwrap(); +assert_eq!(ts, 1234); +``` ### Supported Formats The `parse_datetime` and `parse_datetime_at_date` functions support absolute datetime and the following relative times: From 0922b391b49e4fa1e4a0e43431affeb2031872a6 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sat, 23 Sep 2023 10:37:14 +0200 Subject: [PATCH 04/10] make parse_weekday public --- src/parse_weekday.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/parse_weekday.rs b/src/parse_weekday.rs index d61aca7..23fb6fa 100644 --- a/src/parse_weekday.rs +++ b/src/parse_weekday.rs @@ -13,7 +13,7 @@ macro_rules! tag_match { }; } -pub(crate) fn parse_weekday(s: &str) -> Option { +pub fn parse_weekday(s: &str) -> Option { let s = s.trim().to_lowercase(); let s = s.as_str(); From 3bab6bdfea4fa19249af2f6f64869adb7638260d Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sat, 23 Sep 2023 10:37:23 +0200 Subject: [PATCH 05/10] expose the various features --- src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index de65b56..9c987c1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,11 +12,11 @@ use regex::Error as RegexError; use std::error::Error; use std::fmt::{self, Display}; -// Expose parse_datetime -mod parse_relative_time; -mod parse_timestamp; +// Expose other features from this crate +pub mod parse_relative_time; +pub mod parse_timestamp; -mod parse_weekday; +pub mod parse_weekday; use chrono::{ DateTime, Datelike, Duration, FixedOffset, Local, LocalResult, NaiveDateTime, TimeZone, From 5d2a67c205c2de3af727f08b2420517321b891a3 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sat, 23 Sep 2023 10:37:35 +0200 Subject: [PATCH 06/10] add examples to make sure we can use them properly --- tests/simple.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/simple.rs b/tests/simple.rs index 8b13789..0df5bb5 100644 --- a/tests/simple.rs +++ b/tests/simple.rs @@ -1 +1,32 @@ +use chrono::{Duration, Local,Weekday}; +use parse_datetime::{parse_datetime_at_date, parse_relative_time::parse_relative_time, parse_timestamp::parse_timestamp, parse_weekday::parse_weekday}; +#[test] +fn test_parse_datetime_at_date() { + let now = Local::now(); + let after = parse_datetime_at_date(now, "+3 days"); + + assert_eq!( + (now + Duration::days(3)).naive_utc(), + after.unwrap().naive_utc() + ); +} + +#[test] +fn test_parse_relative_time() { + let one_minute = parse_relative_time("1 minute").unwrap(); + assert_eq!(one_minute, Duration::seconds(60)); +} + +#[test] +fn test_parse_timestamp() { + let ts = parse_timestamp("@1234").unwrap(); + assert_eq!(ts, 1234); +} + + +#[test] +fn test_weekday() { + let mon = parse_weekday("monday").unwrap(); + assert_eq!(mon, Weekday::Mon); +} From 62345bff9240b0eab723c038a448823df21cea79 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sat, 23 Sep 2023 10:49:17 +0200 Subject: [PATCH 07/10] add examples to make sure we can use them properly --- tests/simple.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/simple.rs b/tests/simple.rs index 0df5bb5..5cc62c2 100644 --- a/tests/simple.rs +++ b/tests/simple.rs @@ -1,5 +1,8 @@ -use chrono::{Duration, Local,Weekday}; -use parse_datetime::{parse_datetime_at_date, parse_relative_time::parse_relative_time, parse_timestamp::parse_timestamp, parse_weekday::parse_weekday}; +use chrono::{Duration, Local, Weekday}; +use parse_datetime::{ + parse_datetime_at_date, parse_relative_time::parse_relative_time, + parse_timestamp::parse_timestamp, parse_weekday::parse_weekday, +}; #[test] fn test_parse_datetime_at_date() { @@ -24,7 +27,6 @@ fn test_parse_timestamp() { assert_eq!(ts, 1234); } - #[test] fn test_weekday() { let mon = parse_weekday("monday").unwrap(); From eae69bf903ca80d0d9de49c2c697d2add0959e72 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sat, 23 Sep 2023 10:38:23 +0200 Subject: [PATCH 08/10] update of the example for weekday --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index 03e2bcf..f3b2f82 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,17 @@ use parse_datetime::parse_timpestamp; let ts = parse_timestamp("@1234").unwrap(); assert_eq!(ts, 1234); ``` + +For weekday parsing, import the `parse_weekday` module: + +```rs +use chrono::{Local, TimeZone}; +use parse_datetime::parse_weekday; + +let mon = parse_weekday("monday").unwrap(); +assert_eq!(mon, Weekday::Mon); +``` + ### Supported Formats The `parse_datetime` and `parse_datetime_at_date` functions support absolute datetime and the following relative times: From ab1d9b30373b3d023423aab197877020413eb2bd Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sat, 23 Sep 2023 10:39:15 +0200 Subject: [PATCH 09/10] version 0.5.1 --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cd3b98a..24a9be7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -151,7 +151,7 @@ checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" [[package]] name = "parse_datetime" -version = "0.5.0" +version = "0.5.1" dependencies = [ "chrono", "nom", diff --git a/Cargo.toml b/Cargo.toml index 5255ddb..d56241d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "parse_datetime" description = "parsing human-readable time strings and converting them to a DateTime" -version = "0.5.0" +version = "0.5.1" edition = "2021" license = "MIT" repository = "https://github.com/uutils/parse_datetime" From fade16a32c7b54c32889735803c7819aa87ec1e8 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sat, 23 Sep 2023 10:49:50 +0200 Subject: [PATCH 10/10] add missing license headers --- fuzz/fuzz_targets/parse_datetime.rs | 3 +++ tests/simple.rs | 3 +++ 2 files changed, 6 insertions(+) diff --git a/fuzz/fuzz_targets/parse_datetime.rs b/fuzz/fuzz_targets/parse_datetime.rs index 289bbb3..f3f98cb 100644 --- a/fuzz/fuzz_targets/parse_datetime.rs +++ b/fuzz/fuzz_targets/parse_datetime.rs @@ -1,3 +1,6 @@ +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. + #![no_main] use libfuzzer_sys::fuzz_target; diff --git a/tests/simple.rs b/tests/simple.rs index 5cc62c2..8187ab1 100644 --- a/tests/simple.rs +++ b/tests/simple.rs @@ -1,3 +1,6 @@ +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. + use chrono::{Duration, Local, Weekday}; use parse_datetime::{ parse_datetime_at_date, parse_relative_time::parse_relative_time,