FHIR Chat · Regex Patten for dateTime · implementers

Stream: implementers

Topic: Regex Patten for dateTime


view this post on Zulip Dave Barnet (Feb 15 2019 at 11:18):

Its been brought to my attention that the regex pattern for dateTime differs from that declared in the schema files to that on the data type definition pages
http://hl7.org/fhir/STU3/datatypes.html#dateTime
Regex:
-?[0-9]{4}(-(0[1-9]|1[0-2])(-(0[0-9]|[1-2][0-9]|3[0-1])(T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5]0-9?(Z|(\+|-)((0[0-9]|1[0-3]):[0-5][0-9]|14:00)))?)?)?
In HL7 fhir schema
-?[0-9]{4}(-(0[1-9]|1[0-2])(-(0[0-9]|[1-2][0-9]|3[0-1])(T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5]0-9?(Z|(\+|-)((0[0-9]|1[0-3]):[0-5][0-9]|14:00))?)?)?)?
Which is correct (I'm assuming the schema?)

view this post on Zulip John Silva (Feb 15 2019 at 14:11):

@Dave Barnet - I don't know the answer but I used https://text-compare.com/ to see that the difference is the fourth question mark from the end. ?)?)?)?

Maybe this RegEx online parser page would be useful to test out which of the above is 'correct' with sample FHIR date/times: https://regex101.com/

view this post on Zulip Marcus Fearnett (Feb 15 2019 at 15:03):

@Dave Barnet
Top one from the spec is correct.
In FHIR spec, 'If hours and minutes are specified, a time zone SHALL be populated' so it's:
-?[0-9]{4}(-(0[1-9]|1[0-2])(-(0[0-9]|[1-2][0-9]|3[0-1])(T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5]0-9?(Z|(\+|-)((0[0-9]|1[0-3]):[0-5][0-9]|14:00)))?)?)?

-?[0-9]{4}(-(0[1-9]|1[0-2])(-(0[0-9]|[1-2][0-9]|3[0-1])(T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5]0-9?(Z|(\+|-)((0[0-9]|1[0-3]):[0-5][0-9]|14:00))?)?)?)?
leaves the offset part of a dateTime optional by lazy matching the group starting (Z|...)

p.s. It's only the STU3 schema that's off. The R4 version has got it correct.

view this post on Zulip Lloyd McKenzie (Feb 15 2019 at 15:41):

Can you submit a change request? We're doing an R3 patch soon and we might be able to fix this.

view this post on Zulip Simone Heckmann (Feb 17 2019 at 13:24):

@Alexander Zautke

view this post on Zulip Patrick Werner (Feb 17 2019 at 16:49):

looking @ R4:
what about the regex for time: ([01][0-9]|2[0-3]):[0-5][0-9]:([0-5][0-9]|60)(\.[0-9]+)?

view this post on Zulip Patrick Werner (Feb 17 2019 at 16:51):

i think the last capture group is wrong? What is the purpose of it?
Now something like: 08:23:12.2234323434534646234485767843756872980 would be valid

view this post on Zulip Grahame Grieve (Feb 17 2019 at 16:57):

not sure what the limits are on decimal places. I support up to 9

view this post on Zulip Patrick Werner (Feb 17 2019 at 16:58):

spec says: A time during the day, in the format hh:mm:ss whereas the regex allows infinite milliseconds

view this post on Zulip Grahame Grieve (Feb 17 2019 at 16:58):

fractions are allowed

view this post on Zulip Patrick Werner (Feb 17 2019 at 17:00):

ok. Couldn't find it in the spec here: http://build.fhir.org/datatypes.html#time

view this post on Zulip Patrick Werner (Feb 17 2019 at 17:01):

would be nice to have it explicitly stated to avoid misunderstandings

view this post on Zulip John Silva (Feb 17 2019 at 21:34):

Wow, where is that time machine that supports 'infinite milliseconds' ? :-)

view this post on Zulip Patrick Werner (Feb 18 2019 at 14:27):

i made a ticket: GF#20400]

view this post on Zulip Elliot Silver (Feb 19 2019 at 19:47):

What are infinite milliseconds? There are either milliseconds ([0-9]{1,3}) or infinite precision ([0-9]+).

view this post on Zulip Patrick Werner (Feb 19 2019 at 20:08):

please excuse my fuzzy language, i meant infinitely accurate fractions of a second = infinite precision


Last updated: Apr 12 2022 at 19:14 UTC