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

Re: date bug?



On Mon, 31 May 2010 17:34:12 +0000, T o n g wrote:

> Please take a look at the following, do you think it is bug of date?

(...)

> $ date --date='next month'
> Thu Jul  1 11:07:31 EDT 2010
> 
> I was hoping to get June.

But June has not "31 days" so the closest is indeed "1st July" ;-)
 
> Is it a bug, or there are other ways to get the correct answer?

It's a "feature" when playing with relative time :-)

***
info date (Relative items in date strings)

(...)

When a relative item causes the resulting date to cross a boundary
where the clocks were adjusted, typically for daylight saving time, the
resulting date and time are adjusted accordingly.

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:
***

Greetings,

-- 
Camaleón


Reply to: