Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/winnow-datetime-assert/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
4 changes: 4 additions & 0 deletions crates/winnow-datetime/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion crates/winnow-datetime/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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" ]
Expand Down
4 changes: 2 additions & 2 deletions crates/winnow-datetime/src/convert/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#[cfg(feature = "time")]
mod time;
pub mod time;

#[cfg(feature = "chrono")]
mod chrono;
pub mod chrono;
28 changes: 28 additions & 0 deletions crates/winnow-datetime/src/convert/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,39 @@ impl TryFrom<crate::DateTime> for time::PrimitiveDateTime {
}
}

impl TryFrom<crate::DateTime> for time::OffsetDateTime {
type Error = ();

fn try_from(iso: crate::DateTime) -> Result<Self, Self::Error> {
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> {
time::PrimitiveDateTime::try_from(self).ok()
}

pub fn into_offset(self) -> Option<time::OffsetDateTime> {
time::OffsetDateTime::try_from(self).ok()
}
}

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion crates/winnow-datetime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions crates/winnow-iso8601/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 2 additions & 2 deletions crates/winnow-iso8601/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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" ]
Expand All @@ -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 }
Expand Down
3 changes: 3 additions & 0 deletions crates/winnow-rfc3339/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions crates/winnow-rfc3339/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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" ]
Expand All @@ -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 }
Expand Down
Loading