Skip to content

Commit e5bbd27

Browse files
committed
add tests for reformatUtcTimestamp()
1 parent deb0155 commit e5bbd27

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

packages/cubejs-backend-shared/test/time.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
utcToLocalTimeZone,
99
addSecondsToLocalTimestamp,
1010
reformatInIsoLocal,
11+
reformatUtcTimestamp,
1112
} from '../src';
1213

1314
describe('timeSeries', () => {
@@ -529,3 +530,35 @@ describe('reformatInIsoLocal', () => {
529530
expect(reformatInIsoLocal(timestamp)).toBe(expected);
530531
});
531532
});
533+
534+
describe('reformatUtcTimestamp', () => {
535+
it('should format timestamp to YYYY-MM-DDTHH:mm:ss.SSS', () => {
536+
expect(reformatUtcTimestamp('YYYY-MM-DDTHH:mm:ss.SSS', '2025-02-28T12:34:56Z'))
537+
.toBe('2025-02-28T12:34:56.000');
538+
});
539+
540+
it('should format timestamp to YYYY-MM-DDTHH:mm:ss', () => {
541+
expect(reformatUtcTimestamp('YYYY-MM-DDTHH:mm:ss', '2025-02-28T12:34:56Z'))
542+
.toBe('2025-02-28T12:34:56');
543+
});
544+
545+
it('should format timestamp to YYYY-MM-DD HH:mm:ss.SSS', () => {
546+
expect(reformatUtcTimestamp('YYYY-MM-DD HH:mm:ss.SSS', '2025-02-28T12:34:56Z'))
547+
.toBe('2025-02-28 12:34:56.000');
548+
});
549+
550+
it('should format timestamp to YYYY-MM-DD HH:mm:ss', () => {
551+
expect(reformatUtcTimestamp('YYYY-MM-DD HH:mm:ss', '2025-02-28T12:34:56Z'))
552+
.toBe('2025-02-28 12:34:56');
553+
});
554+
555+
it('should handle timestamps with milliseconds', () => {
556+
expect(reformatUtcTimestamp('YYYY-MM-DDTHH:mm:ss.SSS', '2025-02-28T12:34:56.789Z'))
557+
.toBe('2025-02-28T12:34:56.789');
558+
});
559+
560+
it('should handle timestamps without timezone info', () => {
561+
expect(reformatUtcTimestamp('YYYY-MM-DDTHH:mm:ss.SSS', '2025-02-28 12:34:56'))
562+
.toBe('2025-02-28T12:34:56.000');
563+
});
564+
});

0 commit comments

Comments
 (0)