File tree Expand file tree Collapse file tree 2 files changed +12
-1
lines changed
projects/common/src/utilities/formatters/date Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Original file line number Diff line number Diff line change 1
- import { DateFormatter } from './date-formatter' ;
1
+ import { DateFormatMode , DateFormatter } from './date-formatter' ;
2
2
3
3
describe ( 'Date formatter' , ( ) => {
4
4
const dateString = '2021-08-19T23:35:45.861Z' ;
5
5
6
6
test ( 'can format a date string' , ( ) => {
7
7
expect ( new DateFormatter ( ) . format ( dateString ) ) . toEqual ( '19 Aug 2021 11:35 PM' ) ;
8
8
} ) ;
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
+ } ) ;
9
17
} ) ;
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ export const enum DateFormatMode {
7
7
TimeWithSeconds ,
8
8
DateOnly ,
9
9
MonthAndDayOnly ,
10
+ MonthAndYearOnly ,
10
11
DateAndTime ,
11
12
DateAndTimeWithSeconds
12
13
}
@@ -51,6 +52,8 @@ export class DateFormatter {
51
52
return 'h:mm a' ;
52
53
case DateFormatMode . MonthAndDayOnly :
53
54
return 'MMM d' ;
55
+ case DateFormatMode . MonthAndYearOnly :
56
+ return 'MMM yy' ;
54
57
case DateFormatMode . DateOnly :
55
58
return 'd MMM y' ;
56
59
case DateFormatMode . DateAndTime :
You can’t perform that action at this time.
0 commit comments