GNU bug report logs -
#11125
date command calculations are not consistent
Previous Next
Full log
View this message in rfc822 format
[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.