Feat: add support for day-first and year-first date formats (DD/MM/YYYY, YYYY/MM/DD) (#12333)

Closes #12152 



https://github.com/user-attachments/assets/53640777-578f-4de8-a1f8-52d409a7582d

---------

Co-authored-by: etiennejouan <jouan.etienne@gmail.com>
This commit is contained in:
Abdul Rahman
2025-06-03 17:42:01 +05:30
committed by GitHub
parent 70cc3e75fe
commit 278a7baf5e
14 changed files with 125 additions and 114 deletions

View File

@ -4,9 +4,11 @@ import { differenceInCalendarDays, formatDistanceToNow } from 'date-fns';
import { DateTime } from 'luxon';
import moize from 'moize';
import { logError } from './logError';
import { DateFormat } from '@/localization/constants/DateFormat';
import { isDefined } from 'twenty-shared/utils';
import { logError } from './logError';
export const DEFAULT_DATE_LOCALE = 'en-EN';
export const parseDate = (dateToParse: Date | string | number) => {
@ -212,3 +214,20 @@ export const formatToHumanReadableDateTime = (date: Date | string) => {
minute: 'numeric',
}).format(parsedJSDate);
};
export const getDateFormatString = (
dateFormat: DateFormat,
isDateTimeInput: boolean,
): string => {
const timePart = isDateTimeInput ? ' HH:mm' : '';
switch (dateFormat) {
case DateFormat.DAY_FIRST:
return `dd/MM/yyyy${timePart}`;
case DateFormat.YEAR_FIRST:
return `yyyy-MM-dd${timePart}`;
case DateFormat.MONTH_FIRST:
default:
return `MM/dd/yyyy${timePart}`;
}
};