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
3 changes: 3 additions & 0 deletions crates/winnow-datetime/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

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.2"
version = "0.2.3"
description = "Parsing dates using winnow"
keywords = [ "iso8601", "date-time", "parser", "winnow" ]
categories = [ "parser-implementations", "date-and-time" ]
Expand Down
28 changes: 23 additions & 5 deletions crates/winnow-datetime/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<chrono::FixedOffset>`

### 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
Expand Down
20 changes: 15 additions & 5 deletions crates/winnow-datetime/src/convert/jiff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,10 @@ impl TryFrom<crate::Date> 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()
}
}
}
Expand Down Expand Up @@ -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 {
Expand Down
Loading