[patch] Fix libfortran/98507, handling of timezone near year boundaries

FX fxcoudert@gmail.com
Thu Dec 16 14:17:08 GMT 2021


Hi,

DATE_AND_TIME can return incorrect values for non-UTC timezones, near the new year, when the local time and UTC time are in different years. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98507

Attached patch fixes the issue by correcting the logic to account for that wrapping of “day of the year” around new year. I include a testcase, which checks the sanity of values returned by DATE_AND_TIME. Since the bug only occurs for a few hours every year, and depends on local timezone, I could not think of a better (systematic) test.

I also want to propose (it’s not directly needed to fix the bug) that we switch our time routines to rely on clock_gettime() instead of gettimeofday(), when available. This is in line with POSIX.1-2008, which marks gettimeofday() as obsolete, recommending the use of 
clock_gettime() instead.

Bootstrapped and regtested on x86_64-pc-linux-gnu.
OK to commit?

FX


-------------- next part --------------
A non-text attachment was scrubbed...
Name: pr98507.patch
Type: application/octet-stream
Size: 4520 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/fortran/attachments/20211216/d52d694e/attachment.obj>


More information about the Fortran mailing list