bug-coreutils
[Top][All Lists]
Advanced

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

Re: bug in daylight-saving?


From: Bob Proulx
Subject: Re: bug in daylight-saving?
Date: Tue, 29 Mar 2005 10:26:04 -0700
User-agent: Mutt/1.5.6+20040907i

Andreas Schwab wrote:
> Pavel Riha <address@hidden> writes:
> 
> > #info date
> >>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 following text also appears in the date manual immediately after
the above text.

       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!

       Also, take care when manipulating dates around clock changes such as
    daylight saving leaps.  In a few cases these have added or subtracted
    as much as 24 hours from the clock, so it is often wise to adopt
    universal time by setting the `TZ' environment variable to `UTC0'
    before embarking on calendrical calculations.

> > I use `date -d yesterday +%F` in my shell script to obtain the day of
> > yesterday. The script is run in 0:00 every day for backup logs.
> >
> > today (2005-03-28 0:00) there was a problem, that it returned 2005-03-26 !
> > instead of 2005-03-27
> >
> > I think, it is because of the time change (27.3. was the daylight-saving
> > day).
> >
> > according to the info page (see above), it should be bug.

> "date -d yesterday" is the same as "date -d '24 hours ago'", thus since
> the day before 2005-03-28 had only 23 hours this is perfectly reasonable.
> To avoid any problems with DST use something like "date -d '12:00 yesterday'".

Agreed.

I am thinking that the reasoning given for determining the last month
might be applied as well to determining the last day.

  date -d "$(date +'%F 12:00') 24 hours ago" '+%F'

Bob




reply via email to

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