fix: correct GPS epoch constant in format_G (%G)#109
Conversation
The GPS epoch constant in format_G is 315993600 (Jan 6, 1980 08:00 UTC) instead of the correct 315964800 (Jan 6, 1980 00:00 UTC). This 8-hour offset causes wrong GPS week numbers at week boundaries. These tests fail against the current code, demonstrating the bug. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The GPS epoch is midnight UTC on January 6, 1980 (315964800), not 08:00 UTC (315993600). The 8-hour offset caused %G to return wrong GPS week numbers for timestamps near week boundaries (~4.8% of all timestamps). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Greptile SummaryThis PR fixes a long-standing off-by-one bug in the Confidence Score: 5/5Safe to merge — the constant change is correct and all new test assertions are mathematically verified The fix is a single well-understood constant correction (28800 seconds = 8 hours) with independent verification. New tests cover the exact failure mode (week-boundary timestamps) and pass with the corrected value. No other code paths are affected. No files require special attention
|
| Filename | Overview |
|---|---|
| lib/Date/Format/Generic.pm | Single-constant fix: GPS epoch corrected from 315993600 (08:00 UTC Jan 6, 1980) to 315964800 (midnight UTC Jan 6, 1980), eliminating an 8-hour offset that caused off-by-one GPS week numbers at week boundaries |
| t/gps-week.t | New test file with 6 boundary-focused assertions covering GPS epoch identity, end/start of week 0→1 transition, a known historical reference, and a recent date sanity check; all expected values verified correct |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["time2str('%G', $unix_ts)"] --> B["format_G called\n($_[0]->[9] = raw Unix timestamp)"]
B --> C["Subtract GPS epoch\n315964800 ✅\n(was 315993600 ❌)"]
C --> D["Divide by 604800\n(seconds per week)"]
D --> E["int() truncate\ntoward zero"]
E --> F["GPS week number returned"]
subgraph "Old vs New epoch"
G["315993600\n= Jan 6, 1980 08:00 UTC ❌\n(+8 hours wrong)"]
H["315964800\n= Jan 6, 1980 00:00 UTC ✅\n(correct GPS epoch)"]
end
C -.->|"was"| G
C -.->|"now"| H
Reviews (1): Last reviewed commit: "fix: correct GPS epoch constant in forma..." | Re-trigger Greptile
What
Fixes the GPS epoch constant used by
%Gformat specifier from315993600to315964800.Why
The GPS epoch is midnight UTC on January 6, 1980, but the constant
315993600corresponds to 08:00 UTC — an 8-hour offset. This causes%Gto return a GPS week number off by one for any timestamp falling within the first 8 hours of a GPS week boundary (~4.8% of all timestamps).How
Single constant fix in
format_G(Generic.pm line 235). The existing test data happened to avoid week boundaries, so the bug was invisible.Testing
t/gps-week.twith boundary tests (epoch start, week 0→1 transition, recent dates)🤖 Generated with Claude Code
Quality Report
Changes: 2 files changed, 38 insertions(+), 1 deletion(-)
Code scan: clean
Tests: skipped
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline