import { getDateTimeFromISO } from './datetime' import { fromJSDateToJSDateToString } from './index' describe('fromJSDateToJSDateToString', () => { it.each([ [new Date('2021-01-01T00:00:00.000Z'), '2021-01-01T00:00:00+00:00'], [new Date('2021-01-01T00:00:00.123Z'), '2021-01-01T00:00:00+00:00'], [new Date('2024-01-01T12:00:00.000-04:00'), '2024-01-01T16:00:00+00:00'], [new Date('2024-01-01T12:00:00.000-03:00'), '2024-01-01T15:00:00+00:00'], [new Date('2024-01-01T12:00:00.000-02:00'), '2024-01-01T14:00:00+00:00'], [new Date('2024-01-01T12:00:00.000-01:00'), '2024-01-01T13:00:00+00:00'], [new Date('2024-01-01T12:00:00.000+00:00'), '2024-01-01T12:00:00+00:00'], [new Date('2024-01-01T12:00:00.000+01:00'), '2024-01-01T11:00:00+00:00'], [new Date('2024-01-01T12:00:00.000+02:00'), '2024-01-01T10:00:00+00:00'], [new Date('2024-01-01T12:00:00.000+03:00'), '2024-01-01T09:00:00+00:00'], [new Date('2024-01-01T12:00:00.000+04:00'), '2024-01-01T08:00:00+00:00'], ])( 'should return a string with the date and time from a Date object', (input, expected) => expect(fromJSDateToJSDateToString(input)).toBe( getDateTimeFromISO(expected) .set({ millisecond: 0 }) .toISO({ suppressMilliseconds: true }) ) ) it('should throw an error if the input is not a Date object', () => { expect(() => // @ts-expect-error testing invalid input fromJSDateToJSDateToString('2021-01-01T00:00:00.000Z') ).toThrow('Invalid date string: 2021-01-01T00:00:00.000Z') }) })