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

feat: add hook to adjust for server time [LIBS-396] #1308

Merged
merged 9 commits into from
Jan 19, 2023

Conversation

tomzemp
Copy link
Member

@tomzemp tomzemp commented Dec 15, 2022

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

expect(serverDateFromString).toEqual(serverDateFromNumber)
})

// returns current (client) date if no argument is provided
Copy link
Member Author

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

Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link

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:

There might be workarounds and other solutions, but if you want to upgrade cli-app-scripts working through the above would be the way.

Copy link
Contributor

@Mohammer5 Mohammer5 left a 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.

@tomzemp
Copy link
Member Author

tomzemp commented Dec 20, 2022

Thanks @Mohammer5!

I'm wondering why not just copy what's in the aggregate data entry app.

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)

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.

Sounds good to me. useDate was a name I just added without much thought.

Copy link
Contributor

@HendrikThePendric HendrikThePendric left a 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
Copy link
Contributor

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.

Copy link
Contributor

@HendrikThePendric HendrikThePendric left a 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.

@tomzemp tomzemp force-pushed the LIBS-396/server-client-date-hook branch from 61629f5 to df418bc Compare January 17, 2023 15:14
Copy link
Contributor

@HendrikThePendric HendrikThePendric left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @tomzemp

@tomzemp tomzemp merged commit d511303 into master Jan 19, 2023
@tomzemp tomzemp deleted the LIBS-396/server-client-date-hook branch January 19, 2023 08:06
dhis2-bot added a commit that referenced this pull request Jan 19, 2023
# [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))
@dhis2-bot
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants