Activity timeline refactoring followup (#5835)
Following https://github.com/twentyhq/twenty/pull/5697, addressing review
This commit is contained in:
@ -0,0 +1,29 @@
|
||||
import {
|
||||
formatToHumanReadableDay,
|
||||
formatToHumanReadableMonth,
|
||||
formatToHumanReadableTime,
|
||||
} from '../formatDate';
|
||||
|
||||
describe('formatToHumanReadableMonth', () => {
|
||||
it('should format the date to a human-readable month', () => {
|
||||
const date = new Date('2022-01-01');
|
||||
const result = formatToHumanReadableMonth(date);
|
||||
expect(result).toBe('Jan');
|
||||
});
|
||||
});
|
||||
|
||||
describe('formatToHumanReadableDay', () => {
|
||||
it('should format the date to a human-readable day', () => {
|
||||
const date = new Date('2022-01-01');
|
||||
const result = formatToHumanReadableDay(date);
|
||||
expect(result).toBe('1');
|
||||
});
|
||||
});
|
||||
|
||||
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);
|
||||
expect(result).toBe('12:30 PM');
|
||||
});
|
||||
});
|
||||
26
packages/twenty-front/src/utils/format/formatDate.ts
Normal file
26
packages/twenty-front/src/utils/format/formatDate.ts
Normal file
@ -0,0 +1,26 @@
|
||||
import { parseDate } from '~/utils/date-utils';
|
||||
|
||||
export const formatToHumanReadableMonth = (date: Date | string) => {
|
||||
const parsedJSDate = parseDate(date).toJSDate();
|
||||
|
||||
return new Intl.DateTimeFormat(undefined, {
|
||||
month: 'short',
|
||||
}).format(parsedJSDate);
|
||||
};
|
||||
|
||||
export const formatToHumanReadableDay = (date: Date | string) => {
|
||||
const parsedJSDate = parseDate(date).toJSDate();
|
||||
|
||||
return new Intl.DateTimeFormat(undefined, {
|
||||
day: 'numeric',
|
||||
}).format(parsedJSDate);
|
||||
};
|
||||
|
||||
export const formatToHumanReadableTime = (date: Date | string) => {
|
||||
const parsedJSDate = parseDate(date).toJSDate();
|
||||
|
||||
return new Intl.DateTimeFormat(undefined, {
|
||||
hour: 'numeric',
|
||||
minute: 'numeric',
|
||||
}).format(parsedJSDate);
|
||||
};
|
||||
Reference in New Issue
Block a user