GNU bug report logs - #16606
date command throws error when DST is turned on

Previous Next

Package: coreutils;

Reported by: "Lakshmi Ramamurthi -X (lramamur - HCL TECHNOLOGIES LIMITED at Cisco)" <lramamur <at> cisco.com>

Date: Fri, 31 Jan 2014 06:23:01 UTC

Severity: normal

Tags: notabug

Done: Bob Proulx <bob <at> proulx.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 16606 in the body.
You can then email your comments to 16606 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-coreutils <at> gnu.org:
bug#16606; Package coreutils. (Fri, 31 Jan 2014 06:23:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to "Lakshmi Ramamurthi -X (lramamur - HCL TECHNOLOGIES LIMITED at Cisco)" <lramamur <at> cisco.com>:
New bug report received and forwarded. Copy sent to bug-coreutils <at> gnu.org. (Fri, 31 Jan 2014 06:23:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: "Lakshmi Ramamurthi -X (lramamur - HCL TECHNOLOGIES LIMITED at Cisco)"
 <lramamur <at> cisco.com>
To: "bug-coreutils <at> gnu.org" <bug-coreutils <at> gnu.org>
Subject: date command throws error when DST is turned on
Date: Fri, 31 Jan 2014 06:10:36 +0000
[Message part 1 (text/plain, inline)]
Hi,

The date command throws error when the DST is turned on.

# date +%s -d "2013/11/20"
1384912800
# date +%s -d "2013/10/20"
date: invalid date `2013/10/20'

1 sec after Oct 19 23:59:59 2013 becomes Oct 20 01:00:00 2013
As there is no 0th hour on Oct 20, it shows invalid date.

Are there any options to fix this problems ?
Has there been a patch posted for this.


#date
Sun Mar 10 07:02:07 BRT 2013

# zdump -v /etc/localtime | grep 2013
/etc/localtime Sun Feb 17 01:59:59 2013 UTC = Sat Feb 16 23:59:59 2013 BRST isdst=1 gmtoff=-7200
/etc/localtime Sun Feb 17 02:00:00 2013 UTC = Sat Feb 16 23:00:00 2013 BRT isdst=0 gmtoff=-10800
/etc/localtime Sun Oct 20 02:59:59 2013 UTC = Sat Oct 19 23:59:59 2013 BRT isdst=0 gmtoff=-10800
/etc/localtime Sun Oct 20 03:00:00 2013 UTC = Sun Oct 20 01:00:00 2013 BRST isdst=1 gmtoff=-7200

Thanks,
Lakshmi
[Message part 2 (text/html, inline)]

Information forwarded to bug-coreutils <at> gnu.org:
bug#16606; Package coreutils. (Fri, 31 Jan 2014 07:18:02 GMT) Full text and rfc822 format available.

Message #8 received at 16606 <at> debbugs.gnu.org (full text, mbox):

From: Bob Proulx <bob <at> proulx.com>
To: "Lakshmi Ramamurthi -X (lramamur - HCL TECHNOLOGIES LIMITED at Cisco)"
 <lramamur <at> cisco.com>
Cc: 16606 <at> debbugs.gnu.org
Subject: Re: bug#16606: date command throws error when DST is turned on
Date: Fri, 31 Jan 2014 00:17:19 -0700
tag 16606 +notabug
close 16606
thanks

Lakshmi Ramamurthi -X (lramamur - HCL TECHNOLOGIES LIMITED at Cisco) wrote:
> The date command throws error when the DST is turned on.
> 
> # date +%s -d "2013/11/20"
> 1384912800
> # date +%s -d "2013/10/20"
> date: invalid date `2013/10/20'
>
> 1 sec after Oct 19 23:59:59 2013 becomes Oct 20 01:00:00 2013
> As there is no 0th hour on Oct 20, it shows invalid date.

You are completely correct that there is no midnight in your timezone
and therefore the date you are requesting *in your timezone* does not
exist and therefore it is an invalid date.  The date command is
working correctly in reporting it as an invalid date.  I will
emphasize that this is timezone specific behavior.

> Are there any options to fix this problems ?
> Has there been a patch posted for this.

The option to fix this is the -u option to select UTC.  No patches are
needed.

The best choice is to work with dates in the UTC timezone which avoids
all DST issues since UTC never changes and never skips seconds.  The
second best choice is to work with times around noon which avoids DST
time changes that usually happen at night.  These hints are discussed
in the FAQ entry in more detail.

You didn't say what specific timezone you were concerned with so I
will pick one at random for an example.

  $ env TZ=America/Sao_Paulo date -R -d "2013/10/20"
  date: invalid date ‘2013/10/20’

That date at midnight does not exist in that timezone.

  $ env TZ=America/Sao_Paulo date -R -d "2013/10/20 12:00"
  Sun, 20 Oct 2013 12:00:00 -0200

Using 12:00 noon avoids the skipped interval.

  $ date -u -R -d "2013/10/20"
  Sun, 20 Oct 2013 00:00:00 +0000

Using UTC avoids the problem because UTC doesn't skip intervals for
DST.  I also didn't show setting a default timezone (TZ) because that
is also not matter when using UTC.  It is just simpler all around.

Please see the FAQ entry where this is explained in detail.

  http://www.gnu.org/software/coreutils/faq/coreutils-faq.html#The-date-command-is-not-working-right_002e

Bob




bug closed, send any further explanations to 16606 <at> debbugs.gnu.org and "Lakshmi Ramamurthi -X (lramamur - HCL TECHNOLOGIES LIMITED at Cisco)" <lramamur <at> cisco.com> Request was from Bob Proulx <bob <at> proulx.com> to control <at> debbugs.gnu.org. (Fri, 31 Jan 2014 07:18:03 GMT) Full text and rfc822 format available.

Added tag(s) notabug. Request was from Bob Proulx <bob <at> proulx.com> to control <at> debbugs.gnu.org. (Fri, 31 Jan 2014 07:33:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-coreutils <at> gnu.org:
bug#16606; Package coreutils. (Fri, 31 Jan 2014 07:57:01 GMT) Full text and rfc822 format available.

Message #15 received at 16606 <at> debbugs.gnu.org (full text, mbox):

From: "Lakshmi Ramamurthi -X (lramamur - HCL TECHNOLOGIES LIMITED at Cisco)"
 <lramamur <at> cisco.com>
To: Bob Proulx <bob <at> proulx.com>
Cc: "16606 <at> debbugs.gnu.org" <16606 <at> debbugs.gnu.org>
Subject: RE: bug#16606: date command throws error when DST is turned on
Date: Fri, 31 Jan 2014 07:56:35 +0000
Thanks a lot for your quick reply.

-Lakshmi

-----Original Message-----
From: Bob Proulx [mailto:bob <at> proulx.com] 
Sent: Friday, January 31, 2014 12:47 PM
To: Lakshmi Ramamurthi -X (lramamur - HCL TECHNOLOGIES LIMITED at Cisco)
Cc: 16606 <at> debbugs.gnu.org
Subject: Re: bug#16606: date command throws error when DST is turned on

tag 16606 +notabug
close 16606
thanks

Lakshmi Ramamurthi -X (lramamur - HCL TECHNOLOGIES LIMITED at Cisco) wrote:
> The date command throws error when the DST is turned on.
> 
> # date +%s -d "2013/11/20"
> 1384912800
> # date +%s -d "2013/10/20"
> date: invalid date `2013/10/20'
>
> 1 sec after Oct 19 23:59:59 2013 becomes Oct 20 01:00:00 2013 As there 
> is no 0th hour on Oct 20, it shows invalid date.

You are completely correct that there is no midnight in your timezone and therefore the date you are requesting *in your timezone* does not exist and therefore it is an invalid date.  The date command is working correctly in reporting it as an invalid date.  I will emphasize that this is timezone specific behavior.

> Are there any options to fix this problems ?
> Has there been a patch posted for this.

The option to fix this is the -u option to select UTC.  No patches are needed.

The best choice is to work with dates in the UTC timezone which avoids all DST issues since UTC never changes and never skips seconds.  The second best choice is to work with times around noon which avoids DST time changes that usually happen at night.  These hints are discussed in the FAQ entry in more detail.

You didn't say what specific timezone you were concerned with so I will pick one at random for an example.

  $ env TZ=America/Sao_Paulo date -R -d "2013/10/20"
  date: invalid date ‘2013/10/20’

That date at midnight does not exist in that timezone.

  $ env TZ=America/Sao_Paulo date -R -d "2013/10/20 12:00"
  Sun, 20 Oct 2013 12:00:00 -0200

Using 12:00 noon avoids the skipped interval.

  $ date -u -R -d "2013/10/20"
  Sun, 20 Oct 2013 00:00:00 +0000

Using UTC avoids the problem because UTC doesn't skip intervals for DST.  I also didn't show setting a default timezone (TZ) because that is also not matter when using UTC.  It is just simpler all around.

Please see the FAQ entry where this is explained in detail.

  http://www.gnu.org/software/coreutils/faq/coreutils-faq.html#The-date-command-is-not-working-right_002e

Bob

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Fri, 28 Feb 2014 12:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 11 years and 117 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.