-
Notifications
You must be signed in to change notification settings - Fork 251
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
(fix): format observation datetime to accurate local time to prevent inaccurate timestamps #2208
base: main
Are you sure you want to change the base?
(fix): format observation datetime to accurate local time to prevent inaccurate timestamps #2208
Conversation
test?.obs?.map((entry) => { | ||
const isoFormattedString = entry.obsDatetime.replace(' ', 'T').replace('.0', '.000').concat('Z'); | ||
const date = new Date(isoFormattedString); | ||
return format(date, 'yyyy-MM-dd HH:mm:ss'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use the framework formatDatetime
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not want to break the existing functionality. In my investigation using formatDatetime
returns dates like Today 06:50 am
which was not my intention. I wanted to return a string like this 2024-09-04 06:23:23.0
so that wherever the value is being used it doesn't break anything. In short I wanted to return the original date but formatted correctly,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I vote for consistency across the system and I vote for the formatters provided by the framework. Is there a strong reason not to go with the formatted date from the framework's function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes @ojwanganto that date object at that point is not for display but rather to make sure it is in the correct timezone and that approach is what made it possible. using formatDateTime
or any other format function from the framework did not quite fit the use case.
I am open to suggestions though.
const formatObsDatetime = (obsDatetime: string) => { | ||
const isoFormattedString = obsDatetime.replace(' ', 'T').replace('.0', '.000').concat('Z'); | ||
return isoFormattedString; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const formatObsDatetime = (obsDatetime: string) => { | |
const isoFormattedString = obsDatetime.replace(' ', 'T').replace('.0', '.000').concat('Z'); | |
return isoFormattedString; | |
}; | |
const formatObsDatetime = (obsDatetime: string) => { | |
return dayjs(obsDatetime).toISOString(); | |
}; |
dayjs already provides this conversion to ISO format.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The obsDatetime
parameter is weird. It's an already formatted date string like this: 2025-01-22 05:28:00.0
Following your suggestion rolls back the date by 3 hours (probably because I am on EAT).
obsDatetime - 2025-01-22 05:28:00.0
isoFormattedString - 2025-01-22T05:28:00.000Z
formattedWithDayJS - 2025-01-22T02:28:00.000Z
thanks for highlighting though I have seen a use case for it on the tooltip for accuracy purposes
Requirements
Summary
This PR formats the test timestamp in the results panel using the openmrs framework
formatDatetime
function that accurately handles the users locale. Since the date we had was already formatted to a certain format we first convert it to an ISO string (which was the original format) then format it correctly to the users local time removing the inconsistency.Screenshots
Results
Visits
Related Issue
https://openmrs.atlassian.net/browse/O3-4297
Other