I want a TypeScript function that checks if an ISO 8601 datetime string is in UTC. So the output should be:
isUTC('2020-01-01T00:00:00Z') // true
isUTC('2020-01-01T00:00:00+00') // true
isUTC('2020-01-01T00:00:00+0000) // true
isUTC('2020-01-01T00:00:00+00:00') // true
isUTC('2020-01-01T00:00:00+01) // false
isUTC('2020-01-01T00:00:00+0100) // false
isUTC('2020-01-01T00:00:00+01:00') // false
If possible I would like to avoid regular expressions and use an existing parser or decomposer instead. Ideally there would be a library that decomposes ISO 8601 strings, so that I can check Iso8601Decomposer(value).timezoneOffset === 0
. Does something like this exist in TypeScript/JavaScript?
I found some answers that were checking if value === new Date(Date.parse(value)).toISOString()
, but this does not work for lines 2 and 3 above.