@ -3,6 +3,8 @@ import {
dateTimeAsIsoNoDateIfToday ,
dateTimeAsUS ,
dateTimeAsUSNoDateIfToday ,
getDateTimeAsLocalFormat ,
getDateTimeAsLocalFormatNoDateIfToday ,
dateTimeFromNow ,
Interval ,
toClock ,
@ -74,6 +76,36 @@ describe('date time formats', () => {
expect ( actual . text ) . toBe ( expected ) ;
} ) ;
it ( 'should format as local date' , ( ) = > {
const dateTimeObject = browserTime . toDate ( ) ;
const formattedDateText = getDateTimeAsLocalFormat ( ) ( epoch , 0 , 0 ) . text ;
expect ( formattedDateText ) . toContain ( dateTimeObject . getFullYear ( ) ) ;
expect ( formattedDateText ) . toContain ( dateTimeObject . getSeconds ( ) ) ;
} ) ;
it ( 'should format as local date and skip date when today' , ( ) = > {
const now = dateTime ( ) ;
const dateTimeObject = now . toDate ( ) ;
const formattedDateText = getDateTimeAsLocalFormatNoDateIfToday ( ) ( now . valueOf ( ) , 0 , 0 ) . text ;
expect ( formattedDateText ) . not . toContain ( dateTimeObject . getFullYear ( ) ) ;
expect ( formattedDateText ) . toContain ( dateTimeObject . getSeconds ( ) ) ;
} ) ;
it ( 'should format as local date (in UTC)' , ( ) = > {
const dateTimeObject = utcTime . toDate ( ) ;
const formattedDateText = getDateTimeAsLocalFormat ( ) ( epoch , 0 , 0 , 'utc' ) . text ;
expect ( formattedDateText ) . toContain ( dateTimeObject . getFullYear ( ) ) ;
expect ( formattedDateText ) . toContain ( dateTimeObject . getSeconds ( ) ) ;
} ) ;
it ( 'should format as local date (in UTC) and skip date when today' , ( ) = > {
const now = toUtc ( ) ;
const dateTimeObject = now . toDate ( ) ;
const formattedDateText = getDateTimeAsLocalFormatNoDateIfToday ( ) ( now . valueOf ( ) , 0 , 0 , 'utc' ) . text ;
expect ( formattedDateText ) . not . toContain ( dateTimeObject . getFullYear ( ) ) ;
expect ( formattedDateText ) . toContain ( dateTimeObject . getSeconds ( ) ) ;
} ) ;
it ( 'should format as from now with days' , ( ) = > {
const daysAgo = dateTime ( ) . add ( - 7 , 'd' ) ;
const expected = '7 days ago' ;