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>
This commit is contained in:
@ -151,7 +151,7 @@ const getMonthLabels = () => {
|
||||
.map((date) => formatter.format(date));
|
||||
};
|
||||
|
||||
const getMonthLabelsMemoized = moize(getMonthLabels);
|
||||
export const getMonthLabelsMemoized = moize(getMonthLabels);
|
||||
|
||||
export const formatISOStringToHumanReadableDateTime = (date: string) => {
|
||||
const monthLabels = getMonthLabelsMemoized();
|
||||
|
||||
@ -7,7 +7,7 @@ import {
|
||||
describe('formatToHumanReadableMonth', () => {
|
||||
it('should format the date to a human-readable month', () => {
|
||||
const date = new Date('2022-01-01');
|
||||
const result = formatToHumanReadableMonth(date);
|
||||
const result = formatToHumanReadableMonth(date, 'UTC');
|
||||
expect(result).toBe('Jan');
|
||||
});
|
||||
});
|
||||
@ -15,7 +15,7 @@ describe('formatToHumanReadableMonth', () => {
|
||||
describe('formatToHumanReadableDay', () => {
|
||||
it('should format the date to a human-readable day', () => {
|
||||
const date = new Date('2022-01-01');
|
||||
const result = formatToHumanReadableDay(date);
|
||||
const result = formatToHumanReadableDay(date, 'UTC');
|
||||
expect(result).toBe('1');
|
||||
});
|
||||
});
|
||||
@ -23,7 +23,7 @@ describe('formatToHumanReadableDay', () => {
|
||||
describe('formatToHumanReadableTime', () => {
|
||||
it('should format the date to a human-readable time', () => {
|
||||
const date = new Date('2022-01-01T12:30:00');
|
||||
const result = formatToHumanReadableTime(date);
|
||||
const result = formatToHumanReadableTime(date, 'UTC');
|
||||
// it seems when running locally on MacOS the space is not the same
|
||||
expect(['12:30 PM', '12:30 PM']).toContain(result);
|
||||
});
|
||||
|
||||
@ -1,26 +1,38 @@
|
||||
import { parseDate } from '~/utils/date-utils';
|
||||
|
||||
export const formatToHumanReadableMonth = (date: Date | string) => {
|
||||
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) => {
|
||||
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) => {
|
||||
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);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user