localtime() changes tzname

Bug #513874 reported by Alberto Bertogli
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
eglibc (Ubuntu)
New
Undecided
Unassigned

Bug Description

Release: 9.10
Version: libc6 2.10.1-0ubuntu16

The following testcase (also attached):

#include <stdio.h>
#include <time.h>
#include <locale.h>

int main(void)
{
        time_t t;

        tzset();
        printf("tzname: (%s,%s) timezone: %ld daylight:%d\n",
                        tzname[0], tzname[1], timezone, daylight);
        time(&t);
        localtime(&t);
        printf("tzname: (%s,%s) timezone: %ld daylight:%d\n",
                        tzname[0], tzname[1], timezone, daylight);

        return 0;
}

Outputs the following:

    tzname: (ART,ARST) timezone: 10800 daylight:1
    tzname: (ART,ART) timezone: 10800 daylight:0

I think it should output the same tzname twice, but as shown fails to do so when using
Argentina/Buenos Aires timezone.

The timezone has the peculiarity that some years we have DST and some years we don't.
This year we don't. I don't know if it happens with other timezones.

If tzset() is called again after localtime() it does not change the tzname anymore.

As an example of the consequences of this behaviour, this breaks applications that need
to know the names of the local time zone in order to parse them from an external source.

After reading http://www.opengroup.org/onlinepubs/9699919799/functions/tzset.html and
http://www.opengroup.org/onlinepubs/9699919799/functions/localtime.html, I think the
correct output would be:

    tzname: (ART,ARST) timezone: 10800 daylight:1
    tzname: (ART,ARST) timezone: 10800 daylight:1

because even though there is no DST to be applied currently, there is a name for the
alternative DST timezone, and at some point DST could be applied.

If there is anything else I can do to get this bug fixed, please let me know.

Thanks a lot,
    Alberto

Revision history for this message
Alberto Bertogli (albertito) wrote :
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Bug attachments

Remote bug watches

Bug watches keep track of this bug in other bug trackers.