Repository navigation
fix(analytics-utils): localTime offset hour wrong in negative half-hour timezones - #523
Open
sarmah-rup wants to merge 1 commit into
Open
sarmah-rup wants to merge 1 commit into
sarmah-rup wants to merge 1 commit into
Conversation
…-hour zones pad() floored before taking the absolute value, so localTime() built the timezone offset hour from Math.floor(tzo / 60). For negative half-hour zones Math.floor(-9.5) is -10, so UTC-09:30 (Pacific/Marquesas) rendered as -10:30 and Newfoundland -03:30 rendered as -04:30. The sign is already handled by the dif variable, so take the magnitude before the divide: pad(Math.abs(tzo) / 60). Minutes and positive/whole-hour zones are unchanged. Adds uvu regression coverage pinning process.env.TZ for Marquesas, Newfoundland, Kolkata (+05:30), New York and UTC.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
localTime()emits the wrong offset hour in negative half-hour timezones. In Newfoundland (UTC-03:30) it returns-04:30, and in Pacific/Marquesas (UTC-09:30) it returns-10:30, so timestamps from those users are off by an hour.Root cause
The hour is built with
pad(tzo / 60), andpadfloors before taking the absolute value. For UTC-09:30,tzo / 60is-9.5, andMath.floor(-9.5)is-10.Solution
The sign is already handled by
dif, so take the magnitude first:Positive and whole-hour zones are unchanged.
Closes #524
Testing
Added
packages/analytics-utils/tests/localTime.test.js(uvu), pinningprocess.env.TZfor Marquesas, Newfoundland, Kolkata, New York and UTC. The Marquesas case fails before the change (-10:30) and passes after.