diff --git a/packages/common/src/utils/__tests__/dates.test.ts b/packages/common/src/utils/__tests__/dates.test.ts index b09eb9474..d3a204cc7 100644 --- a/packages/common/src/utils/__tests__/dates.test.ts +++ b/packages/common/src/utils/__tests__/dates.test.ts @@ -63,14 +63,10 @@ describe('parseISOtoJSDate', () => { describe('areSameDayInUTCZero', () => { test('the same date', () => { - expect( - areSameDayInUTCZero('2023-10-31T01:30:00.000+02:00', '2023-10-29T23:30:00.000-02:00'), - ).toBeTruthy(); + expect(areSameDayInUTCZero('2023-10-31T01:30:00.000+02:00', '2023-10-30')).toBeTruthy(); }); test('the different dates', () => { - expect( - areSameDayInUTCZero('2023-10-31T10:00:00.000+02:00', '2023-10-29T14:00:00.000-02:00'), - ).toBeFalsy(); + expect(areSameDayInUTCZero('2023-10-31T01:30:00.000+02:00', '2023-10-31')).toBeFalsy(); }); test('one date invalid', () => { expect(areSameDayInUTCZero('2023-10-31T10:00:00.000+02:00', '2023-foo')).toBeFalsy(); diff --git a/packages/common/src/utils/dates.ts b/packages/common/src/utils/dates.ts index 6fe5163da..feb39e208 100644 --- a/packages/common/src/utils/dates.ts +++ b/packages/common/src/utils/dates.ts @@ -47,9 +47,12 @@ export const parseISOtoJSDate = (isoDateString: string) => { /** * - * @param a ISO date(time) formatted string - * @param b ISO date(time) formatted string + * @param dateTime ISO date time formatted string (with time zone) + * @param calendarDate local date as ISO date formatted string (no time, no time zone) * @returns true if both dates are on the same day in UTC+00:00 */ -export const areSameDayInUTCZero = (a: string, b: string): boolean => - DateTime.fromISO(a).toUTC().hasSame(DateTime.fromISO(b).toUTC(), 'day'); +export const areSameDayInUTCZero = (dateTime: string, calendarDate: string): boolean => { + // calendar date has no zone - during conversion to UTC the local zone is used + // which results in shifting to previous day for zones with positive offsets + return DateTime.fromISO(dateTime).toUTC().hasSame(DateTime.fromISO(calendarDate), 'day'); +};