MatchesXsDateTimeUtc🔗

Type: Pattern verification
Check that text conforms to the pattern of an xs:dateTime.

The time zone must be fixed to UTC. We verify only that the text matches a pre-defined pattern. We do not verify that the day of month is correct nor do we check for leap seconds.

See: https://www.w3.org/TR/xmlschema-2/#dateTime

text🔗
Text to be checked
Return🔗
True if the text conforms to the pattern

Code

digit = '[0-9]'
yearFrag = (
    f'-?(([1-9]{digit}{digit}{digit}+)|(0{digit}{digit}{digit}))'
)
monthFrag = (
    '((0[1-9])|(1[0-2]))'
)
dayFrag = (
    f'((0[1-9])|([12]{digit})|(3[01]))'
)
hourFrag = (
    f'(([01]{digit})|(2[0-3]))'
)
minuteFrag = (
    f'[0-5]{digit}'
)
secondFrag = (
    f'([0-5]{digit})(\\.{digit}+)?'
)
endOfDayFrag = (
    '24:00:00(\\.0+)?'
)
timezoneFrag = (
    '(Z|\\+00:00|-00:00)'
)
dateTimeLexicalRep = (
    f'{yearFrag}-{monthFrag}-{dayFrag}T(({hourFrag}:{minuteFrag}:{secondFrag})|{endOfDayFrag}){timezoneFrag}'
)
pattern = (
    f'^{dateTimeLexicalRep}$'
)
return match(
    pattern,
    text
) is not None