-
-
Notifications
You must be signed in to change notification settings - Fork 34
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
Restrict literals for :date
and :time
#680
Comments
For the tech preview, I'm starting to think we probably ought to restrict the literal values for each of
This last one is of particular interest for JavaScript, where the language does not currently provide for a time-only parser. The Temporal proposal does introduce Temporal.PlainTime.from(), but that isn't in the spec yet. We already intend to include a note adding a dependency on Temporal regarding time zone name serialization, so I think extending that to also cover time parsing would be appropriate. I also have a specific concern about relying on the XML date specification, as it supports including an optional timezone offset on a date without a time, such as On the other hand, if we only support a full XML dateTime, we don't need to find answers to the above questions in the very short term, and we only inconvenience a very marginal set of use cases. |
As one minor relaxation, we could also support plain yyyy-mm-dd dates, as long as they did not include timezones. That's valid ISO 8601, and when used as a literal it's reasonable to fill out with a 00:00:00 time from the system timezone. That corresponds to the following regexp once its whitespace is removed:
|
The use of XMLSchema was semi-arbitrary on my part. We could use RFC3339 instead. The definitions there might be I don't think it makes that much sense to require The offset in both XMLSchema and 3339 is tricky. It is NOT a time zone. It adjusts the value by the offset's number of hours and minutes. I can totally live without the headache on date literals or time literals in the Tech Preview. |
Based on RFC3339, the regexp would be a bit simpler:
If we wanted to hedge our bets, this is the subset that's valid for both:
For |
As pointed out by @hsivonen during the ECMA-402 call, the HTML spec provides another reasonable ISO 8601 subset for us to depend on. That one supports 4+ digit years > 0, space as well as Then there's one in the JS spec as well, which extends the HTML definition by allowing I had not really realised before how much variance there was on these, and how they seem to semi-randomly restrict the expression of some datetimes and allow others. As far as I can tell, the core points of variance are:
As we aren't actually defining how a string gets parsed, and we're not really able to represent accurate limits on e.g. max days within a month using a regexp, I think the only sensible thing we can do is call our dates ISO 8601, make the regexp somewhat lax, and explicitly note that implementations may impose further restrictions on validity. Which I think leaves us with this:
|
Yes, the variability sucks. I disagree with just saying "ISO 8601" (which is far more expansive than just date/time values). And I disagree with being "permissive". We want messages to be portable and the writing of messages to be portable--not just for developers/translators, but also for tools and the larger ecosystem. It would be one thing to require implementations to support a relaxed syntax. It's quite another for us to allow a relaxed syntax for input and then all of the implementations be more strict (sort of an inverse Postel situation). I would also be somewhat unhappy as an implementer if I had to support a custom date/time format. One reason I changed to proposing 3339 above is that SEDATE extends 3339. Other folks will then need to consume the changes downstream. Support for real time zone names in date/time stamps isn't just important for Temporal. It's actually important for every time-related application. A couple of side notes. The 8601-based syntax depends on a proleptic Gregorian calendar, so dates before 1582 CE (and a lot of dates after that, due to adoption issues) are already on a tenuous footing. The year |
To rephrase my general viewpoint here, I would like us to arrive at some solution where a valid JS implementation can use either To achieve that, the solution I propose is to explicitly define a regexp for some subset of ISO 8601 that is valid ~everywhere, and to allow implementations to accept inputs beyond that. |
Fair enough. That works for me, although I'm leery of the "my message worked in X but not on Y" problem. |
That's why the custom regexp in #687, because anything matching that should work everywhere, as long as it doesn't use a non-existent day like 2024-02-31. |
Keeping this issue alive for further discussion of date/time/datetime literals. |
This is a spin-off from #665, which conflates this issue's nominal topic with a discussion of the
timeZone
options. The text below is an extract of the original by @aphillips.@eemeli noted that some literal values don't make sense with some of the date/time functions. Notably
date
literal with:time
ortime
literal with:date
.In LDML45, I propose:
:datetime
accepts XMLSchemadate
,time
, anddateTime
types as literal operands.:date
acceptsdate
anddateTime
:time
acceptstime
anddateTime
Note that not accepting all three types on all three functions makes for potential issues with declarations, since the temporal value would be rejected instead of passed to later calls. Examples:
The text was updated successfully, but these errors were encountered: