GNU bug report logs - #11098
date --yesterday wrong result

Previous Next

Package: coreutils;

Reported by: Hugo Guérineau <hugo.guerineau <at> wwsight.com>

Date: Mon, 26 Mar 2012 16:43:01 UTC

Severity: normal

Tags: notabug

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

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

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Hugo Guérineau <hugo.guerineau <at> wwsight.com>
Subject: bug#11098: closed (Re: bug#11098: date --yesterday wrong result)
Date: Mon, 26 Mar 2012 18:04:03 +0000
[Message part 1 (text/plain, inline)]
Your bug report

#11098: date --yesterday wrong result

which was filed against the coreutils package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to 11098 <at> debbugs.gnu.org.

-- 
11098: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=11098
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: Eric Blake <eblake <at> redhat.com>
To: Hugo Guérineau <hugo.guerineau <at> wwsight.com>
Cc: 11098-done <at> debbugs.gnu.org
Subject: Re: bug#11098: date --yesterday wrong result
Date: Mon, 26 Mar 2012 11:31:57 -0600
[Message part 3 (text/plain, inline)]
tag 11098 notabug
thanks

On 03/26/2012 05:31 AM, Hugo Guérineau wrote:
> Dear Mister, Madam,
> 
> I'm writing to report a date computation problem.
> 
> The command "date --date='yesterday' +%Y-%m-%d" launched this morning
> between 0:00 am and 0:59 am gives the wrong result:
> 
> root <at> serveur:> date --date='today' +%Y-%m-%d; date --date='yesterday'
> +%Y-%m-%d
> 2012-03-26
> 2012-03-24
> 
> This is caused by the system clock changes which happened last night.

Thanks for the report.  However, this is not a bug in date, but in your
expectations.  'yesterday' translates to '24 hours ago', and due to your
daylight savings swap, 24 hours ago really does put you into a different
date.  As recommended in our FAQ,

https://www.gnu.org/software/coreutils/faq/#The-date-command-is-not-working-right_002e

it's almost always better to base relative time computations off of noon
rather than midnight (as both 11 am and 1 pm fall in the same day, even
when your multiple-of-24-hours crosses a 23-hour or 25-hour day).

-- 
Eric Blake   eblake <at> redhat.com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

[signature.asc (application/pgp-signature, attachment)]
[Message part 5 (message/rfc822, inline)]
From: Hugo Guérineau <hugo.guerineau <at> wwsight.com>
To: bug-coreutils <at> gnu.org
Subject: date --yesterday wrong result
Date: Mon, 26 Mar 2012 13:31:00 +0200
[Message part 6 (text/plain, inline)]
Dear Mister, Madam,

I'm writing to report a date computation problem.

The command "date --date='yesterday' +%Y-%m-%d" launched this morning
between 0:00 am and 0:59 am gives the wrong result:

root <at> serveur:> date --date='today' +%Y-%m-%d; date --date='yesterday'
+%Y-%m-%d
2012-03-26
2012-03-24

This is caused by the system clock changes which happened last night. If we
run the command with full date display format, we can see that UTC+0100
have switch to UTC+0200:

root <at> serveur:> date --date='today'; date --date='yesterday'
lundi 26 mars 2012, 00:27:43 (UTC+0200)
samedi 24 mars 2012, 23:27:43 (UTC+0100)

Without any reference to UTC, "yesterday" means "the day before" and not
"now minus 24 hours". That's the reason why results are good in the full
display format and wrong when we are only displaying the day.

I hope this report will be usefull and want to thank you for any feedback
you could give me about it.

Yours faithfully,

Hugo Guérineau
Expert Génie Logiciel
tel: 06.50.88.43.47
hugo.guerineau <at> wwsight.com
[Message part 7 (text/html, inline)]

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

Previous Next


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