Stream: implementers
Topic: date regular expression
Richard Townley-O'Neill (Jul 21 2017 at 05:53):
I'm looking at hl7.org/fhir/STU3/datatypes.html#date
The Regex for date: -?[0-9]{4}(-(0[1-9]|1[0-2])(-(0[0-9]|[1-2][0-9]|3[0-1]))?)? allows the following
000
0000-01
0000-01-00
but prohibits
0000-00-00
Why allow 00 for day but not for month?
Richard Townley-O'Neill (Jul 21 2017 at 05:54):
dateTime is the same.
Grahame Grieve (Jul 21 2017 at 21:27):
how does it allow 000?
Grahame Grieve (Jul 21 2017 at 21:28):
allowing 00 for the day is an oversight
Richard Townley-O'Neill (Jul 24 2017 at 01:15):
[0-9]{4} allows 0000
Richard Townley-O'Neill (Jul 24 2017 at 01:15):
http://www.freeformatter.com/regex-tester.html processes it that way.
Grahame Grieve (Jul 24 2017 at 01:16):
ok. it does allow 0000 (but not 000). I don't think it's worth complicating the regular expression enough to prohibit 0000 as a year
Richard Townley-O'Neill (Jul 24 2017 at 01:17):
Oops, I meant 0000. :)
Richard Townley-O'Neill (Jul 24 2017 at 01:19):
Allowing a year 0000 permits 0000-12-31 for birthday is 31st of December, but year of birth is unknown. Is that intended?
Grahame Grieve (Jul 24 2017 at 01:19):
no that would be wrong
Richard Townley-O'Neill (Jul 24 2017 at 01:27):
Prohibiting 9999-12-00 can be done with
-?[0-9]{4}(-(0[1-9]|1[0-2])(-(0[1-9]|[1-2][0-9]|3[0-1]))?)?
Richard Townley-O'Neill (Jul 24 2017 at 02:04):
Replacing [0-9]{4}
with [0-9]([0-9]([0-9][1-9]|[1-9]0)|[1-9]00)|[1-9]000
should prevent a year of 0000
Richard Townley-O'Neill (Jul 24 2017 at 02:18):
Issue #13684 created
Grahame Grieve (Jul 24 2017 at 02:19):
is that worth it is it?
Richard Townley-O'Neill (Jul 24 2017 at 04:41):
That depends upon what the point of the Regex expression is.
It is so nasty to read that making it worse does not seem to be much of a problem.
Making it exact means it could be used to validate dates or generate validations.
Richard Townley-O'Neill (Jul 24 2017 at 04:43):
For describing what strings date
allows, examples are easier for casual readers than a Regex
Lloyd McKenzie (Jul 24 2017 at 17:29):
There's a limit to how exact it can be. If we wanted to be wild and crazy, we could factor in leap years too. The existing structure makes clear that month comes before day and communicates the syntax. That plus "and must be a valid date" is all that's needed.
John Moehrke (Jul 24 2017 at 17:58):
leap-seconds are important... make sure you can process a 'second' indicator that is 0-60; not just 0-59
Grahame Grieve (Jul 24 2017 at 18:00):
can you make a task, because we don't.
John Moehrke (Jul 24 2017 at 18:05):
done GF#13685
Grahame Grieve (Jul 24 2017 at 18:05):
thanks
Last updated: Apr 12 2022 at 19:14 UTC