Skip to content

Commit 57fcf47

Browse files
committed
Support for ordinal dates in jiff conversions
1 parent 71f72af commit 57fcf47

File tree

4 files changed

+42
-11
lines changed

4 files changed

+42
-11
lines changed

crates/winnow-datetime/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 0.2.3 - 2015-05-14
2+
* Support for `Date::Ordinal` conversions to `jiff::civil::Date`
3+
14
## 0.2.2 - 2015-05-14
25
* Added convert::jiff for jiff support of date and time
36

crates/winnow-datetime/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "winnow_datetime"
3-
version = "0.2.2"
3+
version = "0.2.3"
44
description = "Parsing dates using winnow"
55
keywords = [ "iso8601", "date-time", "parser", "winnow" ]
66
categories = [ "parser-implementations", "date-and-time" ]

crates/winnow-datetime/README.md

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,29 @@ is the most common format used on the internet.
2929
dates, times, durations, and intervals. [ISO8601](https://en.wikipedia.org/wiki/ISO_8601) is a very ambitious format
3030
that can represent a wide range of date and time concepts.
3131

32-
### Conversion
33-
[winnow-datetime] provides a set of TryInto implementations to convert to common rust date/time libraries. Currently
34-
chrono, jiff, and time are supported. Each have a feature flag of the same name as the lib to enable support for the
35-
conversions. The TryInto implementations are available with the features and so try_into() could be called to convert to
36-
any of the compatible types.
32+
## Conversion
33+
[winnow-datetime] provides a set of TryInto implementations to convert to common rust date/time libraries. Each have a
34+
feature flag of the same name as the lib to enable support for the conversions. The TryInto implementations are
35+
available with the features and so try_into() could be called to convert to any of the compatible types which are listed
36+
below.
37+
38+
### chrono
39+
* `Date` -> `chrono::NaiveDate`
40+
* `Time` -> `chrono::NaiveTime`
41+
* `DateTime` -> `chrono::DateTime<chrono::FixedOffset>`
42+
43+
### jiff
44+
* `Date` -> `jiff::civil::Date`
45+
* `DateTime` -> `jiff::civil::DateTime`
46+
* `DateTime` -> `jiff::Zoned`
47+
* `Duration` -> `jiff::Span`
48+
* `Time` -> `jiff::civil::Time`
49+
50+
### time
51+
* `Time` -> `time::Time`
52+
* `Date` -> `time::Date`
53+
* `DateTime` -> `time::PrimitiveDateTime`
54+
* `DateTime` -> `time::OffsetDateTime`
3755

3856
## Parsing Something Strange
3957
Despite there being countless specifications some people will still come up with their own way to poetically express a

crates/winnow-datetime/src/convert/jiff.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,10 @@ impl TryFrom<crate::Date> for jiff::civil::Date {
5050
}
5151

5252
crate::Date::Ordinal { year, day } => {
53-
unimplemented!(
54-
"Ordinal date conversion for {}-{} not implemented for jiff",
55-
year,
56-
day
57-
);
53+
jiff::civil::Date::new(year.try_into().unwrap(), 1, 1)?
54+
.with()
55+
.day_of_year(day.try_into().unwrap())
56+
.build()
5857
}
5958
}
6059
}
@@ -188,6 +187,17 @@ mod date_and_time {
188187
assert_eq!(datetime.second(), 0);
189188
}
190189

190+
#[test]
191+
fn date_from_yddd() {
192+
let dt = crate::Date::Ordinal {
193+
year: 2024,
194+
day: 122,
195+
};
196+
197+
let date = jiff::civil::Date::try_from(dt).unwrap();
198+
assert_eq!(date, jiff::civil::date(2024, 5, 1));
199+
}
200+
191201
#[test]
192202
fn span_from_duration() {
193203
let d = crate::Duration {

0 commit comments

Comments
 (0)