Skip to content

Commit

Permalink
fix: pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
tomzemp committed Oct 16, 2024
1 parent 9722a21 commit b944648
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 121 deletions.
10 changes: 5 additions & 5 deletions i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"POT-Creation-Date: 2024-10-14T16:17:34.694Z\n"
"PO-Revision-Date: 2024-10-14T16:17:34.694Z\n"
"POT-Creation-Date: 2024-10-16T08:10:10.883Z\n"
"PO-Revision-Date: 2024-10-16T08:10:10.883Z\n"

msgid "Not authorized"
msgstr "Not authorized"
Expand Down Expand Up @@ -54,9 +54,6 @@ msgstr "1 value failed to save"
msgid "{{numberOfErrors}} values failed to save"
msgstr "{{numberOfErrors}} values failed to save"

msgid "This form closes and will be locked at {{-dateTime}}"
msgstr "This form closes and will be locked at {{-dateTime}}"

msgid "Closes {{-relativeTime}}"
msgstr "Closes {{-relativeTime}}"

Expand Down Expand Up @@ -598,6 +595,9 @@ msgstr ""
"Something went wrong while setting the form's completion to "
"\"{{completed}}\": {{errorMessage}}"

msgid "Invalid date ({{date}})"
msgstr "Invalid date ({{date}})"

msgid "{{title}} (disabled)"
msgstr "{{title}} (disabled)"

Expand Down
10 changes: 4 additions & 6 deletions src/bottom-bar/form-expiry-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { IconInfo16, colors, Tooltip } from '@dhis2/ui'
import cx from 'classnames'
import React from 'react'
import i18n from '../locales/index.js'
import { useLockedContext, getRelativeTime } from '../shared/index.js'
import { useLockedContext, getRelativeTime, DateText } from '../shared/index.js'
import styles from './main-tool-bar.module.css'

export default function FormExpiryInfo() {
Expand All @@ -20,16 +20,14 @@ export default function FormExpiryInfo() {
calendar: 'gregory',
timezone,
})
const dateTime = `${lockDate} (${timezone})`

return (
<>
{!locked && lockDate && (
<Tooltip
content={i18n.t(
'This form closes and will be locked at {{-dateTime}}',
{ dateTime }
)}
content={
<DateText date={lockDate} includeTimeZone={true} />
}
>
<span
className={cx(
Expand Down
11 changes: 9 additions & 2 deletions src/shared/date/date-text.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useConfig, useTimeZoneConversion } from '@dhis2/app-runtime'
import i18n from '@dhis2/d2-i18n'
import PropTypes from 'prop-types'
import React from 'react'
import { convertFromIso8601ToString } from './date-utils.js'
Expand Down Expand Up @@ -37,6 +38,12 @@ export const DateText = ({ date, includeTimeZone }) => {

// NOTE: the passed date is assumed to be in ISO

// check that date is parsable as ISO
const parsedDate = new Date(date)
if (isNaN(parsedDate)) {
return <span>{i18n.t('Invalid date ({{date}})', { date })}</span>
}

// we first correct for time zone
const dateClient = fromServerDate(date)

Expand All @@ -49,13 +56,13 @@ export const DateText = ({ date, includeTimeZone }) => {
// we put it in the system setting for the date display

return (
<p>
<span>
{formatDate({
dateString: inSystemCalendarDateString,
dateFormat,
includeTimeZone,
})}
</p>
</span>
)
}

Expand Down
225 changes: 117 additions & 108 deletions src/shared/date/date-text.test.js
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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,
Expand Down

0 comments on commit b944648

Please sign in to comment.