fix: epoch converter showing wrong UTC and IST times - #129
Merged
Merged
Conversation
formatDateTime() read the date with local-time getters, so the "UTC" field printed the visitor's local time and the "IST" field (which pre-adds the +5:30 offset) applied the offset a second time. On an IST browser, epoch 1785828555 rendered as 12:59:15 UTC / 18:29:15 IST instead of the correct 07:29:15 UTC / 12:59:15 IST. istToEpoch() had the same class of bug in reverse: it built the date with the local-time Date(...) constructor before subtracting the IST offset, which was only correct in a UTC browser. Both now use the UTC APIs (getUTC*, Date.UTC), making conversions independent of the visitor's timezone. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
The bug
On the epoch timestamp converter, both output fields were wrong for anyone browsing from IST. Epoch
1785828555rendered as:2026-08-04 12:59:152026-08-04 07:29:152026-08-04 18:29:152026-08-04 12:59:15The UTC field was off by +5:30 and the IST field was double-offset.
Root cause
formatDateTime()read the date with local-time getters (getFullYear,getHours, …). Since the browser was in IST:epochToUTC()formatted the date in local time and labelled it UTC → printed IST.epochToIST()pre-addsIST_OFFSET_MSand then the local getters added another +5:30 → double offset.istToEpoch()had the same class of bug in reverse — it built the date with the local-timeDate(...)constructor before subtracting the IST offset, so it was only correct in a UTC browser. Fixed here too, since it was silently wrong for non-IST visitors.utcToEpoch()was already correct (it usedDate.UTC) and is unchanged.The fix
Use the UTC APIs —
getUTC*informatDateTime(),Date.UTC(...)inistToEpoch()— so output no longer depends on where the visitor is.Testing
Property-tested the conversion helpers against an independent oracle (
Intl.DateTimeFormatwithtimeZone, i.e. real tzdata rather than this file's own offset arithmetic).20,136 assertions × 10 visitor timezones = 201,360 checks, 0 failures.
Coverage per zone:
utcToEpochandistToEpoch0,±1,-19800(IST epoch zero),86399/86400,4102444800,2534023007991785828555.7)Zones:
Asia/Kolkata,America/Los_Angeles,UTC,Australia/Sydney,Asia/Kathmandu(+5:45),Europe/London,America/St_Johns(−3:30),Pacific/Chatham(+12:45),Asia/Tokyo,America/Sao_Paulo.Control run — the identical suite against the pre-fix code, to confirm the tests are actually sensitive:
Asia/KolkataAmerica/Los_AngelesUTCThe old code passing cleanly under
UTCand failing everywhere else confirms the root cause: it was accidentally correct in exactly one timezone.Not covered
Verified in Node against the extracted conversion helpers — not in a real browser. The DOM wiring (click handler, date/time pickers,
parseDateTimeinput formats, the "current time" button) is unexercised and worth a manual click-through. Those paths are unchanged by this PR.Notes
collectstaticneeded: this repo has nostatic/source tree, sostaticfiles/is the served copy.scripts/uglify-minify.shruns terser in place and isn't wired into CI, so it doesn't affect this change.flake8fails onviews_converters.py(W292) andviews_textanalyzer.py(W391), both pre-existing onmasterata1012bd. This PR changes one JS file and no Python.