Fix timezone bug in analytics revenue time series date bucketing - #151
Open
michaellasmanis wants to merge 15 commits into
Open
Fix timezone bug in analytics revenue time series date bucketing#151michaellasmanis wants to merge 15 commits into
michaellasmanis wants to merge 15 commits into
Conversation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…able Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The revenue time series helpers (formatDateKey, formatMonthKey, generateDailyKeys, generateMonthlyKeys) were using local-time Date methods (getFullYear, getMonth, getDate, setHours, setDate, setMonth) to generate the date keys used for bucketing revenue data points. However, purchase timestamps are stored as ISO 8601 strings (UTC), and the SQL query groups revenue by extracting the date prefix from those UTC strings via substr(createdAt, 1, 10). This mismatch meant that in timezones behind UTC (e.g. US timezones), a purchase made in the late local evening would have a UTC date one day ahead of the locally-generated key. The revenue from the DB query would then fail to map to any key in the generated range, silently dropping it from the results. Switched all four helper functions to use UTC Date methods (getUTCFullYear, getUTCMonth, getUTCDate, setUTCHours, setUTCDate, setUTCMonth, Date.UTC) so the generated keys are always consistent with the UTC-based grouping in the database queries. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
mattpocock
force-pushed
the
live-run-through
branch
from
April 27, 2026 09:20
15f6a7c to
2c2858e
Compare
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.
This should be applied to commit "05.06.02: Instructor analytics Phase 2 — revenue chart + per-course table"
This unit tests there are failing from PDT (UTC-7)
The revenue time series helpers (formatDateKey, formatMonthKey, generateDailyKeys, generateMonthlyKeys) were using local-time Date methods (getFullYear, getMonth, getDate, setHours, setDate, setMonth) to generate the date keys used for bucketing revenue data points. However, purchase timestamps are stored as ISO 8601 strings (UTC), and the SQL query groups revenue by extracting the date prefix from those UTC strings via substr(createdAt, 1, 10).
This mismatch meant that in timezones behind UTC (e.g. US timezones), a purchase made in the late local evening would have a UTC date one day ahead of the locally-generated key. The revenue from the DB query would then fail to map to any key in the generated range, silently dropping it from the results.
Switched all four helper functions to use UTC Date methods (getUTCFullYear, getUTCMonth, getUTCDate, setUTCHours, setUTCDate, setUTCMonth, Date.UTC) so the generated keys are always consistent with the UTC-based grouping in the database queries.