Negative dates parsing #387
-
|
Hello @BurntSushi, I often work with data from the humanities and BCE dates are not uncommon here. I stumbled upon this timestamp in Wikidata: |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
This is indeed intentional. Jiff follows the Temporal ISO 8601 grammar, which requires that datetimes prior to 1 BCE are represented with a leading Negative timestamps are somewhat odd and a bit of a grey area in ISO 8601 proper. According to ISO 8601, Note though that Jiff's use jiff::{civil::DateTime, tz::TimeZone};
fn main() -> anyhow::Result<()> {
let s = "-0280-01-01T00:00:00Z";
let dt = DateTime::strptime("%Y-%m-%dT%H:%M:%SZ", s)?;
let ts = dt.to_zoned(TimeZone::UTC)?.timestamp();
dbg!(ts);
Ok(())
}Or, if you want to specifically allow up to 6 digits for the year (it defaults to 4), then you can use use jiff::{civil::DateTime, tz::TimeZone};
fn main() -> anyhow::Result<()> {
let s = "-000280-01-01T00:00:00Z";
let dt = DateTime::strptime("%06Y-%m-%dT%H:%M:%SZ", s)?;
let ts = dt.to_zoned(TimeZone::UTC)?.timestamp();
dbg!(ts);
Ok(())
}
Did the error message from parsing |
Beta Was this translation helpful? Give feedback.
This is indeed intentional. Jiff follows the Temporal ISO 8601 grammar, which requires that datetimes prior to 1 BCE are represented with a leading
-and 6 digits for the year.Negative timestamps are somewhat odd and a bit of a grey area in ISO 8601 proper. According to ISO 8601,
-0280-01-01T00:00:00Zis not inherently invalid, but requires "mutual agreement" among the parties to agree upon it, including a specification on the number of digits to allow for the year.Note though that Jiff's
strptimesupport is a bit more flexible. For example, this works: