Opened 2 months ago

Closed 2 months ago

Last modified 2 months ago

#19047 closed bug (fixed)

gmtime_r sets the tm_zone field to a wrong value

Reported by: bhaible Owned by: nobody
Priority: normal Milestone: R1/beta5
Component: System/POSIX Version: R1/beta5
Keywords: Cc:
Blocked By: Blocking:
Platform: All

Description

The gmtime_r and localtime_r functions return information about the time zone in the fields tm_gmtoff and tm_zone. For gmtime_r, this time zone should be UTC (equivalent to GMT), because POSIX https://pubs.opengroup.org/onlinepubs/9799919799/functions/gmtime.html says: "Upon successful completion, gmtime_r() shall return the address of the structure pointed to by the argument result. The structure's tm_zone member shall be set to a pointer to the string "UTC", which shall have static storage duration."

This does not work in Haiku hrev57823 (from 2024-07-15).

How to reproduce:

Time preferences > Date and Time > Time zone > Set to Germany Time.

Compile and run the attached program foo.c.

gcc -Wall foo.c
./a.out

Expected output:

tm_zone = UTC
OK

or

tm_zone = GMT
OK

Actual output:

tm_zone = GMT+1
a.out: foo.c:26:main: strcmp (result->tm_zone, "GMT") == 0 || strcmp (result->tm_zone, "UTC") == 0
Kill Thread

Attachments (1)

foo.c (862 bytes ) - added by bhaible 2 months ago.
test case foo.c

Download all attachments as: .zip

Change History (6)

by bhaible, 2 months ago

Attachment: foo.c added

test case foo.c

comment:1 by waddlesplash, 2 months ago

Milestone: UnscheduledR1/beta5
Resolution: fixed
Status: newclosed

Fixed in hrev58061 +beta5.

comment:2 by bhaible, 2 months ago

Does your fix also work when the user is in London time zone, i.e. currently British Summer Time?

In other words, can the line

	if (tmOut->tm_gmtoff == -*fDataBridge->addrOfTimezone) {

correctly distinguish GMT (= UTC) and the London time zone, which has GMT offset 0 in the winter and 1 in the DST period (March to October)?

comment:3 by waddlesplash, 2 months ago

My current timezone is a DST one, and this worked on my system. It appears that the timezone offset will be the DST timezone offset in this case, and *addrOfDaylight will then be 1.

comment:4 by bhaible, 2 months ago

It appears that the timezone offset will be the DST timezone offset in this case, and *addrOfDaylight will then be 1.

Well, then you have a bug in the Azores Summer Time.

Look at https://www.timeanddate.com/time/zone/uk/edinburgh https://www.timeanddate.com/time/zone/portugal/ponta-delgada-azores compared to https://www.timeanddate.com/time/zone/timezone/utc

comment:5 by waddlesplash, 2 months ago

Indeed so, fixed that in hrev58062.

Note: See TracTickets for help on using tickets.