diff --git a/src/utils/timezoneUtils/dateTimeMiddleware.test.ts b/src/utils/timezoneUtils/dateTimeMiddleware.spec.ts similarity index 92% rename from src/utils/timezoneUtils/dateTimeMiddleware.test.ts rename to src/utils/timezoneUtils/dateTimeMiddleware.spec.ts index b14702b546..ead19444c3 100644 --- a/src/utils/timezoneUtils/dateTimeMiddleware.test.ts +++ b/src/utils/timezoneUtils/dateTimeMiddleware.spec.ts @@ -3,6 +3,7 @@ import type { Operation, FetchResult } from '@apollo/client/core'; import { Observable } from '@apollo/client/core'; import { gql } from '@apollo/client'; import type { DocumentNode } from 'graphql'; +import { describe, it, expect, vi } from 'vitest'; const DUMMY_QUERY: DocumentNode = gql` query GetDummyData { @@ -19,12 +20,12 @@ describe('Date Time Middleware Tests', () => { query: DUMMY_QUERY, operationName: 'GetDummyData', variables: { startDate: '2023-09-01', startTime: '12:00:00' }, - getContext: jest.fn(() => ({})), - setContext: jest.fn(), + getContext: vi.fn(() => ({})), + setContext: vi.fn(), extensions: {}, }; - const forward = jest.fn( + const forward = vi.fn( (op) => new Observable((observer) => { expect(op.variables['startDate']).toBe('2023-09-01'); @@ -55,12 +56,12 @@ describe('Date Time Middleware Tests', () => { query: DUMMY_QUERY, operationName: 'GetDummyData', variables: {}, - getContext: jest.fn(() => ({})), - setContext: jest.fn(), + getContext: vi.fn(() => ({})), + setContext: vi.fn(), extensions: {}, }; - const forward = jest.fn( + const forward = vi.fn( () => new Observable((observer) => { observer.next(testResponse); @@ -98,12 +99,12 @@ describe('Date Time Middleware Tests', () => { query: DUMMY_QUERY, operationName: 'GetDummyData', variables: { startDate: 'not-a-date', startTime: '25:99:99' }, - getContext: jest.fn(() => ({})), - setContext: jest.fn(), + getContext: vi.fn(() => ({})), + setContext: vi.fn(), extensions: {}, }; - const forward = jest.fn( + const forward = vi.fn( (op) => new Observable((observer) => { expect(op.variables['startDate']).toBe('not-a-date'); @@ -130,12 +131,12 @@ describe('Date Time Middleware Tests', () => { query: DUMMY_QUERY, operationName: 'GetDummyData', variables: {}, - getContext: jest.fn(() => ({})), - setContext: jest.fn(), + getContext: vi.fn(() => ({})), + setContext: vi.fn(), extensions: {}, }; - const forward = jest.fn( + const forward = vi.fn( () => new Observable((observer) => { observer.next(testResponse); @@ -188,12 +189,12 @@ describe('Date Time Middleware Tests', () => { }, }, }, - getContext: jest.fn(() => ({})), - setContext: jest.fn(), + getContext: vi.fn(() => ({})), + setContext: vi.fn(), extensions: {}, }; - const forward = jest.fn( + const forward = vi.fn( (op) => new Observable((observer) => { expect(op.variables.event.startDate).toBe('2023-10-01'); diff --git a/src/utils/timezoneUtils/dateTimeMiddleware.ts b/src/utils/timezoneUtils/dateTimeMiddleware.ts index 70fc20a026..f3be59bacb 100644 --- a/src/utils/timezoneUtils/dateTimeMiddleware.ts +++ b/src/utils/timezoneUtils/dateTimeMiddleware.ts @@ -14,6 +14,13 @@ const combineDateTime = (date: string, time: string): string => { const splitDateTime = (dateTimeStr: string): { date: string; time: string } => { const dateTime = dayjs.utc(dateTimeStr); + if (!dateTime.isValid()) { + const [date, time] = dateTimeStr.split('T'); + return { + date: date, + time: time, + }; + } return { date: dateTime.format('YYYY-MM-DD'), time: dateTime.format('HH:mm:ss.SSS[Z]'), @@ -21,18 +28,17 @@ const splitDateTime = (dateTimeStr: string): { date: string; time: string } => { }; const convertUTCToLocal = (dateStr: string): string => { - if (dayjs(dateStr).isValid()) { - return dayjs.utc(dateStr).local().format('YYYY-MM-DDTHH:mm:ss.SSS'); + if (!dayjs(dateStr).isValid()) { + return dateStr; } - return dateStr; + return dayjs.utc(dateStr).local().format('YYYY-MM-DDTHH:mm:ss.SSS'); }; const convertLocalToUTC = (dateStr: string): string => { - if (dayjs(dateStr).isValid()) { - const result = dayjs(dateStr).utc().format('YYYY-MM-DDTHH:mm:ss.SSS[Z]'); - return result; + if (!dayjs(dateStr).isValid()) { + return dateStr; // Leave the invalid value unchanged } - return dateStr; + return dayjs(dateStr).utc().format('YYYY-MM-DDTHH:mm:ss.SSS[Z]'); }; const traverseAndConvertDates = (