public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/17443] New: timegm appears broken when DST is in effect
@ 2014-09-28 19:17 esr at thyrsus dot com
  2014-09-29 20:10 ` [Bug libc/17443] " esr at thyrsus dot com
  0 siblings, 1 reply; 2+ messages in thread
From: esr at thyrsus dot com @ 2014-09-28 19:17 UTC (permalink / raw)
  To: glibc-bugs

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.


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug libc/17443] timegm appears broken when DST is in effect
  2014-09-28 19:17 [Bug libc/17443] New: timegm appears broken when DST is in effect esr at thyrsus dot com
@ 2014-09-29 20:10 ` esr at thyrsus dot com
  0 siblings, 0 replies; 2+ messages in thread
From: esr at thyrsus dot com @ 2014-09-29 20:10 UTC (permalink / raw)
  To: glibc-bugs

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

Eric S. Raymond <esr at thyrsus dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |INVALID

--- Comment #1 from Eric S. Raymond <esr at thyrsus dot com> ---
Bug report withdrawn.  Some reviewers pointed out that my test program tripped
over an obscure side effect of mktime(3).

Now I have a goal to write better documentation so nobody trips over thus
again.

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-09-29 20:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-28 19:17 [Bug libc/17443] New: timegm appears broken when DST is in effect esr at thyrsus dot com
2014-09-29 20:10 ` [Bug libc/17443] " esr at thyrsus dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).