Skip to content

Conversation

jasonvarga
Copy link
Contributor

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
Contributor 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
Contributor 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
@yihuiliao yihuiliao added this pull request to the merge queue Aug 6, 2025
@yihuiliao yihuiliao removed this pull request from the merge queue due to a manual request Aug 6, 2025
@yihuiliao yihuiliao changed the title Ability to reset the timezone fix: allow user to invalidate timezone Aug 6, 2025
@yihuiliao yihuiliao changed the title fix: allow user to invalidate timezone fix: allow user to reset timezone Aug 6, 2025
@yihuiliao yihuiliao added this pull request to the merge queue Aug 6, 2025
Merged via the queue into adobe:main with commit 1f35627 Aug 6, 2025
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants