bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#16606: date command throws error when DST is turned on


From: Bob Proulx
Subject: bug#16606: date command throws error when DST is turned on
Date: Fri, 31 Jan 2014 00:17:19 -0700
User-agent: Mutt/1.5.21 (2010-09-15)

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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]