Skip to content

Commit

Permalink
front: change arrivalDate type to Date in isArrivalDateInSearchTimeWi…
Browse files Browse the repository at this point in the history
…ndow

Signed-off-by: SarahBellaha <[email protected]>
  • Loading branch information
SarahBellaha committed Nov 19, 2024
1 parent 48cb9e5 commit 9559d98
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const StdcmOpSchedule = ({
useMemo(() => {
const isArrivalDateValid =
opTimingData?.arrivalDate &&
isArrivalDateInSearchTimeWindow(opTimingData.arrivalDate, searchDatetimeWindow);
isArrivalDateInSearchTimeWindow(new Date(opTimingData.arrivalDate), searchDatetimeWindow);
return {
arrivalDate:
opTimingData && isArrivalDateValid
Expand Down
12 changes: 9 additions & 3 deletions front/src/utils/__tests__/date.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ describe('extractDateAndTimefromISO', () => {

describe('isArrivalDateInSearchTimeWindow', () => {
it('should return true if searchDatetimeWindow is undefined', () => {
const result = isArrivalDateInSearchTimeWindow('2024-08-01T10:00:00Z', undefined);
const result = isArrivalDateInSearchTimeWindow(new Date('2024-08-01T10:00:00Z'), undefined);
expect(result).toBe(true);
});

Expand All @@ -125,7 +125,10 @@ describe('isArrivalDateInSearchTimeWindow', () => {
begin: new Date('2024-08-01T00:00:00Z'),
end: new Date('2024-08-02T00:00:00Z'),
};
const result = isArrivalDateInSearchTimeWindow('2024-08-01T10:00:00Z', searchDatetimeWindow);
const result = isArrivalDateInSearchTimeWindow(
new Date('2024-08-01T10:00:00Z'),
searchDatetimeWindow
);
expect(result).toBe(true);
});

Expand All @@ -134,7 +137,10 @@ describe('isArrivalDateInSearchTimeWindow', () => {
begin: new Date('2024-08-01T00:00:00Z'),
end: new Date('2024-08-02T00:00:00Z'),
};
const result = isArrivalDateInSearchTimeWindow('2024-07-30T23:59:59Z', searchDatetimeWindow);
const result = isArrivalDateInSearchTimeWindow(
new Date('2024-07-30T23:59:59Z'),
searchDatetimeWindow
);
expect(result).toBe(false);
});
});
Expand Down
5 changes: 2 additions & 3 deletions front/src/utils/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,18 +218,17 @@ export function extractDateAndTimefromISO(arrivalTime: string, dateFormat: strin
/**
* Checks if the given arrival date falls within the specified search time window.
*
* @param {string | Date} arrivalTime - The arrival time, which can be a Date object or an ISO string that will be parsed into a Date object.
* @param {Date} arrivalDate - The arrival time, which is a Date object.
* @param {{ begin: Date; end: Date } | undefined} searchDatetimeWindow - An object containing the start and end dates of the search window. If undefined, the function will return true.
* @returns {boolean} - Returns true if the arrival date is within the search time window, or if the search time window is undefined. Returns false otherwise.
*/
export function isArrivalDateInSearchTimeWindow(
arrivalTime: string | Date,
arrivalDate: Date,
searchDatetimeWindow?: { begin: Date; end: Date }
) {
if (!searchDatetimeWindow) {
return true;
}
const arrivalDate = typeof arrivalTime === 'string' ? new Date(arrivalTime) : arrivalTime;
return arrivalDate >= searchDatetimeWindow.begin && arrivalDate <= searchDatetimeWindow.end;
}

Expand Down

0 comments on commit 9559d98

Please sign in to comment.