Skip to content

Commit d2cea35

Browse files
palbizuPatricio Albizu
andauthored
feat: Adding date formatter (#1447)
* feat: Adding date formatter * feat: adding test Co-authored-by: Patricio Albizu <[email protected]>
1 parent c35dedf commit d2cea35

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1-
import { DateFormatter } from './date-formatter';
1+
import { DateFormatMode, DateFormatter } from './date-formatter';
22

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

66
test('can format a date string', () => {
77
expect(new DateFormatter().format(dateString)).toEqual('19 Aug 2021 11:35 PM');
88
});
9+
10+
test('can format a date string with month and year only', () => {
11+
expect(
12+
new DateFormatter({
13+
mode: DateFormatMode.MonthAndYearOnly
14+
}).format(dateString)
15+
).toEqual('Aug 21');
16+
});
917
});

projects/common/src/utilities/formatters/date/date-formatter.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export const enum DateFormatMode {
77
TimeWithSeconds,
88
DateOnly,
99
MonthAndDayOnly,
10+
MonthAndYearOnly,
1011
DateAndTime,
1112
DateAndTimeWithSeconds
1213
}
@@ -51,6 +52,8 @@ export class DateFormatter {
5152
return 'h:mm a';
5253
case DateFormatMode.MonthAndDayOnly:
5354
return 'MMM d';
55+
case DateFormatMode.MonthAndYearOnly:
56+
return 'MMM yy';
5457
case DateFormatMode.DateOnly:
5558
return 'd MMM y';
5659
case DateFormatMode.DateAndTime:

0 commit comments

Comments
 (0)