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

Fix (?) timezone issue for datetime #114

Merged
merged 1 commit into from
Oct 8, 2024
Merged

Fix (?) timezone issue for datetime #114

merged 1 commit into from
Oct 8, 2024

Conversation

jdeniau
Copy link
Owner

@jdeniau jdeniau commented Oct 8, 2024

objects from datetime and date columns are returned as Date objects, but Date objects is just bad.

The mariadb timezone can be specified on the system and mysql library can pass a timezone as connection option, but let's keep it simple for now :

As Date are construct with "local" timezone, imagine the following date:

d = new Date('2020-01-01 00:00:00')
// Date Wed Jan 01 2020 00:00:00 GMT+0100 (heure normale d’Europe centrale)

Formating this with .toISOString() will give us "2019-12-31T23:00:00.000Z" (ISO string is UTC+0 for JS), but we do want only the local value.

We do implement a small date utility function to format the date that use the "Y-m-d H:i:s" format.

In the future, we might want to use another library, like temporal, luxon or dare-fns, but for the moment the helper works fine 👌

@jdeniau jdeniau merged commit cc80b73 into main Oct 8, 2024
3 checks passed
@jdeniau jdeniau deleted the handle-timezone-issue branch October 8, 2024 21:51
@jdeniau jdeniau linked an issue Oct 8, 2024 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Do not use local timezone
1 participant