Subject: | Format date-time Regex does not Match Timezone Offset and Fractions of a Second |
The current date-time format regex is:
qr/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/i
(The '/i' option seems unnecessary.)
This only matches dates with Zulu time. This format is specified in JSON Schema to match dates specified in RFC3339, section 5.6. This would include timezone offsets like "-0500" or "+0100", in addition to "Z" for zulu time.
A regex that expands the timezone offset is:
qr/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:Z|[+\-]\d{4})$/i
The RFC also specifies an optional fractional second, which comes after the seconds field as a ".0000". The number of digits unbounded.
Combined with the timezone offset, we get:
qr/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+\-]\d{4})$/i