This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libc/17443] New: timegm appears broken when DST is in effect


https://sourceware.org/bugzilla/show_bug.cgi?id=17443

            Bug ID: 17443
           Summary: timegm appears broken when DST is in effect
           Product: glibc
           Version: 2.19
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
          Assignee: unassigned at sourceware dot org
          Reporter: esr at thyrsus dot com
                CC: drepper.fsp at gmail dot com

Created attachment 7812
  --> https://sourceware.org/bugzilla/attachment.cgi?id=7812&action=edit
Test program illustrating apparent bug in timegm().

Build the enclosed test program timetest.c as timetest and run

TZ='America/New_York' timetest 1411929303

You should observe the following output:

----------------------------------------------------------------
TZ = America/New_York

using 1411929303
Unix time:   1411929303
localtime:   {S=3,M=35,H=14,d=28,m=8,y=114,a=0,isdst=1,gmt_off=-14400,zone=EDT}
gmtime:      {S=3,M=35,H=18,d=28,m=8,y=114,a=0,isdst=0,gmt_off=0,zone=GMT}
UTC time:    2014-09-28T18:35:03Z
Local time:  2014-09-28T14:35:03
RFC822 time: Sun, 28 Sep 2014 14:35:03 -0400
Zone offset: 18000 (5h 0m 0s)
Zone name:   EST

Assertions passed.

mktime() - now:    0
timegm() - now:    3600
--------------------------------------------------------------------

The TZ and Unix seconds value are chosen so DST is in effect, as shown by
isdst=1 in the structure dump. 

The "Assertions passed" part means that two alternative and different methods
of inverting gmtime() work, producing a zero residual with the input value. 

Also, inverting localtime() with mktime() works (second to last time).

Only timegm() fails.  The 3600 difference suggests that the problem is due to
failure to offset by the DST hour.

One of the alternative methods is:

----------------------------------------------------------

time_t mkgmtime(struct tm *tm)
{
    return mktime(tm) - timezone;
}

------------------------------------------------------------

If this is not both correct and an improvement over the complicated
implementation of glibc, I'd like to know why.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]