Fix timezone handling in quantised activity - #1659
skyfallwastaken wants to merge 1 commit into
Conversation
Amp-Thread-ID: https://ampcode.com/threads/T-01a05ac7-c804-756c-8dcb-97745c5b3944 Co-authored-by: Amp <amp@ampcode.com>
Greptile SummaryThe PR makes quantized admin activity use the target user’s timezone consistently for month boundaries, daily SQL grouping, point grouping, and returned day timestamps.
Confidence Score: 5/5The PR appears safe to merge with no actionable correctness or security failures identified. The controller now uses one validated timezone across query bounds, SQL grouping, Ruby grouping, and response generation, while the added test exercises the principal month-boundary and DST behavior. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart LR
A[Requested year and month] --> B[Resolve target user timezone]
B --> C[Compute local month epoch bounds]
C --> D[Select active heartbeats]
D --> E[Convert timestamps to local time in SQL]
E --> F[Group and quantize by local day]
E --> G[Calculate capped daily durations]
F --> H[Group returned points by local Date]
G --> I[Build each calendar day response]
H --> I
Reviews (1): Last reviewed commit: "Fix quantized activity time zones" | Re-trigger Greptile |
There was a problem hiding this comment.
Pull request overview
This PR fixes the admin “quantized visualization” endpoint so month bounds, day bucketing, and returned date_timestamp_s values are computed in the target user’s timezone, preventing mis-bucketed activity near local month/day boundaries and across DST transitions.
Changes:
- Compute month start/end epochs from the user’s timezone and build the response days by local calendar
Daterather than stepping UTC seconds. - Bucket/quantize heartbeats in SQL using local-time day boundaries and group returned points by the same local date in Ruby.
- Update OpenAPI/Rswag descriptions and add a regression test covering DST + month-boundary behaviour.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
app/controllers/api/admin/v1/admin_controller.rb |
Switches quantized visualization month bounds, SQL grouping, and response assembly to the target user’s timezone/local dates. |
test/controllers/api/admin/v1/admin_controller_test.rb |
Adds an integration test asserting correct local-day bucketing across DST and month boundaries. |
swagger/admin/swagger.yaml |
Updates the OpenAPI description for date_timestamp_s to reflect user-local start-of-day epoch semantics. |
spec/requests/api/admin/v1/admin_misc_spec.rb |
Updates the Rswag schema description for date_timestamp_s to match the new semantics. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| begin | ||
| start_epoch = Time.utc(year, month, 1).to_i | ||
| end_epoch = month == 12 ? Time.utc(year + 1, 1, 1).to_i : Time.utc(year, month + 1, 1).to_i | ||
| timezone = Time.find_zone!(user.timezone) | ||
| start_date = Date.new(year, month, 1) | ||
| end_date = start_date.next_month | ||
| start_epoch = timezone.local(start_date.year, start_date.month, start_date.day).to_i |
f1786c8 to
6101271
Compare
Summary of the problem
The quantised activity endpoint used UTC month bounds and day buckets for every user. This misplaced activity near local month boundaries and produced incorrect calendar days across daylight saving transitions.
Describe your changes
Use the target user's validated timezone for local month bounds, SQL day grouping and quantisation. Group returned points by the same local date and build the response by calendar date while preserving the existing duration cap and response shape.
Screenshots / Media
Not applicable. This changes the JSON activity calculation only.