-
Notifications
You must be signed in to change notification settings - Fork 153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
why isn't a datetime string like 2024-08-24T14:00:00-05
allowed to be parsed into a ZonedDateTime
?
#2930
Comments
Huh, isn't Temporal grammar lists UTCOffset as taking FWIW, I did test the below cases in #[test]
fn test_hour_utc_offset() {
let tz_test = "2024-08-24T14:00:00-05[-05]";
let result = IxdtfParser::from_str(&tz_test).parse();
assert!(result.is_ok());
let tz_test = "2024-08-24T14:00:00-05";
let result = IxdtfParser::from_str(&tz_test).parse();
assert!(result.is_ok());
} So at least from that perspective, there wouldn't be any deviation 😄 |
Just to be clear, do you mean If you try to parse |
It's not the grammar I'm asking about here. It makes sense that the lower level parsing routine accepts it. It's about what |
Oh, sorry! 😅 The documentation isn't out of sync. But I'd 100% defer to the champions on this in general. |
Yep! There is definitely a footgun. If you have a ZonedDateTime object, then callers expect that they can derive other ZDT objects from it, e.g. by adding a Duration, by using If Temporal allowed parsing RFC3339 strings like In other words, if a developer tries to parse a timezone-less string into a ZDT, it's almost certainly a programmer bug not an intentional bypassing of the ZDT guardrails. Temporal is pretty agressive across the API at making "likely bug" cases illegal. For example, you also can't parse a string like Similarly, to prevent programmer bugs from timezone-less strings, we disallow parsing strings into a ZDT unless there's a time zone annotation. This ensures that developers won't accidentally parse a timezone-less string and then treat the resulting ZDT as if it had a real time zone. They can still fake it using an offset time zone, but they have to opt into extra work to do it, which makes is somewhat more likely that they actually are intending to break the rules and are aware of the consequences of doing so: that downstream consumers of that ZDT can't rely on its time zone to derive more ZDT objects. Instead, users who have RFC3339 strings should be parsing those strings into Out of curiosity, what are the use cases where people are wanting to parse these strings into a ZDT? Why isn't Instant good enough? If the need is just to get the individual components (offset, year, month, day, hour, ...) from an RFC3339 string, then a developer can use this (intentionally less ergonomic than regular parsing in order to discourage accidental use) code like this: function getOffsetOfRFC3339String(s) {
return Temporal.Instant.from(s).toZonedDateTimeISO(s).offset;
}
getOffsetOfRFC3339String('2024-08-24T14:00:00-05:00')
// => '-05:00' I'd strongly advise against passing ZDTs parsed in this way to any other code, because it's not really a time zone and will break downstream code. |
Sorry, forgot to answer this question directly in my earlier comment: I think this would be bad! It would mean that Jiff's ZDT could not be trusted by downstream callers, because there'd be no way to know if the time zone of the ZDT is a real human time zone, or a programmer bug where they parsed a timezone-less string as if it had a real time zone. |
Thanks for the reply @justingrant! Much appreciated. I now understand the motivation on Temporal's side here much better.
Ah yeah this is interesting. The downside with this though is that it isn't just less ergonomic, but it's also more expensive since it appears to need to parse I also didn't realize you could do that with the Temporal API. I'm not sure if the docs for
I am still trying to understand that myself. Here's one example. You'll notice that I phrase "I do not understand" in a few different ways. :-) I filed this issue because I also wanted to make sure I understood things from the other side too here, even if the use cases end up not being compelling enough.
Yeah this makes sense. It's a big part of what attracted me to Temporal. :-)
I think this is the crux of the matter. And in particular:
The way I conceptualize this is that the My sense here is that it might be worth Jiff growing a opt-in option to parse a ZDT from a timezone-less RFC3339 instant (accepting a fixed offset, but not Zulu). I think this would match the spirit of "intentionally less ergonomic than regular parsing in order to discourage accidental use" but without requiring double-parsing. It would look something like this: use jiff::fmt::temporal::DateTimeParser;
static PARSER: DateTimeParser = DateTimeParser::new().time_zone_annotation_requried(false);
let zdt = PARSER.parsed_zoned("2024-08-24T14:00:00-05").unwrap();
assert_eq!(zdt.offset(), jiff::tz::offset(-5)); This is a lot more verbose than the typical way to parse a ZDT in Jiff. That is, |
It's not specific to
That's correct, and because the caller has gone through the extra effort to opt in, then ZDT can parse it.
I guess I would first ask: what use cases require a ZDT in this case as opposed to an Instant? What are callers trying to do with the returned ZDT that they can't do with an Instant? If the issue is purely a parsing thing ("I want to know every individual field of an RFC 9557 string) then you may be better served by a parsing-only function instead of a function that returns a ZDT. |
Yes, I agree. The use cases need to be flushed out more.
That's a possibility too. Jiff supports this via its |
Yep, that's the place to start. Let's better understand what users are trying to do, and why, and then we can figure out if ZDT is the right solution for those cases. Do you want to post a comment here when you learn more about the use cases behind these asks? |
Yes, will do. |
@justingrant I see that you are a contributor to RFC 9557. Question: If I want to store a datetime in the future (e.g. for a future meeting), like "2035-11-08 14:00:00" in Belgium,
Omitting the offset, specifying at this local time in Europe/Brussels, whatever the offset from UTC at that time (we don't know for sure; who knows, DST is probably abolished in EU by that time). Instead, to be compliant, it seems I would need to "guess" the offset (as DST rules might change):
I know for sure the time zone identifier is correct, but not the offset. I want to mention: resolve the date time first by the provided time zone ID. |
@francois08 RFC 9557 is for exact time strings, and |
@ptomato I assumed the point of this standard is to address the lack of time zone information in ISO 8601 and RFC 3339, where we lose daylight saving time details. But DST and exact times don't go well together as DST is uncertain/variable for future date times. |
@francois08 Nonetheless, |
Sorry for late reply, I've been traveling for work for a few weeks.
The specific goal of RFC 9557 is to extend RFC 3339 with time zone information. Therefore, the standard's format's data model was intended to be backwards compatible with RFC 3339, so applications can strip off all content after the first There was discussion during the development of the standard about whether to handle the case you mentioned (we called it "floating" timestamps) but ultimately we decided to keep the scope limited to only a superset of RFC 3339, which leaves space for a future standard to define how floating timestamps should be handled. (And ensured that RFC 9557, which had already taken years, would finally ship!) As @ptomato notes above, Temporal does accept formats like
Handling this case is exactly why Temporal allows the offset to be omitted. By omitting the offset, you're telling Temporal that you want to evaluate the string always using the time zone rules that are effective when the string is parsed. Including both is also useful, because then you can deal with conflicts better. For example, you can parse the string using the option |
I think we've addressed the questions above, so I'll close this issue now. Feel free to re-open if more discussion needed. Thanks! |
In particular, one possible result of parsing
2024-08-24T14:00:00-05
would be as if it were written2024-08-24T14:00:00-05[-05]
?Some users of Jiff are running into this restriction and I guess it seems somewhat limiting for the sake of being limiting in some respect. In particular, a
ZonedDateTime
isn't just limited to an instant in a time zone, but it can be an instant in a fixed offset as well. So it seems like it would be fine to accept just a2024-08-24T14:00:00-05
as-is. Is this meant more as a gentle nudging toward using RFC 9557 everywhere? Or is there a footgun here that this restriction is preventing that I'm not seeing?And if Jiff were to allow parsing of
2024-08-24T14:00:00-05
directly into its analog ofZonedDateTime
, how bad of a deviation do you think that would be in your opinion?The text was updated successfully, but these errors were encountered: