diff --git a/lib/DateTimeUtils.test.ts b/lib/DateTimeUtils.test.ts index b5f6149..cb84d8b 100644 --- a/lib/DateTimeUtils.test.ts +++ b/lib/DateTimeUtils.test.ts @@ -34,5 +34,24 @@ describe('DateTimeUtils.timestampToString', () => { it('still formats a valid time-of-day', () => { expect(DateTimeUtils.timestampToString(4980)).toBe('01:23:00'); + expect(DateTimeUtils.timestampToString(86399)).toBe('23:59:59'); + }); + + it('formats a full timestamp with its date', () => { + expect(DateTimeUtils.timestampToString(1704164645)).toBe( + '2024-01-02T03:04:05Z', + ); + }); +}); + +describe('DateTimeUtils.convertDayTimeToTod', () => { + it.each([ + ['01000000', 'YYYY-MM-01T00:00:00'], + ['15123456', 'YYYY-MM-15T12:34:56'], + ['31235959', 'YYYY-MM-31T23:59:59'], + ])('keeps the day of month when formatting %s', (time, expected) => { + expect( + DateTimeUtils.timestampToString(DateTimeUtils.convertDayTimeToTod(time)), + ).toBe(expected); }); }); diff --git a/lib/DateTimeUtils.ts b/lib/DateTimeUtils.ts index 9912829..075ee55 100644 --- a/lib/DateTimeUtils.ts +++ b/lib/DateTimeUtils.ts @@ -86,9 +86,10 @@ export class DateTimeUtils { // only time, no date return date.toISOString().slice(11, 19); } - if (time < 2678400) { - // unknown month and date - return `YYYY-MM-${date.toISOString().slice(8, 19)}`; + if (time < 32 * 86400) { + // unknown month, day of month is time / 86400 + const day = String(Math.floor(time / 86400)).padStart(2, '0'); + return `YYYY-MM-${day}T${date.toISOString().slice(11, 19)}`; } //strip off millis return date.toISOString().slice(0, -5) + 'Z';