Skip to content

Refactor gmtime_r(), fix localtime() test

This is a refactor of gmtime_r() for the purpose of getting that function to run in O(1) time. While this MR kind of reverts eb6ddac1, it should be noted that it is now simpler to implement the relevant algorithm as Rust has stabilized Euclidean division since then. Also, the output has been validated against glibc output with the extra tests in !308 (merged).

The function should now generate correct output as long as the year will fit in a c_int (assuming 64-bit time_t).

Surprisingly, the refactored version broke the localtime() test, which of course warrants investigation. Looking into it, the refactored version is in agreement with glibc (with gmtime substituted for localtime), and the old output cannot possibly be true - a zero-based .tm_yday cannot be 365 in the non-leap year 1969. Thus, the expected test output has been fixed.

Merge request reports