[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: problem with mktime
From: |
Bob Proulx |
Subject: |
Re: problem with mktime |
Date: |
Mon, 21 Jun 2010 16:48:45 -0600 |
User-agent: |
Mutt/1.5.18 (2008-05-17) |
Petko Bogdanov wrote:
> The problem is with the function mktime
> to reproduce:
> gawk 'BEGIN{print mktime("2008 03 09 02 37 43")}'
> outputs -1
> although the date format specification is correct
Thanks for the report. But I think this is a misunderstanding of DST
and not actually a bug in gawk. Since you did not mention timezones
and daylight savings time I assume that you were not aware that your
timezone may have daylight savings time active and that some
timestamps may not actually exist because of jumps due to daylight
savings time. Worse some times may exist twice due to the reverse
jump. And of course in the US this is done by Act of Congress and is
quite difficult for individuals to affect.
What is your timezone? In my US/Mountain timezone that is an invalid
date. This can be checked with date.
$ date -d '2008-03-09 02:37:43'
date: invalid date `2008-03-09 02:37:43'
The times when DST becomes effective can be displayed using zdump.
$ zdump -v US/Mountain | grep 2008
US/Mountain Sun Mar 9 08:59:59 2008 UTC = Sun Mar 9 01:59:59 2008 MST
isdst=0 gmtoff=-25200
US/Mountain Sun Mar 9 09:00:00 2008 UTC = Sun Mar 9 03:00:00 2008 MDT
isdst=1 gmtoff=-21600
At 01:59:59 the next second in time is 03:00:00 and there isn't any
valid time 2008-03-09 02:37:43 in that timezone. I assume that this
is what you are experiencing.
UTC is a good timezone to use to avoid all DST issues.
> changing the month to 04 results in a valid timestamp
Of course there wasn't a time change due to DST in the next month so
changing to 04 (April) avoids the gap.
This FAQ is for the date command but seems to apply here too.
http://www.gnu.org/software/coreutils/faq/#The-date-command-is-not-working-right_002e
Hope this helps!
Bob