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(datetime): account for 30 and 45 minute timezones when getting current date #25120

Merged
merged 3 commits into from
Apr 14, 2022

Conversation

liamdebeasi
Copy link
Contributor

Pull request checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)
  • Build (npm run build) was run locally and any changes were pushed
  • Lint (npm run lint) has passed locally and any fixes were made for failures

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

What is the current behavior?

Issue URL: resolves #25112

The getToday function always assumes timezones contain hour offsets. However, there are some timezones that includes minute offsets of either 30 or 45 minutes: https://www.timeanddate.com/time/time-zones-interesting.html

Ionic was not account for these minutes, so the getToday value was always off by either 30 or 45 minutes for users in the relevant timezones.

What is the new behavior?

  • We now check the minute remainder of the timezone offset:
  1. We take the timezone offset in minutes and divide by 60 to get the hours.
  2. From there we take the result mod 1 do get the fractional result.
  3. We multiply this result by 60 to get the fractional result in minutes.
  4. From there we add this to the existing date object.

The date object is smart enough to increment the hour one more time if we give it a value > 60. For example, doing date.setMinutes(70) will increment the hour by 1 and set the minutes to 10.

Does this introduce a breaking change?

  • Yes
  • No

Other information

I am investigating ways we can test this. Currently it does not look like Jest lets us mock the timezone between tests. I manually verified in multiple 30/45 minute timezones and the fix does appear to work.

@liamdebeasi liamdebeasi requested a review from a team as a code owner April 13, 2022 16:38
@github-actions github-actions bot added the package: core @ionic/core package label Apr 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: core @ionic/core package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: ion-datetime reset function doesn't work properly for time zones with 30 and 45 minutes
3 participants