Skip to content

Conversation

@krixkrix
Copy link

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:

Input: UTC components (e.g., 15:24:29 UTC from "2025-10-01T15:24:29Z")
mktime() treats as local: 15:24:29 local time
mktime() converts to UTC: 15:24:29 - 2 hours = 13:24:29 UTC
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

@alexanderoster
Copy link
Owner

Wow, how did you find that?

@alexanderoster alexanderoster merged commit 3a0e7b6 into alexanderoster:develop Oct 24, 2025
1 check passed
@krixkrix
Copy link
Author

Wow, how did you find that?

even a blind squirrel finds a nut...

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