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 getParsedDate - add 8h to account for timezone #963

Merged
merged 5 commits into from
Jan 3, 2025

Conversation

adriangohjw
Copy link
Contributor

Problem

date in collection preview is one day behind on studio

Solution

Breaking Changes

  • Yes - this PR contains breaking changes
    • Details ...
  • No - this PR is backwards compatible

Bug Fixes:

  • add a 8h addition to date to account for SG timezone

Before & After Screenshots

BEFORE:

Screenshot 2024-12-27 at 9 28 07 PM

AFTER:

Screenshot 2024-12-27 at 10 32 13 PM

Tests

  1. create a link in a collection
  2. select a date
  3. the date in the date selector and that in the preview should be the same

@adriangohjw adriangohjw added the bug Something isn't working label Dec 27, 2024
@adriangohjw adriangohjw self-assigned this Dec 27, 2024
@adriangohjw adriangohjw requested a review from a team as a code owner December 27, 2024 14:36
@datadog-opengovsg
Copy link

datadog-opengovsg bot commented Dec 27, 2024

Datadog Report

Branch report: fix-wrong-timezone-in-renderengine-in-studio
Commit report: fb75679
Test service: isomer-studio

✅ 0 Failed, 245 Passed, 36 Skipped, 49.19s Total Time
⬆️ Test Sessions change in coverage: 1 increased (+0.24%)

if (format === TIMEZONE_DATE_FORMAT) {
offsetDate = new Date(
// Add 8 hours to account for the Singapore timezone offset
new Date(dateString).getTime() + 8 * 60 * 60 * 1000,
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't new Date() by default get the date in local timezone?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

from what i understand, new Date() is the reference date that provides default values for any missing components in dateString. e.g. if the dateString includes only the month and day, the year is taken from the reference date

let offsetDate = dateString
if (format === TIMEZONE_DATE_FORMAT) {
offsetDate = new Date(
// Add 8 hours to account for the Singapore timezone offset
Copy link
Contributor

Choose a reason for hiding this comment

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

issue: I think hardcoding the 8 hours here might not be an ideal solution (although the vast majority of our users are in this timezone). Instead, we should be parsing the date in the machine's local time zone, as we can see that the date changes when you try to change your computer's timezone.

Screen.Recording.2025-01-02.at.21.49.12.mov

This doesn't affect actual live sites since the date formats have already been statically generated at build time.

Screen.Recording.2025-01-03.at.10.52.11.mov

Hence, instead of 8, we should determine the timezone offset that the user's machine is in, then inputing that as part of the calculation here. Alternatively, we can discard the time part of this date string and only work with the date part (i.e. yyyy-MM-dd'T'HH:mm:ss.SSS'Z' becomes just yyyy-MM-dd) before performing the parsing, so we are guaranteed to be working without consideration for the timezone.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

address in 3c4c605, thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

btw have also updated GH actions to use Asia/Singapore during CI - c7177d5

@adriangohjw adriangohjw merged commit 84a079f into main Jan 3, 2025
18 checks passed
@adriangohjw adriangohjw deleted the fix-wrong-timezone-in-renderengine-in-studio branch January 3, 2025 07:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants