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

[v11.0.x] DateTimePicker: Alternate timezones now behave correctly #87041

Merged
merged 1 commit into from
Apr 29, 2024

Conversation

ashharrison90
Copy link
Contributor

Backport 7fab894 from #86750


What is this feature?
It's a bugfix for the timezone issue with the DateTimePicker

Why do we need this feature?
Currently, users that have one timezone in Grafana (bootData) and another on in their client/browser, cannot use the DateTimePicker as it changes the date onBlur as well as showing invalid date/time information in date/time modal.

Who is this feature for?
Developers who wants to use DateTimePicker as well as users that already are interacting with DateTimePicker in published plugins

Which issue(s) does this PR fix?:
86305

Fixes #86305

Special notes for your reviewer:
setTimeZoneResolver needs to be used to change timezone.
There are notes in #86305 how you could do this.

I just added the blow snippe to DateTimePicker.story.tsx:

  useEffect(() => {
    setTimeZoneResolver(() => 'America/Indiana/Marengo')
    return () => setTimeZoneResolver(() => 'browser')
  }, []);

Please check that:

  • It works as expected from a user's perspective.
  • If this is a pre-GA feature, it is behind a feature toggle.
  • The docs are updated, and if this is a notable improvement, it's added to our What's New doc.

* Add failing tests for timezone handling

* Fix `DateTimePicker.tsx` timezone handling

- Resolves `onBlur` issue
- Resolve Calendar and TimeOfDay issues
- Update test to cover different timezone

* Handle `console.warn` in test

* Handle `console.warn` in test #2

* Better handling of invalid date

When parsing date string with `dateTime`, adding a second `formatInput` aids in both parsing the actual string and avoid `console.warn` when `moment` reverts to be using `Date`.

* add more test cases

* Ash/proposed changes (#86854)

* simplify

* only need this change

* formatting

* const > let

* add test to ensure calendar is always showing the matching day

* separate state

* undo story changes

* update util function comments

* fix for selecting date in the calendar

---------

Co-authored-by: Ashley Harrison <ashley.harrison@grafana.com>
(cherry picked from commit 7fab894)
@ashharrison90 ashharrison90 added type/bug area/frontend add to changelog area/grafana/ui Issues that belong to components in the @grafana/ui library backport A backport PR labels Apr 29, 2024
@ashharrison90 ashharrison90 added this to the 11.0.x milestone Apr 29, 2024
@ashharrison90 ashharrison90 requested review from a team as code owners April 29, 2024 10:26
@ashharrison90 ashharrison90 requested review from joshhunt, JoaoSilvaGrafana and sunker and removed request for a team April 29, 2024 10:26
Copy link
Contributor

@eledobleefe eledobleefe left a comment

Choose a reason for hiding this comment

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

LGTM 👌

@ashharrison90 ashharrison90 enabled auto-merge (squash) April 29, 2024 10:34
@ashharrison90 ashharrison90 merged commit e0a06c6 into v11.0.x Apr 29, 2024
23 checks passed
@ashharrison90 ashharrison90 deleted the backport-86750-to-v11.0.x branch April 29, 2024 10:42
@fabrizio-grafana fabrizio-grafana modified the milestones: 11.0.x, 11.0.0 May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
add to changelog area/frontend area/grafana/ui Issues that belong to components in the @grafana/ui library backport A backport PR type/bug
Projects
Status: 🚀 Done
Development

Successfully merging this pull request may close these issues.

None yet

5 participants