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' ;
22
33describe ( '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} ) ;
Original file line number Diff line number Diff 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 :
You can’t perform that action at this time.
0 commit comments