ISO8601 Ordinal Date support? #375
-
|
I am working on a set of parsers based on winnow https://crates.io/crates/winnow_datetime which support parsing common date time formats (currently ISO8601 and RFC3999). So far, adding conversions from the existing AST to jiff has been wonderfully straight forward. However, I don't see a way to create a civil::Date object from the ordinal dates (i.e. 2024-122) which is supported by ISO8601? Is support for creating a date for ordinal dates along the lines of civil::ISOWeekDate possible? I am not sure if the internal parser supports this format, but I would like to avoid reparsing the date value if at all possible. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
|
If you're looking to parse use jiff::civil;
fn main() -> anyhow::Result<()> {
let date = civil::Date::strptime("%Y-%j", "2024-122")?;
assert_eq!(date, civil::date(2024, 5, 1));
Ok(())
}But it sounds like you are owning the parsing. In that case, you'll want to use use jiff::civil;
fn main() -> anyhow::Result<()> {
let date =
civil::Date::new(2024, 1, 1)?.with().day_of_year(122).build()?;
assert_eq!(date, civil::date(2024, 5, 1));
Ok(())
}
Jiff provides |
Beta Was this translation helpful? Give feedback.
-
Taking a quick look here, one thing I'd suggest adding is time zone support. Specifically, RFC 9557. Note also that Jiff supports the Temporal ISO 8601 grammar. It is a marriage of ISO 8601, RFC 3339 and RFC 9557. |
Beta Was this translation helpful? Give feedback.
If you're looking to parse
2024-122, then that can be done with Jiff'sstrptimeAPIs:But it sounds like you are owning the parsing. In that case, you'll want to use
Date::withto do those sorts of manipulations. It returns a builder which lets you set a number of fields. ThewithAPIs are available on all datetime types, including onZoned. Here's how to do it: