Skip to content

fix: correct GPS epoch constant in format_G (%G)#109

Merged
atoomic merged 2 commits into
cpan-authors:mainfrom
Koan-Bot:koan.atoomic/fix-gps-epoch-constant
Apr 26, 2026
Merged

fix: correct GPS epoch constant in format_G (%G)#109
atoomic merged 2 commits into
cpan-authors:mainfrom
Koan-Bot:koan.atoomic/fix-gps-epoch-constant

Conversation

@Koan-Bot
Copy link
Copy Markdown

@Koan-Bot Koan-Bot commented Apr 13, 2026

What

Fixes the GPS epoch constant used by %G format specifier from 315993600 to 315964800.

Why

The GPS epoch is midnight UTC on January 6, 1980, but the constant 315993600 corresponds to 08:00 UTC — an 8-hour offset. This causes %G to 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

  • New t/gps-week.t with boundary tests (epoch start, week 0→1 transition, recent dates)
  • First commit adds failing tests, second commit fixes them
  • Full test suite passes

🤖 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

Koan-Bot and others added 2 commits April 12, 2026 23:36
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>
@atoomic atoomic marked this pull request as ready for review April 26, 2026 12:49
@atoomic atoomic merged commit cf36006 into cpan-authors:main Apr 26, 2026
22 checks passed
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Apr 26, 2026

Greptile Summary

This PR fixes a long-standing off-by-one bug in the %G GPS week format specifier caused by an epoch constant that was 8 hours too late (315993600 = 08:00 UTC Jan 6, 1980 instead of 315964800 = midnight UTC Jan 6, 1980). The single-line fix is mathematically correct, and the new test file covers epoch identity, the week 0→1 boundary transition, a known historical reference point, and a recent-date sanity check — all verified independently.

Confidence Score: 5/5

Safe 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

Important Files Changed

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
Loading

Reviews (1): Last reviewed commit: "fix: correct GPS epoch constant in forma..." | Re-trigger Greptile

@Koan-Bot Koan-Bot deleted the koan.atoomic/fix-gps-epoch-constant branch April 27, 2026 09:14
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.

2 participants