GNU bug report logs - #11125
date command calculations are not consistent

Previous Next

Package: coreutils;

Reported by: "Thomas R. Schaefer" <schaefert <at> yahoo.com>

Date: Thu, 29 Mar 2012 18:21:01 UTC

Severity: normal

Tags: notabug

Merged with 11098, 11101, 15785, 18159, 18479, 20523

Done: Assaf Gordon <assafgordon <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


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

From: "Thomas R. Schaefer" <schaefert <at> yahoo.com>
To: bug-coreutils <at> gnu.org
Subject: date command calculations are not consistent
Date: Thu, 29 Mar 2012 10:43:39 -0700 (PDT)
[Message part 1 (text/plain, inline)]
Discovered this when I script I have cronned to run at 12:01AM gave some unexpected results.

After much picking at it I finally figured out that the date command itself was the source of my problem.  It isn't handling date calculations that span the daylight savings time change consistently..

[schaefer <at> fedora14 ~]$ date --version
date (GNU coreutils) 8.5
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by David MacKenzie.
[schaefer <at> fedora14 ~]$ date -d "last Thursday"
Thu Mar 22 00:00:00 CDT 2012
[schaefer <at> fedora14 ~]$ date -d "Thu Mar 22 00:00:00 CDT 2012"
Thu Mar 22 00:00:00 CDT 2012
[schaefer <at> fedora14 ~]$ date -d "last Thursday - 21 days"
Thu Mar  1 00:00:00 CST 2012
[schaefer <at> fedora14 ~]$ date -d "Thu Mar 22 00:00:00 CDT 2012 - 21 days"
Wed Feb 29 23:00:00 CST 2012

In my real world case I was running a script at 12:01AM on Sundays that did this..

RSD="$(date +%F -d "today - 35  days")" # Report Start Date

RSD was getting set to a Saturday date but ordinarily, when a DST change hasn't occurred in the past 35 days, it would be set to a Sunday date.  I expect and want the Sunday date regardless; although I realize an argument could be made for the correctness of the Saturday date too.  However the date command is going to make a calculation like that it should be consistent with its own self which if you look closely at my examples above regarding last Thursday you will see it is not consistent with itself.

Thank you,
Tom Schaefer


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

This bug report was last modified 6 years and 210 days ago.

Previous Next


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