Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import { DateFormatter } from './date-formatter';
import { DateFormatMode, DateFormatter } from './date-formatter';

describe('Date formatter', () => {
const dateString = '2021-08-19T23:35:45.861Z';

test('can format a date string', () => {
expect(new DateFormatter().format(dateString)).toEqual('19 Aug 2021 11:35 PM');
});

test('can format a date string with month and year only', () => {
expect(
new DateFormatter({
mode: DateFormatMode.MonthAndYearOnly
}).format(dateString)
).toEqual('Aug 21');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const enum DateFormatMode {
TimeWithSeconds,
DateOnly,
MonthAndDayOnly,
MonthAndYearOnly,
DateAndTime,
DateAndTimeWithSeconds
}
Expand Down Expand Up @@ -51,6 +52,8 @@ export class DateFormatter {
return 'h:mm a';
case DateFormatMode.MonthAndDayOnly:
return 'MMM d';
case DateFormatMode.MonthAndYearOnly:
return 'MMM yy';
case DateFormatMode.DateOnly:
return 'd MMM y';
case DateFormatMode.DateAndTime:
Expand Down