tobyink / p5-json-schema

1 stars 4 forks source link

Format date-time Regex does not Match Timezone Offset and Fractions of a Second #14

Open tobyink opened 3 years ago

tobyink commented 3 years ago

Migrated from rt.cpan.org #110148 (status was 'new')

Requestors:

From tmurray.no@meat.wumpus-cave.net on 2015-12-07 19:36:48 :

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