Skip to content

Conversation

@krixkrix
Copy link
Owner

Fixes a timezone conversion bug in getMicrosecondsSince1970FromDay():

ISO 8601 UTC timestamps would be incorrectly converted when parsed and re-serialized.

This issue surfaces in the scenario:

parseISO8601TimeUTC()
-> calls getMicrosecondsSince1970FromDateTime()
-> calls getMicrosecondsSince1970FromDay()

std::mktime() interprets the tm structure as LOCAL TIME and converts it to UTC, but the function receives date/time components that are already in UTC (parsed from ISO 8601 strings with 'Z' suffix).

This causes a double conversion:

  1. Input: UTC components (e.g., 15:24:29 UTC from "2025-10-01T15:24:29Z")
  2. mktime() treats as local: 15:24:29 local time
  3. mktime() converts to UTC: 15:24:29 - 2 hours = 13:24:29 UTC
  4. Result: Wrong by timezone offset!

I have added unit tests that demonstrate the issue.
4 "chrono" tests will fail without the fix.

With the fix:

92 | Chrono | ISO8601RoundTrip [ SUCCESS ]
93 | Chrono | LeapYear [ SUCCESS ]
94 | Chrono | MidnightBoundary [ SUCCESS ]
95 | Chrono | TimezoneIndependence [ SUCCESS ]

The fix aims to be valid also on windows, but this is not tested

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