diff --git a/lib/util/timestamp.spec.ts b/lib/util/timestamp.spec.ts index c084c062f3025ededb6e188ec499ec4d014e0e53..1926ea478aed719313280d6600c2db93ec601e45 100644 --- a/lib/util/timestamp.spec.ts +++ b/lib/util/timestamp.spec.ts @@ -17,6 +17,8 @@ describe('util/timestamp', () => { ${'2021-01-01'} | ${'2021-01-01T00:00:00.000Z'} ${'20210101000000'} | ${'2021-01-01T00:00:00.000Z'} ${'20211231235959'} | ${'2021-12-31T23:59:59.000Z'} + ${'20210101000000+0000'} | ${'2021-01-01T00:00:00.000Z'} + ${'20211231235959+0000'} | ${'2021-12-31T23:59:59.000Z'} ${'Jan 1, 2021'} | ${'2021-01-01T00:00:00.000Z'} ${'2021/01/01'} | ${'2021-01-01T00:00:00.000Z'} ${'2021-01-02T00:00:00+05:30'} | ${'2021-01-01T18:30:00.000Z'} diff --git a/lib/util/timestamp.ts b/lib/util/timestamp.ts index b40fd93ead2d2a7cf346f8ddbd78d09682159d04..5c0e3d32b9c9c15d86772c35a9b3570e9a738f4f 100644 --- a/lib/util/timestamp.ts +++ b/lib/util/timestamp.ts @@ -64,6 +64,15 @@ export function asTimestamp(input: unknown): Timestamp | null { return numberLikeDate.toISO() as Timestamp; } + const numberLikeOffsetDate = DateTime.fromFormat( + input, + 'yyyyMMddHHmmssZZZ', + { zone: 'UTC' }, + ); + if (isValid(numberLikeOffsetDate)) { + return numberLikeOffsetDate.toISO() as Timestamp; + } + const fallbackDate = DateTime.fromMillis( Date.parse(input) - timezoneOffset, { zone: 'UTC' },