diff --git a/crates/winnow-datetime/CHANGELOG.md b/crates/winnow-datetime/CHANGELOG.md index 70eb2d7..b575db1 100644 --- a/crates/winnow-datetime/CHANGELOG.md +++ b/crates/winnow-datetime/CHANGELOG.md @@ -1,3 +1,6 @@ +## 0.2.3 - 2015-05-14 +* Support for `Date::Ordinal` conversions to `jiff::civil::Date` + ## 0.2.2 - 2015-05-14 * Added convert::jiff for jiff support of date and time diff --git a/crates/winnow-datetime/Cargo.toml b/crates/winnow-datetime/Cargo.toml index ae6ca69..77b5029 100644 --- a/crates/winnow-datetime/Cargo.toml +++ b/crates/winnow-datetime/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "winnow_datetime" -version = "0.2.2" +version = "0.2.3" description = "Parsing dates using winnow" keywords = [ "iso8601", "date-time", "parser", "winnow" ] categories = [ "parser-implementations", "date-and-time" ] diff --git a/crates/winnow-datetime/README.md b/crates/winnow-datetime/README.md index 5743260..64dd435 100644 --- a/crates/winnow-datetime/README.md +++ b/crates/winnow-datetime/README.md @@ -29,11 +29,29 @@ is the most common format used on the internet. dates, times, durations, and intervals. [ISO8601](https://en.wikipedia.org/wiki/ISO_8601) is a very ambitious format that can represent a wide range of date and time concepts. -### Conversion -[winnow-datetime] provides a set of TryInto implementations to convert to common rust date/time libraries. Currently -chrono, jiff, and time are supported. Each have a feature flag of the same name as the lib to enable support for the -conversions. The TryInto implementations are available with the features and so try_into() could be called to convert to -any of the compatible types. +## Conversion +[winnow-datetime] provides a set of TryInto implementations to convert to common rust date/time libraries. Each have a +feature flag of the same name as the lib to enable support for the conversions. The TryInto implementations are +available with the features and so try_into() could be called to convert to any of the compatible types which are listed +below. + +### chrono +* `Date` -> `chrono::NaiveDate` +* `Time` -> `chrono::NaiveTime` +* `DateTime` -> `chrono::DateTime` + +### jiff +* `Date` -> `jiff::civil::Date` +* `DateTime` -> `jiff::civil::DateTime` +* `DateTime` -> `jiff::Zoned` +* `Duration` -> `jiff::Span` +* `Time` -> `jiff::civil::Time` + +### time +* `Time` -> `time::Time` +* `Date` -> `time::Date` +* `DateTime` -> `time::PrimitiveDateTime` +* `DateTime` -> `time::OffsetDateTime` ## Parsing Something Strange Despite there being countless specifications some people will still come up with their own way to poetically express a diff --git a/crates/winnow-datetime/src/convert/jiff.rs b/crates/winnow-datetime/src/convert/jiff.rs index 0044bf9..1b3d2f0 100644 --- a/crates/winnow-datetime/src/convert/jiff.rs +++ b/crates/winnow-datetime/src/convert/jiff.rs @@ -50,11 +50,10 @@ impl TryFrom for jiff::civil::Date { } crate::Date::Ordinal { year, day } => { - unimplemented!( - "Ordinal date conversion for {}-{} not implemented for jiff", - year, - day - ); + jiff::civil::Date::new(year.try_into().unwrap(), 1, 1)? + .with() + .day_of_year(day.try_into().unwrap()) + .build() } } } @@ -188,6 +187,17 @@ mod date_and_time { assert_eq!(datetime.second(), 0); } + #[test] + fn date_from_yddd() { + let dt = crate::Date::Ordinal { + year: 2024, + day: 122, + }; + + let date = jiff::civil::Date::try_from(dt).unwrap(); + assert_eq!(date, jiff::civil::date(2024, 5, 1)); + } + #[test] fn span_from_duration() { let d = crate::Duration {