Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: swap relative and absolute time #596

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 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-01-02T14:28:02.554Z\n"
"PO-Revision-Date: 2024-01-02T14:28:02.554Z\n"
"POT-Creation-Date: 2024-02-15T14:26:30.056Z\n"
"PO-Revision-Date: 2024-02-15T14:26:30.056Z\n"

msgid "Something went wrong"
msgstr "Something went wrong"
Expand Down Expand Up @@ -189,8 +189,8 @@ msgstr "On/off"
msgid "No jobs to display"
msgstr "No jobs to display"

msgid "Not scheduled"
msgstr "Not scheduled"
msgid "Now"
msgstr "Now"

msgid "Hide jobs"
msgstr "Hide jobs"
Expand Down
24 changes: 16 additions & 8 deletions src/components/JobTable/NextRun.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ import i18n from '@dhis2/d2-i18n'
import { Tooltip } from '@dhis2/ui'
import React from 'react'

const formatDate = (dhis2Date) =>
`${dhis2Date
const dateToServerTimeString = (dhis2Date) => {
const serverTime = dhis2Date
.getServerZonedISOString()
.substring(0, 19)
.split('T')
.join(' ')} (${dhis2Date.serverTimezone})`
.join(' ')
const serverTZ = dhis2Date.serverTimezone

return `${serverTime} (${serverTZ})`
}

const NextRun = ({ nextExecutionTime, enabled }) => {
const { fromServerDate } = useTimeZoneConversion()
Expand All @@ -22,10 +26,12 @@ const NextRun = ({ nextExecutionTime, enabled }) => {
const now = Date.now()

/**
* Adjust for client/sever time zone difference.
* nextExecutionTime does not have timezone information. With
* fromServerDate we return an extended Date object that
* assumes the timestamp refers to server time and parses the
* nextExecutionTime to the user's local timezone.
*/
const nextRun = fromServerDate(nextExecutionTime)
const nextRunIsInPast = nextRun.getTime() <= now
const nextExecutionDate = fromServerDate(nextExecutionTime)

/**
* If the nextExecutionTime is in the past that means that
Expand All @@ -37,13 +43,15 @@ const NextRun = ({ nextExecutionTime, enabled }) => {
* nextExecutionTime will be updated to a time in the future.
*/

const nextRunIsInPast = nextExecutionDate.getTime() <= now

if (nextRunIsInPast) {
return i18n.t('Now')
}

return (
<Tooltip content={moment(nextRun).fromNow()}>
{formatDate(nextRun)}
<Tooltip content={dateToServerTimeString(nextExecutionDate)}>
{moment(nextExecutionDate).fromNow()}
</Tooltip>
)
}
Expand Down
Loading