Skip to content

Commit

Permalink
front: drop formatToIsoDate()
Browse files Browse the repository at this point in the history
This is now unused.

This function was a bit weird, because it had two unrelated
purposes: format a human-readable string with a fixed frenchy
format, or format a machine-readable string for API purposes.
The function also accepted strings and numbers as input
(implicitly converting these to dates), making it so callers are
less type-safe.

Signed-off-by: Simon Ser <[email protected]>
  • Loading branch information
emersion committed Mar 6, 2025
1 parent cdf1aa8 commit 8590f5e
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 19 deletions.
9 changes: 0 additions & 9 deletions front/src/utils/__tests__/date.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { describe, it, expect } from 'vitest';
import {
parseLocalDateTime,
isoDateToMs,
formatToIsoDate,
serializeDateTimeWithoutYear,
extractDateAndTime,
isArrivalDateInSearchTimeWindow,
Expand Down Expand Up @@ -43,14 +42,6 @@ describe('isoDateToMs', () => {
});
});

describe('formatToIsoDate', () => {
it('should return the date in ISO 8601', () => {
const msDate = 1714156215000;
const isoDate = formatToIsoDate(msDate);
expect(isoDate).toEqual('2024-04-26T18:30:15Z'); // Ends by Z because CI seems to be in UTC timezone
});
});

describe('serializeDateTimeWithoutYear', () => {
it('should return the date without the year for a valid Date object', () => {
const inputDate = new Date('2024-07-18T03:16:30Z');
Expand Down
10 changes: 0 additions & 10 deletions front/src/utils/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,6 @@ export const parseLocalDateTime = (inputDateTime: string) => {
export const formatLocalDateTime = (date: Date) =>
dayjs(date).local().format('YYYY-MM-DDTHH:mm:ss');

/**
* Transform a milliseconds date to an ISO 8601 date with the user timezone
* @param msDate milliseconds date (elapsed from January 1st 1970)
* @return an ISO 8601 date (e.g. 2024-04-25T08:30:00+02:00)
*/
export const formatToIsoDate = (date: number | string | Date, formatDate: boolean = false) => {
const format = formatDate ? 'D/MM/YYYY HH:mm:ss' : '';
return dayjs(date).tz(userTimeZone).format(format);
};

/**
* Transform a locale date to an ISO 8601 date
* @param date Date we want to transform to ISO 8601
Expand Down

0 comments on commit 8590f5e

Please sign in to comment.