diff --git a/crates/winnow-datetime-assert/Cargo.toml b/crates/winnow-datetime-assert/Cargo.toml index 3421d49..6ba9b14 100644 --- a/crates/winnow-datetime-assert/Cargo.toml +++ b/crates/winnow-datetime-assert/Cargo.toml @@ -13,7 +13,7 @@ readme = "README.md" edition = "2021" [dependencies] -winnow_datetime = { path = "../winnow-datetime", version = "0.2.0", features = ["serde"] } +winnow_datetime = { path = "../winnow-datetime", version = "0.2", features = ["serde"] } libtest-mimic = "0.8.1" winnow = "0.7" serde = { version = "1.0", features = ["derive"] } diff --git a/crates/winnow-datetime/CHANGELOG.md b/crates/winnow-datetime/CHANGELOG.md index 4288f47..5bf742b 100644 --- a/crates/winnow-datetime/CHANGELOG.md +++ b/crates/winnow-datetime/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.2.1 - 2015-05-11 +* Made the convert modules public so that they can be used outside of the crate. +* Added TryInto for time::OffsetDateTime + ## 0.2.0 - 2015-05-04 * Changed `Stream` helper type to `PartialInput` since this name conflicts with the winnow naming scheme and causes confusion. * Bumped winnow version to 0.7 and changed parser singatures to match standard winnow parsers diff --git a/crates/winnow-datetime/Cargo.toml b/crates/winnow-datetime/Cargo.toml index c70adfb..dbc190e 100644 --- a/crates/winnow-datetime/Cargo.toml +++ b/crates/winnow-datetime/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "winnow_datetime" -version = "0.2.0" +version = "0.2.1" description = "Parsing dates using winnow" keywords = [ "iso8601", "date-time", "parser", "winnow" ] categories = [ "parser-implementations", "date-and-time" ] diff --git a/crates/winnow-datetime/src/convert/mod.rs b/crates/winnow-datetime/src/convert/mod.rs index 3920fe9..776051f 100644 --- a/crates/winnow-datetime/src/convert/mod.rs +++ b/crates/winnow-datetime/src/convert/mod.rs @@ -1,5 +1,5 @@ #[cfg(feature = "time")] -mod time; +pub mod time; #[cfg(feature = "chrono")] -mod chrono; +pub mod chrono; diff --git a/crates/winnow-datetime/src/convert/time.rs b/crates/winnow-datetime/src/convert/time.rs index 807b894..bd3c5e7 100644 --- a/crates/winnow-datetime/src/convert/time.rs +++ b/crates/winnow-datetime/src/convert/time.rs @@ -71,11 +71,39 @@ impl TryFrom for time::PrimitiveDateTime { } } +impl TryFrom for time::OffsetDateTime { + type Error = (); + + fn try_from(iso: crate::DateTime) -> Result { + let naive_date = time::Date::try_from(iso.date)?; + let naive_time = time::Time::try_from(iso.time)?; + + if let Some(o) = iso.time.offset { + if o.offset_hours == 0 && o.offset_minutes == 0 { + Ok(time::OffsetDateTime::new_utc(naive_date, naive_time)) + } else { + Ok(time::OffsetDateTime::new_in_offset( + naive_date, + naive_time, + time::UtcOffset::from_hms(o.offset_hours as i8, o.offset_minutes as i8, 0) + .unwrap(), + )) + } + } else { + Ok(time::OffsetDateTime::new_utc(naive_date, naive_time)) + } + } +} + impl crate::DateTime { /// create a [`time::PrimitiveDateTime`] if possible pub fn into_primitive(self) -> Option { time::PrimitiveDateTime::try_from(self).ok() } + + pub fn into_offset(self) -> Option { + time::OffsetDateTime::try_from(self).ok() + } } #[cfg(test)] diff --git a/crates/winnow-datetime/src/lib.rs b/crates/winnow-datetime/src/lib.rs index fc119b8..84a9a91 100644 --- a/crates/winnow-datetime/src/lib.rs +++ b/crates/winnow-datetime/src/lib.rs @@ -2,7 +2,7 @@ extern crate core; mod clippy; #[cfg(any(feature = "time", feature = "chrono"))] -mod convert; +pub mod convert; mod macros; pub mod parser; pub mod types; diff --git a/crates/winnow-iso8601/CHANGELOG.md b/crates/winnow-iso8601/CHANGELOG.md index c9afe4e..93a6925 100644 --- a/crates/winnow-iso8601/CHANGELOG.md +++ b/crates/winnow-iso8601/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 0.5.1 - 2024-05-11 +* Dependency on winnow-datetime 0.2 instead of a more specific version +* Dropped feature "serde" for winnow-datetime since it isn't needed. + ## 0.5.0 - 2024-05-04 * Changed parser signatures to meet winnow 0.7 standards diff --git a/crates/winnow-iso8601/Cargo.toml b/crates/winnow-iso8601/Cargo.toml index 73c2dfc..c500bfa 100644 --- a/crates/winnow-iso8601/Cargo.toml +++ b/crates/winnow-iso8601/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "winnow_iso8601" -version = "0.5.0" +version = "0.5.1" description = "Parsing ISO8601 dates using winnow" keywords = [ "iso8601", "date-time", "parser", "winnow" ] categories = [ "parser-implementations", "date-and-time" ] @@ -14,7 +14,7 @@ edition = "2021" [dependencies] winnow = { version = "0.7" } -winnow_datetime = { path = "../winnow-datetime", features = ["serde"], version = "0.2.0" } +winnow_datetime = { path = "../winnow-datetime", version = "0.2" } chrono = { version = "0.4", default-features = false, optional = true } time = { version = "0.3.37", default-features = false, optional = true } num-traits = { version = "0.2", optional = true } diff --git a/crates/winnow-rfc3339/CHANGELOG.md b/crates/winnow-rfc3339/CHANGELOG.md index 7ab4dd9..8b3399b 100644 --- a/crates/winnow-rfc3339/CHANGELOG.md +++ b/crates/winnow-rfc3339/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## 0.2.1 - 2024-05-11 +* Dependency on winnow-datetime 0.2 instead of a more specific version + ## 0.2.0 - 2024-05-04 * Changed parser signatures to meet winnow 0.7 standards * Removed mistaken dependency on winnow-datetime-assert, now only using winnow-datetime-assert as a dev-dependency diff --git a/crates/winnow-rfc3339/Cargo.toml b/crates/winnow-rfc3339/Cargo.toml index 536bbc5..803e6c1 100644 --- a/crates/winnow-rfc3339/Cargo.toml +++ b/crates/winnow-rfc3339/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "winnow_rfc3339" -version = "0.2.0" +version = "0.2.1" description = "Parsing RFC 3339 dates using winnow" keywords = [ "rfc3339", "date-time", "parser", "winnow" ] categories = [ "parser-implementations", "date-and-time" ] @@ -14,7 +14,7 @@ edition = "2021" [dependencies] winnow = { version = "0.7" } -winnow_datetime = { path = "../winnow-datetime", version = "0.2.0" } +winnow_datetime = { path = "../winnow-datetime", version = "0.2" } chrono = { version = "0.4", default-features = false, optional = true } time = { version = "0.3.37", default-features = false, optional = true } num-traits = { version = "0.2", optional = true }