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

WC Post Types: Fix timezone offset when sessions happen after DST #1394

Merged
merged 2 commits into from
Oct 18, 2024

Conversation

ryelle
Copy link
Contributor

@ryelle ryelle commented Oct 11, 2024

This change updates how the session dates are converted when the site and client timezones are different. Rather than creating a fixed timezone offset on page load, this converts the times into the server timezone for the given date — this way, the offset is correctly applied if a future date is in a different timezone (DST starts or ends).

Fixes #1385.

The date-fns libraries added are also used in core/gutenberg, though they are bundled in the built script, not as externals. Since this in the editor, and it's not a huge library (not like moment), I think this is okay. Once an admin is editing sessions, it'll be cached from page to page.

How to test the changes in this Pull Request:

  1. Set your site's timezone to a location with DST, for example Los Angeles or New York (different than your current timezone).
  2. DST for those locations ends on Nov 3rd, so try setting the time on a session in December.
  3. The session date/time UI should have a label with the site's timezone, and the time is in that timezone.
  4. It should work, there should be no glitching or skipping numbers.
  5. Once saved, if you view the session in the list table, it should be the same - also in the site timezone.

Try with the site's timezone the same as your own & no during DST to ensure no regressions.

This change updates how the session dates are converted when the site and client timezones are different. Rather than creating a fixed timezone offset on page load, this converts the times into the server timezone for the given date — this way, the offset is correctly applied if a future date is in a different timezone (DST starts or ends).

Fixes #1385
@ryelle ryelle added the [Component] WC-Post-Types Organizers, Speakers, Sessions, Schedule, Sponsors, Volunteers label Oct 11, 2024
@ryelle ryelle self-assigned this Oct 11, 2024
Copy link
Contributor

@renintw renintw left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the fix!

serverTimezone = getTimezoneOffset( settings.timezone );
}

// Because this date is a timestamp, it's understood to be a UTC value, and
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@ryelle ryelle merged commit 087161a into production Oct 18, 2024
3 checks passed
@ryelle ryelle deleted the fix/session-timezones branch October 18, 2024 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Component] WC-Post-Types Organizers, Speakers, Sessions, Schedule, Sponsors, Volunteers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Session time input changes time unexpectedly
2 participants