Skip to content

Commit

Permalink
feat(timestamp): Parse number-like dates plus offset (renovatebot#33647)
Browse files Browse the repository at this point in the history
  • Loading branch information
zharinov authored Jan 16, 2025
1 parent 0c2eaaf commit 1f4790c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/util/timestamp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'}
Expand Down
9 changes: 9 additions & 0 deletions lib/util/timestamp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand Down

0 comments on commit 1f4790c

Please sign in to comment.