[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: date-command
From: |
Bob Proulx |
Subject: |
Re: date-command |
Date: |
Sat, 31 May 2008 14:36:58 -0600 |
User-agent: |
Mutt/1.5.13 (2006-08-11) |
address@hidden wrote:
> I´m running coreutils 6.9.92.4-f088d-dirty (dirty??),
"dirty" means that you are running from a git version control system
checkout of the code with uncommitted changes and not from an official
upstream distribution image. That is okay.
> and I found a bug. I´m using the function of asking for a date some
> month ago. For example date --date="-2 month" +%Y%m%d. And when
> doing that on the first o june 01:00, I got the answer march 31,
> instead of April 1.
This is a known limitation. The date processing code was incorporated
from a best-effort module that isn't 100% precise. Months are fuzzy
quantities that vary in duration. The operation of the plus and minus
month adjustments is to add or subtract a month's worth of days.
However this may land the result on an invalid date or on a date that
isn't into the previous month.
See the Coreutils documentation section "Relative items in date
strings" where this is described in more detail. Expecially this
section:
The fuzz in units can cause problems with relative items. For
example, `2003-07-31 -1 month' might evaluate to 2003-07-01, because
2003-06-31 is an invalid date. To determine the previous month more
reliably, you can ask for the month before the 15th of the current
month. For example:
$ date -R
Thu, 31 Jul 2003 13:02:39 -0700
$ date --date='-1 month' +'Last month was %B?'
Last month was July?
$ date --date="$(date +%Y-%m-15) -1 month" +'Last month was %B!'
Last month was June!
> It doesn´t count a number of month backwords. But a number of days,
> not calculating correctly how many days the different days have.
That is correct. The recommended proceedure is to do month
calculations based upon the middle of the month. Normally I first get
the time once with date and then use it as a reference time thereafter
so as to avoid issues with crossing midnight on a month boundary.
> This is my first bug-report, so I hope I reported in a good manner.
Your report was great!
Bob
- date-command, Anders.Persson, 2008/05/31
- Re: date-command,
Bob Proulx <=