Skip to content
Snippets Groups Projects
Unverified Commit 1f4790c9 authored by Sergei Zharinov's avatar Sergei Zharinov Committed by GitHub
Browse files

feat(timestamp): Parse number-like dates plus offset (#33647)

parent 0c2eaaf8
No related branches found
No related tags found
No related merge requests found
...@@ -17,6 +17,8 @@ describe('util/timestamp', () => { ...@@ -17,6 +17,8 @@ describe('util/timestamp', () => {
${'2021-01-01'} | ${'2021-01-01T00:00:00.000Z'} ${'2021-01-01'} | ${'2021-01-01T00:00:00.000Z'}
${'20210101000000'} | ${'2021-01-01T00:00:00.000Z'} ${'20210101000000'} | ${'2021-01-01T00:00:00.000Z'}
${'20211231235959'} | ${'2021-12-31T23:59:59.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'} ${'Jan 1, 2021'} | ${'2021-01-01T00:00:00.000Z'}
${'2021/01/01'} | ${'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'} ${'2021-01-02T00:00:00+05:30'} | ${'2021-01-01T18:30:00.000Z'}
......
...@@ -64,6 +64,15 @@ export function asTimestamp(input: unknown): Timestamp | null { ...@@ -64,6 +64,15 @@ export function asTimestamp(input: unknown): Timestamp | null {
return numberLikeDate.toISO() as Timestamp; 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( const fallbackDate = DateTime.fromMillis(
Date.parse(input) - timezoneOffset, Date.parse(input) - timezoneOffset,
{ zone: 'UTC' }, { zone: 'UTC' },
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment