From 6cfc9c9092ba04a4a8ec3452bbece661d9348257 Mon Sep 17 00:00:00 2001 From: Patricio Albizu Date: Mon, 21 Feb 2022 18:36:19 -0300 Subject: [PATCH 1/2] feat: Adding date formatter --- .../common/src/utilities/formatters/date/date-formatter.ts | 3 +++ 1 file changed, 3 insertions(+) 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: From 5c394b9254673af18f7fd397cfff2bdfd7062576 Mon Sep 17 00:00:00 2001 From: Patricio Albizu Date: Mon, 21 Feb 2022 19:43:08 -0300 Subject: [PATCH 2/2] feat: adding test --- .../utilities/formatters/date/date-formatter.test.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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'); + }); });