-
Notifications
You must be signed in to change notification settings - Fork 15
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
feat: add hook to adjust for server time [LIBS-396] #1308
Conversation
expect(serverDateFromString).toEqual(serverDateFromNumber) | ||
}) | ||
|
||
// returns current (client) date if no argument is provided |
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.
this should be tested jest.useFakeTimers/jest.setSystemTime, but I got an error about setSystemTime not existing on jest...which hopefully could be fixed by upgrading jest, but I didn't want to do that before deciding if we wanted to allow initialization of dates from null
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.
Maybe @ismay can help 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.
Thanks. Will check if the jest version is the issue and follow up.
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.
Sorry, I missed this notification. I've just now talked to Tom on slack, but I'll post the important part here as well. Basically, from what I understood from Tom, he'd like to upgrade to the latest version of cli-app-scripts to use the updated version of jest it ships. Unfortunately this lib is on v6, so that means working through these breaking changes:
- v10: https://github.com/dhis2/app-platform/blob/master/CHANGELOG.md#1000-2022-07-26
- v9: https://github.com/dhis2/app-platform/blob/master/CHANGELOG.md#900-2022-03-14
- v8: https://github.com/dhis2/app-platform/blob/master/CHANGELOG.md#800-2021-09-20
- v7: https://github.com/dhis2/app-platform/blob/master/CHANGELOG.md#700-2021-06-14
There might be workarounds and other solutions, but if you want to upgrade cli-app-scripts working through the above would be the way.
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'm wondering why not just copy what's in the aggregate data entry app.
Also I'm wondering about the name of useDate
. Its name suggests that it returns a date object, but it returns an object with date utilities. I'd prefer a more precise name, e.g. useClientServerDateUtils
or so. It's not as sexy, but it conveys its usage correctly.
Thanks @Mohammer5!
I think I might have answered this in the very wordy discussion on the ticket (see particularly 'Technical Implementation Questions' on this comment), which explains some of the choices (I reviewed these with Hendrik who was okay with the overall recommendations and suggested focusing on the immediate narrow issue of adjusting for server/client timezones)
Sounds good to me. |
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.
Good work. I've left a few comments.
expect(serverDateFromString).toEqual(serverDateFromNumber) | ||
}) | ||
|
||
// returns current (client) date if no argument is provided |
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.
Maybe @ismay can help 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 responded to some points and resolved most conversations. Let me know if you agree with me.
Co-authored-by: Hendrik de Graaf <HendrikThePendric@users.noreply.github.com>
61629f5
to
df418bc
Compare
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.
Thanks @tomzemp
# [3.8.0](v3.7.0...v3.8.0) (2023-01-19) ### Features * add hook to adjust for server time [LIBS-396] ([#1308](#1308)) ([d511303](d511303))
🎉 This PR is included in version 3.8.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
See LIBS-396.
This adds a hook useDate (in config package as it makes use of the systemInfo information on server timezone). The hook returns two helper functions fromServerDate and fromClientDate that accepts a timestamp (or other accepted input to JavaScript Date constructor) and returns a DHIS2Date object (an extension of JavaScript Date) that gives time in client timezone (and exposes methods for getting server and client ISO strings).
For an example of using this to solve common issue with relative time differences: dhis2/user-app@master...DHIS2-14203/fix-update-time