Files
twenty/packages/twenty-front/src/utils/format/formatDate.ts
T
ccf4d1eeec Date formatting per workspace member settings (#6408)
Implement date formatting per workspace member settings

We'll need another round to maybe initialize all workspaces on the
default settings.

For now the default behavior is to take system settings if nothing is
found in DB.

---------

Co-authored-by: Weiko <corentin@twenty.com>
2024-07-30 14:52:10 +02:00

39 lines
870 B
TypeScript

import { parseDate } from '~/utils/date-utils';
export const formatToHumanReadableMonth = (
date: Date | string,
timeZone: string,
) => {
const parsedJSDate = parseDate(date).toJSDate();
return new Intl.DateTimeFormat(undefined, {
month: 'short',
timeZone: timeZone,
}).format(parsedJSDate);
};
export const formatToHumanReadableDay = (
date: Date | string,
timeZone: string,
) => {
const parsedJSDate = parseDate(date).toJSDate();
return new Intl.DateTimeFormat(undefined, {
day: 'numeric',
timeZone: timeZone,
}).format(parsedJSDate);
};
export const formatToHumanReadableTime = (
date: Date | string,
timeZone: string,
) => {
const parsedJSDate = parseDate(date).toJSDate();
return new Intl.DateTimeFormat(undefined, {
hour: 'numeric',
minute: 'numeric',
timeZone: timeZone,
}).format(parsedJSDate);
};