Skip to content

Ability to reset the timezone #8054

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

jasonvarga
Copy link

Currently, getLocalTimeZone() caches the timezone. There's a todo to have a way to invalidate it, this PR resolves that.

I was writing timezone dependent tests in our own project and needed a way to fake the user's timezone. Due to the cache this wasn't possible.

This adds:

  • A setLocalTimeZone method that allows you to specify a timezone explicitly.
  • A resetLocalTimeZone to clear the cache which will naturally resolve itself next time getLocalTimeZone is used.

References discussion #7195

✅ Pull Request Checklist:

  • Included link to corresponding React Spectrum GitHub Issue.
  • Added/updated unit tests and storybook for this change (for new code or code which already has tests).
  • Filled out test instructions.
  • Updated documentation (if it already exists for this component).
  • Looked at the Accessibility Practices for this feature - Aria Practices

📝 Test Instructions:

This PR only exposes two new methods which aren't used in any components. To test this pull request, just run the tests.

@jasonvarga jasonvarga closed this Apr 8, 2025
@jasonvarga jasonvarga reopened this Apr 8, 2025
@snowystinger
Copy link
Member

Just calling out a key real-life use case from the discussion

This can cause unexpected behaviour if the user happens to change timezone (e.g. they close their laptop in one timezone, go somewhere, open it in another timezone).

Typically, we don't add functionality only for tests, so I want to include that there is a real-life use case as well.

@jasonvarga
Copy link
Author

Are you asking me to address that use case in this PR, or did you just want to note the reason?

@snowystinger
Copy link
Member

I was just noting it. Do you think the use case is not addressed? I do not mean implement the polling, or whatever mechanism people want to use.

@jasonvarga
Copy link
Author

Oh yeah for sure. Someone could set up their own polling mechanism to call the new resetLocalTimeZone method.

@jasonvarga jasonvarga closed this Apr 10, 2025
@jasonvarga jasonvarga reopened this Apr 10, 2025
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.

2 participants