diff --git a/projects/common/src/utilities/formatters/date/date-formatter.test.ts b/projects/common/src/utilities/formatters/date/date-formatter.test.ts index d4e95e3ef..7ab1eccad 100644 --- a/projects/common/src/utilities/formatters/date/date-formatter.test.ts +++ b/projects/common/src/utilities/formatters/date/date-formatter.test.ts @@ -1,4 +1,4 @@ -import { DateFormatter } from './date-formatter'; +import { DateFormatMode, DateFormatter } from './date-formatter'; describe('Date formatter', () => { const dateString = '2021-08-19T23:35:45.861Z'; @@ -6,4 +6,12 @@ describe('Date formatter', () => { 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'); + }); }); diff --git a/projects/common/src/utilities/formatters/date/date-formatter.ts b/projects/common/src/utilities/formatters/date/date-formatter.ts index 1af7144f7..7ec594930 100644 --- a/projects/common/src/utilities/formatters/date/date-formatter.ts +++ b/projects/common/src/utilities/formatters/date/date-formatter.ts @@ -7,6 +7,7 @@ export const enum DateFormatMode { TimeWithSeconds, DateOnly, MonthAndDayOnly, + MonthAndYearOnly, DateAndTime, DateAndTimeWithSeconds } @@ -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: