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.

Full log


Message #10 received at control <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




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

Previous Next


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