@ -1,4 +1,4 @@
import { dateTimeFormat } from './formatter' ;
import { dateTimeFormat , dateTimeFormatTimeAgo , dateTimeFormatWithAbbrevation , timeZoneAbbrevation } from './formatter' ;
describe ( 'dateTimeFormat' , ( ) = > {
describe ( 'dateTimeFormat' , ( ) = > {
describe ( 'when no time zone have been set' , ( ) = > {
describe ( 'when no time zone have been set' , ( ) = > {
@ -66,11 +66,76 @@ describe('dateTimeFormat', () => {
} ) ;
} ) ;
} ) ;
} ) ;
describe ( 'when Africa/Djibouti time zone have been set' , ( ) = > {
describe ( 'when time zone have been set' , ( ) = > {
const options = { timeZone : 'Africa/Djibouti' } ;
it . each ( [
[ 'Africa/Djibouti' , '2020-04-17 15:36:15' ] ,
[ 'Europe/London' , '2020-04-17 13:36:15' ] ,
[ 'Europe/Berlin' , '2020-04-17 14:36:15' ] ,
[ 'Europe/Moscow' , '2020-04-17 15:36:15' ] ,
[ 'Europe/Madrid' , '2020-04-17 14:36:15' ] ,
[ 'America/New_York' , '2020-04-17 08:36:15' ] ,
[ 'America/Chicago' , '2020-04-17 07:36:15' ] ,
[ 'America/Denver' , '2020-04-17 06:36:15' ] ,
] ) ( 'should format with default formatting in correct time zone' , ( timeZone , expected ) = > {
expect ( dateTimeFormat ( 1587126975779 , { timeZone } ) ) . toBe ( expected ) ;
} ) ;
} ) ;
it ( 'should format with default formatting in correct time zone' , ( ) = > {
describe ( 'DateTimeFormatISO' , ( ) = > {
expect ( dateTimeFormat ( 1587126975779 , options ) ) . toBe ( '2020-04-17 15:36:15' ) ;
it ( 'should format according to ISO standard' , ( ) = > {
const options = { timeZone : 'Europe/Stockholm' , format : 'YYYY-MM-DDTHH:mm:ss.SSSZ' } ;
expect ( dateTimeFormat ( 1587126975779 , options ) ) . toBe ( '2020-04-17T14:36:15.779+02:00' ) ;
} ) ;
it ( 'should format according to ISO standard' , ( ) = > {
const options = { timeZone : 'America/New_York' , format : 'YYYY-MM-DDTHH:mm:ss.SSSZ' } ;
expect ( dateTimeFormat ( 1587126975779 , options ) ) . toBe ( '2020-04-17T08:36:15.779-04:00' ) ;
} ) ;
it ( 'should format according to ISO standard' , ( ) = > {
const options = { timeZone : 'Europe/Madrid' , format : 'YYYY-MM-DDTHH:mm:ss.SSSZ' } ;
expect ( dateTimeFormat ( 1587126975779 , options ) ) . toBe ( '2020-04-17T14:36:15.779+02:00' ) ;
} ) ;
} ) ;
describe ( 'dateTimeFormatTimeAgo' , ( ) = > {
it ( 'should return the correct format for 3 years ago' , ( ) = > {
const options = { timeZone : 'Europe/Stockholm' } ;
expect ( dateTimeFormatTimeAgo ( 1587126975779 , options ) ) . toBe ( '3 years ago' ) ;
} ) ;
it ( 'should return the correct format for 2 year ago' , ( ) = > {
const options = { timeZone : 'Europe/Stockholm' } ;
expect ( dateTimeFormatTimeAgo ( 1626154993000 , options ) ) . toBe ( '2 years ago' ) ;
} ) ;
it ( 'should return the correct format for 1 year ago' , ( ) = > {
const options = { timeZone : 'Europe/Stockholm' } ;
expect ( dateTimeFormatTimeAgo ( 1657731795000 , options ) ) . toBe ( 'a year ago' ) ;
} ) ;
} ) ;
describe ( 'dateTimeFormatWithAbbreviation' , ( ) = > {
it ( 'should return the correct format with zone abbreviation' , ( ) = > {
const options = { timeZone : 'Europe/Stockholm' } ;
expect ( dateTimeFormatWithAbbrevation ( 1587126975779 , options ) ) . toBe ( '2020-04-17 14:36:15 CEST' ) ;
} ) ;
it ( 'should return the correct format with zone abbreviation' , ( ) = > {
const options = { timeZone : 'America/New_York' } ;
expect ( dateTimeFormatWithAbbrevation ( 1587126975779 , options ) ) . toBe ( '2020-04-17 08:36:15 EDT' ) ;
} ) ;
it ( 'should return the correct format with zone abbreviation' , ( ) = > {
const options = { timeZone : 'Europe/Bucharest' } ;
expect ( dateTimeFormatWithAbbrevation ( 1587126975779 , options ) ) . toBe ( '2020-04-17 15:36:15 EEST' ) ;
} ) ;
} ) ;
describe ( 'timeZoneAbbrevation' , ( ) = > {
it ( 'should return the correct abbreviation' , ( ) = > {
const options = { timeZone : 'Europe/Stockholm' } ;
expect ( timeZoneAbbrevation ( 1587126975779 , options ) ) . toBe ( 'CEST' ) ;
} ) ;
it ( 'should return the correct abbreviation' , ( ) = > {
const options = { timeZone : 'America/New_York' } ;
expect ( timeZoneAbbrevation ( 1587126975779 , options ) ) . toBe ( 'EDT' ) ;
} ) ;
it ( 'should return the correct abbreviation' , ( ) = > {
const options = { timeZone : 'Europe/Bucharest' } ;
expect ( timeZoneAbbrevation ( 1587126975779 , options ) ) . toBe ( 'EEST' ) ;
} ) ;
} ) ;
} ) ;
} ) ;
} ) ;
} ) ;