+ {formatDate({ dateString: inSystemCalendarDateString, dateFormat, includeTimeZone, })} -
+ ) } diff --git a/src/shared/date/date-text.test.js b/src/shared/date/date-text.test.js index 176e53fea..dd610dcb3 100644 --- a/src/shared/date/date-text.test.js +++ b/src/shared/date/date-text.test.js @@ -1,3 +1,4 @@ +/* eslint-disable max-params */ import { useConfig } from '@dhis2/app-runtime' import React from 'react' import { render } from '../../test-utils/index.js' @@ -19,120 +20,128 @@ describe('DateText', () => { jest.clearAllMocks() }) it.each([ - { - inputDate: '2024-10-14T19:10:57.836', - dateFormat: 'yyyy-mm-dd', - calendar: 'gregory', - serverTimeZone: 'Etc/UTC', - includeTimeZone: false, - output: '2024-10-14 19:10', - }, - { - inputDate: '2024-10-14T19:10:57.836', - dateFormat: 'yyyy-mm-dd', - calendar: 'gregory', - serverTimeZone: 'Etc/UTC', - includeTimeZone: true, - output: '2024-10-14 19:10 (UTC)', - }, - { - inputDate: '2024-10-14T19:10:57.836', - dateFormat: 'dd-mm-yyyy', - calendar: 'gregory', - serverTimeZone: 'Etc/UTC', - includeTimeZone: false, - output: '14-10-2024 19:10', - }, - { - inputDate: '2024-10-14T19:10:57.836', - dateFormat: 'dd-mm-yyyy', - calendar: 'gregory', - serverTimeZone: 'Etc/UTC', - includeTimeZone: true, - output: '14-10-2024 19:10 (UTC)', - }, - { - inputDate: '2024-10-14T19:10:57.836', - dateFormat: 'yyyy-mm-dd', - calendar: 'gregory', - serverTimeZone: 'Asia/Vientiane', - includeTimeZone: true, - output: '2024-10-14 12:10 (UTC)', - }, - { - inputDate: '2024-10-14T19:10:57.836', - dateFormat: 'yyyy-mm-dd', - calendar: 'gregory', - serverTimeZone: 'Atlantic/Cape_Verde', - includeTimeZone: true, - output: '2024-10-14 20:10 (UTC)', - }, - { - inputDate: '2024-10-14T19:10:57.836', - dateFormat: 'yyyy-mm-dd', - calendar: 'gregory', - serverTimeZone: 'Etc/UTC', - includeTimeZone: null, - output: '2024-10-14 19:10', - }, - { - inputDate: '2024-10-14T19:10:57.836', - dateFormat: 'yyyy-mm-dd', - calendar: 'ethiopian', - serverTimeZone: 'Etc/UTC', - includeTimeZone: false, - output: '2017-02-04 19:10', - }, - { - inputDate: '2024-10-14T19:10:57.836', - dateFormat: 'yyyy-mm-dd', - calendar: 'ethiopian', - serverTimeZone: 'Africa/Addis_Ababa', - includeTimeZone: false, - output: '2017-02-04 16:10', - }, - { - inputDate: '2024-10-14T19:10:57.836', - dateFormat: 'yyyy-mm-dd', - calendar: 'ethiopian', - serverTimeZone: 'Africa/Addis_Ababa', - includeTimeZone: true, - output: '2017-02-04 16:10 (UTC)', - }, - { - inputDate: '2024-10-14T19:10:57.836', - dateFormat: 'yyyy-mm-dd', - calendar: 'nepali', - serverTimeZone: 'Etc/UTC', - includeTimeZone: false, - output: '2081-06-28 19:10', - }, - { - inputDate: '2024-10-14T19:10:57.836', - dateFormat: 'yyyy-mm-dd', - calendar: 'nepali', - serverTimeZone: 'Asia/Kathmandu', - includeTimeZone: false, - output: '2081-06-28 13:25', - }, - { - inputDate: '2024-10-14T19:10:57.836', - dateFormat: 'dd-mm-yyyy', - calendar: 'nepali', - serverTimeZone: 'Asia/Kathmandu', - includeTimeZone: false, - output: '28-06-2081 13:25', - }, + [ + '2024-10-14T19:10:57.836', + 'yyyy-mm-dd', + 'gregory', + 'Etc/UTC', + false, + '2024-10-14 19:10', + ], + [ + '2024-10-14T19:10:57.836', + 'yyyy-mm-dd', + 'gregory', + 'Etc/UTC', + true, + '2024-10-14 19:10 (UTC)', + ], + [ + '2024-10-14T19:10:57.836', + 'dd-mm-yyyy', + 'gregory', + 'Etc/UTC', + false, + '14-10-2024 19:10', + ], + [ + '2024-10-14T19:10:57.836', + 'dd-mm-yyyy', + 'gregory', + 'Etc/UTC', + true, + '14-10-2024 19:10 (UTC)', + ], + [ + '2024-10-14T19:10:57.836', + 'yyyy-mm-dd', + 'gregory', + 'Asia/Vientiane', + true, + '2024-10-14 12:10 (UTC)', + ], + [ + '2024-10-14T19:10:57.836', + 'yyyy-mm-dd', + 'gregory', + 'Atlantic/Cape_Verde', + true, + '2024-10-14 20:10 (UTC)', + ], + [ + '2024-10-14T19:10:57.836', + 'yyyy-mm-dd', + 'gregory', + 'Etc/UTC', + null, + '2024-10-14 19:10', + ], + [ + '2024-10-14T19:10:57.836', + 'yyyy-mm-dd', + 'ethiopian', + 'Etc/UTC', + false, + '2017-02-04 19:10', + ], + [ + '2024-10-14T19:10:57.836', + 'yyyy-mm-dd', + 'ethiopian', + 'Africa/Addis_Ababa', + false, + '2017-02-04 16:10', + ], + [ + '2024-10-14T19:10:57.836', + 'yyyy-mm-dd', + 'ethiopian', + 'Africa/Addis_Ababa', + true, + '2017-02-04 16:10 (UTC)', + ], + [ + '2024-10-14T19:10:57.836', + 'yyyy-mm-dd', + 'nepali', + 'Etc/UTC', + false, + '2081-06-28 19:10', + ], + [ + '2024-10-14T19:10:57.836', + 'yyyy-mm-dd', + 'nepali', + 'Asia/Kathmandu', + false, + '2081-06-28 13:25', + ], + [ + '2024-10-14T19:10:57.836', + 'dd-mm-yyyy', + 'nepali', + 'Asia/Kathmandu', + false, + '28-06-2081 13:25', + ], + [ + '2017-13-05T19:10:57.836', + 'yyyy-mm-dd', + 'gregory', + 'Etc/UTC', + false, + 'Invalid date (2017-13-05T19:10:57.836)', + ], ])( - 'should display %s given: format is %s, calendar is %s, server time zone is %s, and includeTimeZone is %s', - ({ + 'with input of %s format is %s, calendar is %s, server time zone is %s, and includeTimeZone is %s. Should display %s', + ( inputDate, dateFormat, calendar, serverTimeZone, includeTimeZone, - output, - }) => { + output + ) => { useConfig.mockReturnValueOnce({ systemInfo: { serverTimeZoneId: serverTimeZone,