Skip to content

fix(analytics-utils): localTime offset hour wrong in negative half-hour timezones - #523

Open
sarmah-rup wants to merge 1 commit into
DavidWells:masterfrom
sarmah-rup:fix/localtime-negative-half-hour-offset
Open

sarmah-rup wants to merge 1 commit into
DavidWells:masterfrom
sarmah-rup:fix/localtime-negative-half-hour-offset

Conversation

@sarmah-rup

@sarmah-rup sarmah-rup commented Sep 29, 2026 •

Copy link
Copy Markdown

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), and pad floors before taking the absolute value. For UTC-09:30, tzo / 60 is -9.5, and Math.floor(-9.5) is -10.

Solution

The sign is already handled by dif, so take the magnitude first:

${dif}${pad(Math.abs(tzo) / 60)}:${pad(tzo % 60)}

Positive and whole-hour zones are unchanged.

Closes #524

Testing

Added packages/analytics-utils/tests/localTime.test.js (uvu), pinning process.env.TZ for Marquesas, Newfoundland, Kolkata, New York and UTC. The Marquesas case fails before the change (-10:30) and passes after.

…-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.
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.

analytics-utils: localTime() offset hour is wrong in negative half-hour timezones

1 participant