From unknown Sat Jun 21 03:29:26 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#11125 <11125@debbugs.gnu.org> To: bug#11125 <11125@debbugs.gnu.org> Subject: Status: date command calculations are not consistent Reply-To: bug#11125 <11125@debbugs.gnu.org> Date: Sat, 21 Jun 2025 10:29:26 +0000 retitle 11125 date command calculations are not consistent reassign 11125 coreutils submitter 11125 "Thomas R. Schaefer" severity 11125 normal tag 11125 notabug thanks From debbugs-submit-bounces@debbugs.gnu.org Thu Mar 29 14:20:28 2012 Received: (at submit) by debbugs.gnu.org; 29 Mar 2012 18:20:28 +0000 Received: from localhost ([127.0.0.1]:45190 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SDJxU-0001Si-5S for submit@debbugs.gnu.org; Thu, 29 Mar 2012 14:20:28 -0400 Received: from eggs.gnu.org ([208.118.235.92]:33540) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SDJtx-0001MG-RP for submit@debbugs.gnu.org; Thu, 29 Mar 2012 14:17:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SDJPQ-0000Fl-Qx for submit@debbugs.gnu.org; Thu, 29 Mar 2012 13:45:21 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.2 Received: from lists.gnu.org ([208.118.235.17]:47127) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SDJPQ-0000F9-LB for submit@debbugs.gnu.org; Thu, 29 Mar 2012 13:45:16 -0400 Received: from eggs.gnu.org ([208.118.235.92]:52518) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SDJO0-0005v0-3w for bug-coreutils@gnu.org; Thu, 29 Mar 2012 13:43:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SDJNu-00083U-UW for bug-coreutils@gnu.org; Thu, 29 Mar 2012 13:43:47 -0400 Received: from nm9.bullet.mail.ne1.yahoo.com ([98.138.90.72]:21110) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1SDJNu-00083A-KY for bug-coreutils@gnu.org; Thu, 29 Mar 2012 13:43:42 -0400 Received: from [98.138.90.55] by nm9.bullet.mail.ne1.yahoo.com with NNFMP; 29 Mar 2012 17:43:40 -0000 Received: from [68.142.200.227] by tm8.bullet.mail.ne1.yahoo.com with NNFMP; 29 Mar 2012 17:43:40 -0000 Received: from [66.94.237.108] by t8.bullet.mud.yahoo.com with NNFMP; 29 Mar 2012 17:43:40 -0000 Received: from [127.0.0.1] by omp1013.access.mail.mud.yahoo.com with NNFMP; 29 Mar 2012 17:43:40 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 225444.97597.bm@omp1013.access.mail.mud.yahoo.com Received: (qmail 34550 invoked by uid 60001); 29 Mar 2012 17:43:40 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1333043020; bh=eJA1L96hmy1lNIOxE9WQAsUisB563kOTyR443dcBDEU=; h=X-YMail-OSG:Received:X-Mailer:Message-ID:Date:From:Subject:To:MIME-Version:Content-Type; b=Qks7MDIitG9vKPnnr/AEEvkY9vUukjXHhRxUxVRNGYtvvDPMdwkvTSq4qc+oFcS9rFNdWxpQspWfNCzWE6+Q9WhHESvt8x/IkckWaI/LsReSSlAVbUO5S10SZWSTh2nWg6BwCxPHmt25yIPBnT+2YMVqLFqOyGtSmdPekC9IbiA= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:X-Mailer:Message-ID:Date:From:Subject:To:MIME-Version:Content-Type; b=DmIHXc6SVsKlz7ZgBHrc9sdIrtDnJ4c+NAP876m4vQeySo7J+V0Fe/LYyuHpITBk9QGK5AE8Z5oVafK3GJMoRCtwg2bCEUfz0S2LdSa/NEMb+m/BxQYEenou0+343eRpohFatXRoqGiJFdif/9fxH30hbnjOoAKa4gsqq156yG0=; X-YMail-OSG: zEMhguEVM1mNdwBARbzR5AzcndZcA_jrriM1qAdozNyBgFI nc5TFxCtu_ZvBxZLL9sVfkqpVpaGhNDkAaq3ZZL731dv0LrIcPRsroIgdziR jFxupO93XF0xJqH9CBqFJoKksppFgvQG8rrqnXFPeXCXIyiTDtvVv_1Pz9Lb C8ywIBAAU1yLxuvYVBL2VPpKMZTfouLZYSUom8N6p30ZP2S98_DO_03EeGqU Zr10S1m12ksqySfE4_Td53EJSzb8ycUrUTsgG8FjqUBTUtfPuYr2qfV2m5uF vbKiN2W2VsGU0eBu2rIAQHf0naq9OWqLj2LXPyEZ5E7.K4SY9m926ChVzMEP lbR5f8A0jfilavPYGZfseA5.sagU4hwsyreztQjY19BhZmQc4WqhDcip5jTj DAW2Izx7YcsSk4U.yPzSv.Y1QZHH1NZjQ0IkyEUtgccvYoLJh_n4iMtmrQTb tC0cjoYmkWGdzLkr_7TFoJZAb2VGxdW9EYqDmgY8JWdt2nHUDP7u8n6YG18T pKG9kofKI Received: from [208.82.145.150] by web80606.mail.mud.yahoo.com via HTTP; Thu, 29 Mar 2012 10:43:39 PDT X-Mailer: YahooMailClassic/15.0.5 YahooMailWebService/0.8.117.340979 Message-ID: <1333043019.33056.YahooMailClassic@web80606.mail.mud.yahoo.com> Date: Thu, 29 Mar 2012 10:43:39 -0700 (PDT) From: "Thomas R. Schaefer" Subject: date command calculations are not consistent To: bug-coreutils@gnu.org MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="-2114655128-926695640-1333043019=:33056" X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 208.118.235.17 X-Spam-Score: -1.9 (-) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Thu, 29 Mar 2012 14:20:25 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -1.9 (-) ---2114655128-926695640-1333043019=:33056 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Discovered this when I script I have cronned to run at 12:01AM gave some un= expected results. After much picking at it I finally figured out that the date command itself= was the source of my problem.=A0 It isn't handling date calculations that = span the daylight savings time change consistently.. [schaefer@fedora14 ~]$ date --version date (GNU coreutils) 8.5 Copyright (C) 2010 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later . 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@fedora14 ~]$ date -d "last Thursday" Thu Mar 22 00:00:00 CDT 2012 [schaefer@fedora14 ~]$ date -d "Thu Mar 22 00:00:00 CDT 2012" Thu Mar 22 00:00:00 CDT 2012 [schaefer@fedora14 ~]$ date -d "last Thursday - 21 days" Thu Mar=A0 1 00:00:00 CST 2012 [schaefer@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=3D"$(date +%F -d "today - 35=A0 days")" # Report Start Date RSD was getting set to a Saturday date but ordinarily, when a DST change ha= sn't occurred in the past 35 days, it would be set to a Sunday date.=A0 I e= xpect and want the Sunday date regardless; although I realize an argument c= ould be made for the correctness of the Saturday date too.=A0 However the d= ate command is going to make a calculation like that it should be consisten= t with its own self which if you look closely at my examples above regardin= g last Thursday you will see it is not consistent with itself. Thank you, Tom Schaefer ---2114655128-926695640-1333043019=:33056 Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable
Discovered this when I script I have cronned = to run at 12:01AM gave some unexpected results.

After much picking a= t it I finally figured out that the date command itself was the source of m= y problem.  It isn't handling date calculations that span the daylight= savings time change consistently..

[schaefer@fedora14 ~]$ date --ve= rsion
date (GNU coreutils) 8.5
Copyright (C) 2010 Free Software Found= ation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.or= g/licenses/gpl.html>.
This is free software: you are free to change a= nd redistribute it.
There is NO WARRANTY, to the extent permitted by law= .

Written by David MacKenzie.
[schaefer@fedora14 ~]$ date -d "las= t Thursday"
Thu Mar 22 00:00:00 CDT 2012
[schaefer@fedora14 ~]$ date = -d "Thu Mar 22 00:00:00 CDT 2012"
Thu Mar 22 00:00:00 CDT 2012
[schaefer@fedora14 ~]$ date -d "last Thursday - 21 days"
Thu Ma= r  1 00:00:00 CST 2012
[schaefer@fedora14 ~]$ date -d "Thu Mar 22 0= 0:00:00 CDT 2012 - 21 days"
Wed Feb 29 23:00:00 CST 2012

In my re= al world case I was running a script at 12:01AM on Sundays that did this..<= br>
RSD=3D"$(date +%F -d "today - 35  days")" # Report Start Date
RSD was getting set to a Saturday date but ordinarily, when a DST cha= nge hasn't occurred in the past 35 days, it would be set to a Sunday date.&= nbsp; I expect and want the Sunday date regardless; although I realize an a= rgument could be made for the correctness of the Saturday date too.  H= owever 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 ab= ove regarding last Thursday you will see it is not consistent with itself.<= br>
Thank you,
Tom Schaefer


---2114655128-926695640-1333043019=:33056-- From debbugs-submit-bounces@debbugs.gnu.org Thu Mar 29 14:33:20 2012 Received: (at 11125) by debbugs.gnu.org; 29 Mar 2012 18:33:21 +0000 Received: from localhost ([127.0.0.1]:45214 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SDK9w-0001nR-Hw for submit@debbugs.gnu.org; Thu, 29 Mar 2012 14:33:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:30634) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SDK9t-0001nE-FW; Thu, 29 Mar 2012 14:33:18 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q2TI1mbn009956 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 29 Mar 2012 14:01:48 -0400 Received: from [10.3.113.31] (ovpn-113-31.phx2.redhat.com [10.3.113.31]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q2TI1laf018596; Thu, 29 Mar 2012 14:01:48 -0400 Message-ID: <4F74A38B.2010308@redhat.com> Date: Thu, 29 Mar 2012 12:01:47 -0600 From: Eric Blake Organization: Red Hat User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:11.0) Gecko/20120316 Thunderbird/11.0 MIME-Version: 1.0 To: "Thomas R. Schaefer" Subject: Re: bug#11125: date command calculations are not consistent References: <1333043019.33056.YahooMailClassic@web80606.mail.mud.yahoo.com> In-Reply-To: <1333043019.33056.YahooMailClassic@web80606.mail.mud.yahoo.com> X-Enigmail-Version: 1.4 OpenPGP: url=http://people.redhat.com/eblake/eblake.gpg Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="------------enig2605DFBD3A0F0033DF33C495" X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Spam-Score: -1.9 (-) X-Debbugs-Envelope-To: 11125 Cc: 11125@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -1.9 (-) This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig2605DFBD3A0F0033DF33C495 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable forcemerge 11098 11125 thanks On 03/29/2012 11:43 AM, Thomas R. Schaefer wrote: > Discovered this when I script I have cronned to run at 12:01AM gave som= e unexpected results. >=20 > After much picking at it I finally figured out that the date command it= self was the source of my problem. It isn't handling date calculations t= hat span the daylight savings time change consistently Thanks for the report. Join the club. This has been reported twice this week already, and the consensus is that date is behaving as documented (relative date operations add or subtract in multiples of 24 hours, without regards to daylight savings boundaries), but that the documented behavior could be improved if someone were to submit a patch. https://lists.gnu.org/archive/html/bug-coreutils/2012-03/msg00102.html As recommended in our FAQ, https://www.gnu.org/software/coreutils/faq/#The-date-command-is-not-worki= ng-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). In your example, change: RSD=3D"$(date +%F -d "today - 35 days")" # Report Start Date to: RSD=3D"$(date +%F -d "noon today - 35 days")" # Report Start Date --=20 Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --------------enig2605DFBD3A0F0033DF33C495 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBCAAGBQJPdKOLAAoJEKeha0olJ0NqEoEH/0ZK2M7CjjvKP6BOw9XTHRbo 0yNfpYsUju9YubFWQNFGxDpZb++O+IKBNfSPSG/yg8+/VAdZkCZWH43/r4EuxKIX 6iz05nneswvcWPyuTcQ8jq6xkdXPBO1748vzKYVLZ8nnr7NbeYi2n4AbtTZ+ghxS wjOKzeJuedbXfBXUS98RcikCk6DTGCMHk6rvAylb1hkjksCPFLl/Lo2jNJM/Qe3H wLoBH4SJsyrKoWRpo/x0ZUdV/kspxxtWyJ6LzHC0XURPM3b+UdzClNL1TlEkmCtl bc1nX8aSNQfXPehRDuUDAHQKNxaaTanGt4P7ipIIIINHBS9IozKZLyANAVCqJNA= =NW+J -----END PGP SIGNATURE----- --------------enig2605DFBD3A0F0033DF33C495-- From debbugs-submit-bounces@debbugs.gnu.org Thu Mar 29 15:05:54 2012 Received: (at 11125) by debbugs.gnu.org; 29 Mar 2012 19:05:54 +0000 Received: from localhost ([127.0.0.1]:45226 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SDKfQ-0003Nb-Mq for submit@debbugs.gnu.org; Thu, 29 Mar 2012 15:05:54 -0400 Received: from nm7-vm1.bullet.mail.ne1.yahoo.com ([98.138.90.250]:45198) by debbugs.gnu.org with smtp (Exim 4.72) (envelope-from ) id 1SDKfN-0003NT-4L for 11125@debbugs.gnu.org; Thu, 29 Mar 2012 15:05:50 -0400 Received: from [98.138.226.179] by nm7.bullet.mail.ne1.yahoo.com with NNFMP; 29 Mar 2012 18:34:20 -0000 Received: from [68.142.200.227] by tm14.bullet.mail.ne1.yahoo.com with NNFMP; 29 Mar 2012 18:34:20 -0000 Received: from [66.94.237.105] by t8.bullet.mud.yahoo.com with NNFMP; 29 Mar 2012 18:34:19 -0000 Received: from [127.0.0.1] by omp1010.access.mail.mud.yahoo.com with NNFMP; 29 Mar 2012 18:34:19 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 931277.3011.bm@omp1010.access.mail.mud.yahoo.com Received: (qmail 74170 invoked by uid 60001); 29 Mar 2012 18:34:19 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1333046059; bh=SHd2XyphezONl5EzvXxcgJyw9BABkWSTNoPNY6Uk7AQ=; h=X-YMail-OSG:Received:X-Mailer:Message-ID:Date:From:Subject:To:Cc:In-Reply-To:MIME-Version:Content-Type; b=Pp7qEQ5sarqq8311Xq4XncEDo0TdBqDRDPjXmM+90x1A7Pe8+0uZ59E6zdv+BQb7Yc1OS/bJyBYFOSe6/Sx8OnSRttL1l92XVW3MiyE+1ECKRqVODAaBqYvKFwYzd3FeknhknYtOyWYtr7TvjARcB1waC2wEan+293xtbDrTOgs= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:X-Mailer:Message-ID:Date:From:Subject:To:Cc:In-Reply-To:MIME-Version:Content-Type; b=vToFZ7qbgNU8M+tFBnn+DsQdwKUXXawIEFYPMtzDjNCmsuhDJb4lGdITmkXnx4z7VT8hA4qRvCZU4Bp6GZJQ9nIY0d42MibvseR+b36p9GIRwa208U7/4hEmZeRJYHJpABJeizFEd6d/MdD1PvFR0moOWxs1IR5IIxdEUiNSNMA=; X-YMail-OSG: 6J9BWb0VM1nWaoCpgDnOMmZrPX84kroZ7MGm1.nb2m1tlHL 0v26uz3VpfZVFsYgvysOKF9z6rkdPpq2k7m5s0d_zha6Z3OCeDK3rqG0YTqd pCo_exXYfbU0P0bx74XokrYvN7RZ8DHARGs.f1IteK_AzsnLaSmWetK1073o XAoz4mO8rVXflupw.KfoaATUN50t0IobU.XNZkZwDN2tOHkvRvZvEmz.HfDv 2q8bCi7Br7ptYQ358ZTwgVHNdM7I2U5W8QhcYdXF6euG0W7sXxXJIcGO25yi S.LMT1fZtLo.Tshq2OGxBYM906rLVEb6I467sRb1hsl82xb3dGUyYfCMo0Zz UdOY_lobxmsSoORWe22S5Fgc7v5FuQBhxWtGE1.2gnuBe.B3YQ13S73ON9S0 bZR9Nmy63JD4YxQOt3RSb1iuIbLEs201zoSvmKdlBSpH4uw2NA98qEkvjkOC BPr3J2mXCnhR8xzpGBDp7hzobGtuAVQ7JgxWLH0.2TyL_tx6.tmnRU4iTISX AW7YMeqwINPdF3bAAHA-- Received: from [208.82.145.150] by web80607.mail.mud.yahoo.com via HTTP; Thu, 29 Mar 2012 11:34:19 PDT X-Mailer: YahooMailClassic/15.0.5 YahooMailWebService/0.8.117.340979 Message-ID: <1333046059.73868.YahooMailClassic@web80607.mail.mud.yahoo.com> Date: Thu, 29 Mar 2012 11:34:19 -0700 (PDT) From: "Thomas R. Schaefer" Subject: Re: bug#11125: date command calculations are not consistent To: Eric Blake In-Reply-To: <4F74A38B.2010308@redhat.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="-2114655128-1097727386-1333046059=:73868" X-Spam-Score: -1.9 (-) X-Debbugs-Envelope-To: 11125 Cc: 11125@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -1.9 (-) ---2114655128-1097727386-1333046059=:73868 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Thank you, I really appreciate your suggestion and will use it in my script= .=A0 That will solve my problem. I can appreciate the consensus that "relative date operations add or subtra= ct in multiples of 24 hours, without regards to daylight savings boundaries= ".=A0 In fact I would be inclined to agree with it. But if that is the consensus then I believe the date command should adhere = to that consensus consistently which it does not. In this case date is calculating with 24 hours days regardless of crossing = a DST boundary.. [root@schaefer-test ~]# date -d "Thu Mar 22 00:00:00 CDT 2012 - 21 days" Wed Feb 29 23:00:00 CST 2012 In this case date does take DST into account in a relative date operation.. [root@schaefer-test ~]# date -d "last Thursday - 21 days" Thu Mar=A0 1 00:00:00 CST 2012 If the date command where being consistent in following the consensus that = "relative date operations add or subtract in multiples of 24 hours, without= regards to daylight savings boundaries" then both of the above date comman= ds would return Wed Feb 29 23:00:00 CST 2012. Again thank you for your help, Tom Schaefer --- On Thu, 3/29/12, Eric Blake wrote: From: Eric Blake Subject: Re: bug#11125: date command calculations are not consistent To: "Thomas R. Schaefer" Cc: 11125@debbugs.gnu.org Date: Thursday, March 29, 2012, 1:01 PM forcemerge 11098 11125 thanks On 03/29/2012 11:43 AM, Thomas R. Schaefer wrote: > Discovered this when I script I have cronned to run at 12:01AM gave some = unexpected results. >=20 > After much picking at it I finally figured out that the date command itse= lf was the source of my problem.=A0 It isn't handling date calculations tha= t span the daylight savings time change consistently Thanks for the report.=A0 Join the club.=A0 This has been reported twice this week already, and the consensus is that date is behaving as documented (relative date operations add or subtract in multiples of 24 hours, without regards to daylight savings boundaries), but that the documented behavior could be improved if someone were to submit a patch. https://lists.gnu.org/archive/html/bug-coreutils/2012-03/msg00102.html 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). In your example, change: RSD=3D"$(date +%F -d "today - 35=A0 days")" # Report Start Date to: RSD=3D"$(date +%F -d "noon today - 35=A0 days")" # Report Start Date --=20 Eric Blake=A0=A0=A0eblake@redhat.com=A0 =A0 +1-919-301-3266 Libvirt virtualization library http://libvirt.org ---2114655128-1097727386-1333046059=:73868 Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable
Thank you, I really appreciate your suggestio= n and will use it in my script.  That will solve my problem.

I = can appreciate the consensus that "relative date operations add or subtract= in multiples of 24 hours, without regards to daylight savings boundaries".=   In fact I would be inclined to agree with it.

But if that is = the consensus then I believe the date command should adhere to that consens= us consistently which it does not.

In this case date is calculating = with 24 hours days regardless of crossing a DST boundary..

[root@sch= aefer-test ~]# date -d "Thu Mar 22 00:00:00 CDT 2012 - 21 days"
Wed Feb = 29 23:00:00 CST 2012

In this case date does take DST into account in= a relative date operation..

[root@schaefer-test ~]# date -d "last T= hursday - 21 days"
Thu Mar  1 00:00:00 CST 2012

If the date command where being consistent in following the consensus that "relative d= ate operations add or subtract in multiples of 24 hours, without regards to= daylight savings boundaries" then both of the above date commands would re= turn Wed Feb 29 23:00:00 CST 2012.

Again thank you for your help,
Tom Schaefer










--- On Thu,= 3/29/12, Eric Blake <eblake@redhat.com> wrote:

From: Eric Blake <eblake@redhat.com>
Subject= : Re: bug#11125: date command calculations are not consistent
To: "Thoma= s R. Schaefer" <schaefert@yahoo.com>
Cc: 11125@debbugs.gnu.org
= Date: Thursday, March 29, 2012, 1:01 PM

for= cemerge 11098 11125
thanks

On 03/29/2012 11:43 AM, Thomas R. Scha= efer wrote:
> Discovered this when I script I have cronned to run at 12:01AM gave some unexpected results.
>
> After much picki= ng 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 dayl= ight savings time change consistently

Thanks for the report.  J= oin the club.  This has been reported twice
this week already, and = the consensus is that date is behaving as
documented (relative date oper= ations add or subtract in multiples of 24
hours, without regards to dayl= ight savings boundaries), but that the
documented behavior could be impr= oved if someone were to submit a patch.

ht= tps://lists.gnu.org/archive/html/bug-coreutils/2012-03/msg00102.html
As recommended in our FAQ,

https://www.gnu.org/software/coreutils/faq/#The-date-com= mand-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 c= rosses a 23-hour or 25-hour day).

In your example, change:

RS= D=3D"$(date +%F -d "today - 35  days")" # Report Start Date

to:=

RSD=3D"$(date +%F -d "noon today - 35  days")" # Report Start = Date

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

---2114655128-1097727386-1333046059=:73868-- From debbugs-submit-bounces@debbugs.gnu.org Thu Mar 29 15:38:17 2012 Received: (at 11125) by debbugs.gnu.org; 29 Mar 2012 19:38:17 +0000 Received: from localhost ([127.0.0.1]:45261 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SDLAm-0004GM-O1 for submit@debbugs.gnu.org; Thu, 29 Mar 2012 15:38:16 -0400 Received: from mx1.redhat.com ([209.132.183.28]:15833) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SDLAj-0004G4-Ty for 11125@debbugs.gnu.org; Thu, 29 Mar 2012 15:38:15 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q2TJ6idX015579 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 29 Mar 2012 15:06:44 -0400 Received: from [10.3.113.31] (ovpn-113-31.phx2.redhat.com [10.3.113.31]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q2TJ6hCn030857; Thu, 29 Mar 2012 15:06:44 -0400 Message-ID: <4F74B2C3.90506@redhat.com> Date: Thu, 29 Mar 2012 13:06:43 -0600 From: Eric Blake Organization: Red Hat User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:11.0) Gecko/20120316 Thunderbird/11.0 MIME-Version: 1.0 To: "Thomas R. Schaefer" Subject: Re: bug#11125: date command calculations are not consistent References: <1333043019.33056.YahooMailClassic@web80606.mail.mud.yahoo.com> <1333046059.73868.YahooMailClassic@web80607.mail.mud.yahoo.com> In-Reply-To: <1333046059.73868.YahooMailClassic@web80607.mail.mud.yahoo.com> X-Enigmail-Version: 1.4 OpenPGP: url=http://people.redhat.com/eblake/eblake.gpg Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="------------enigE33820A40BA77614A92305F0" X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-Spam-Score: -1.9 (-) X-Debbugs-Envelope-To: 11125 Cc: 11125@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -1.9 (-) This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigE33820A40BA77614A92305F0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On 03/29/2012 12:34 PM, Thomas R. Schaefer wrote: > In this case date is calculating with 24 hours days regardless of cross= ing a DST boundary.. >=20 > [root@schaefer-test ~]# date -d "Thu Mar 22 00:00:00 CDT 2012 - 21 days= " > Wed Feb 29 23:00:00 CST 2012 This started from one fixed point in time, relative to the 'CDT' time zone, and subtracted 21 * 24 hours. >=20 > In this case date does take DST into account in a relative date operati= on.. >=20 > [root@schaefer-test ~]# date -d "last Thursday - 21 days" > Thu Mar 1 00:00:00 CST 2012 But notice what date -d "last Thursday" is: $ TZ=3DCST date -d 'last Thursday CST' Thu Mar 22 00:00:00 CST 2012 It's relative to the 'CST' timezone, which is an hour different from the CDT timezone. >=20 > If the date command where being consistent in following the consensus t= hat "relative date operations add or subtract in multiples of 24 hours, w= ithout regards to daylight savings boundaries" then both of the above dat= e commands would return Wed Feb 29 23:00:00 CST 2012. Only if you start from the same point in time in both commands, which you didn't. --=20 Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --------------enigE33820A40BA77614A92305F0 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBCAAGBQJPdLLDAAoJEKeha0olJ0NqJ3AH/08aSts62KkElgBWcI7vuR4n VyA5+8O2+6MjX1nbb2F4VNwhSy36gWU+JshSMkj5XvZT6f3SMD4jo7AMFpq9xr54 rnjikMHCQC0AE4j/4PUguK3WFu183M2oQrbPi+dge+3RwYodKyvm9chSk6AXLheY SswydgyObTEChMMxWtvIOPnriv/OtnUn5/ATzU+sy7POtvm9ZtHmHm0ICfIE4cYk SQGvPIMRMdx5SgSvYJuYc9NpCg4Hh85gbGNDJjUzhAseNdGpd+dro/AWKArsROcs HHW81vZtub1g8GdsXBvNyiBFE+J12+17fN4BnyJxIKIpfeRSQ0s2Wm3eaj8aZX8= =hBxn -----END PGP SIGNATURE----- --------------enigE33820A40BA77614A92305F0-- From debbugs-submit-bounces@debbugs.gnu.org Fri Mar 30 00:07:30 2012 Received: (at 11125) by debbugs.gnu.org; 30 Mar 2012 04:07:30 +0000 Received: from localhost ([127.0.0.1]:45722 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SDT7Z-0000k4-MT for submit@debbugs.gnu.org; Fri, 30 Mar 2012 00:07:29 -0400 Received: from joseki.proulx.com ([216.17.153.58]:34976) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SDT7X-0000jw-1j for 11125@debbugs.gnu.org; Fri, 30 Mar 2012 00:07:27 -0400 Received: from hysteria.proulx.com (hysteria.proulx.com [192.168.230.119]) by joseki.proulx.com (Postfix) with ESMTP id 93578211D1; Thu, 29 Mar 2012 21:35:55 -0600 (MDT) Received: by hysteria.proulx.com (Postfix, from userid 1000) id 37D2D2DC0F; Thu, 29 Mar 2012 21:35:55 -0600 (MDT) Date: Thu, 29 Mar 2012 21:35:55 -0600 From: Bob Proulx To: "Thomas R. Schaefer" , 11125@debbugs.gnu.org Subject: Re: bug#11125: date command calculations are not consistent Message-ID: <20120330033554.GA10357@hysteria.proulx.com> References: <1333043019.33056.YahooMailClassic@web80606.mail.mud.yahoo.com> <1333046059.73868.YahooMailClassic@web80607.mail.mud.yahoo.com> <4F74B2C3.90506@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4F74B2C3.90506@redhat.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Spam-Score: -1.9 (-) X-Debbugs-Envelope-To: 11125 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -1.9 (-) Eric Blake wrote: > Thomas R. Schaefer wrote: > > In this case date does take DST into account in a relative date operation.. > > > > [root@schaefer-test ~]# date -d "last Thursday - 21 days" > > Thu Mar 1 00:00:00 CST 2012 > > But notice what date -d "last Thursday" is: > > $ TZ=CST date -d 'last Thursday CST' > Thu Mar 22 00:00:00 CST 2012 > > It's relative to the 'CST' timezone, which is an hour different from the > CDT timezone. Additionally it is working near the problematic midnight time when crosing DST boundaries may cause problems. > > If the date command where being consistent in following the > > consensus that "relative date operations add or subtract in > > multiples of 24 hours, without regards to daylight savings > > boundaries" then both of the above date commands would return Wed > > Feb 29 23:00:00 CST 2012. > > Only if you start from the same point in time in both commands, which > you didn't. For an example always use a time in addition to a day. Never default to midnight. Instead use 12:00 noon to avoid the DST problems. $ TZ=US/Mountain date -R -d 'last Thursday' Thu, 22 Mar 2012 00:00:00 -0600 That is problematic usage. But specifying the time as 12:00 noon solves the problem. $ TZ=US/Mountain date -R -d '12:00 last Thursday' Thu, 22 Mar 2012 12:00:00 -0600 Then doing calculations will be more reliable. $ TZ=US/Mountain date -R -d '12:00 last Thursday - 21 days' Thu, 01 Mar 2012 12:00:00 -0700 Note that I always use -R to obtain an unambiguous format. Using the default format isn't unambiguous as there are multiple timezones with the same names. Doing calculations on weeks and months have similar issues. When doing calculations on months I always work with the middle of the month to avoid the difference in lenghts of months. Generate a reference date in the middle of the month. $ date +%Y-%m-15 2012-03-15 Use that date for month calculations. $ date --date="$(date +%Y-%m-15) -1 month" +'Last month was %B.' Last month was February. Please see the FAQ for more examples: http://www.gnu.org/software/coreutils/faq/#The-date-command-is-not-working-right_002e Unfortunately the human date parsing that was added to date is a rather simplistic implementation. Bob From debbugs-submit-bounces@debbugs.gnu.org Fri Mar 30 11:56:36 2012 Received: (at 11125) by debbugs.gnu.org; 30 Mar 2012 15:56:36 +0000 Received: from localhost ([127.0.0.1]:47182 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SDeBn-0005U3-K6 for submit@debbugs.gnu.org; Fri, 30 Mar 2012 11:56:36 -0400 Received: from nm15-vm1.bullet.mail.ne1.yahoo.com ([98.138.90.254]:20178) by debbugs.gnu.org with smtp (Exim 4.72) (envelope-from ) id 1SDeBa-0005Tb-Eo for 11125@debbugs.gnu.org; Fri, 30 Mar 2012 11:56:34 -0400 Received: from [98.138.90.49] by nm15.bullet.mail.ne1.yahoo.com with NNFMP; 30 Mar 2012 15:24:48 -0000 Received: from [209.191.108.97] by tm2.bullet.mail.ne1.yahoo.com with NNFMP; 30 Mar 2012 15:24:48 -0000 Received: from [66.94.237.125] by t4.bullet.mud.yahoo.com with NNFMP; 30 Mar 2012 15:24:48 -0000 Received: from [127.0.0.1] by omp1030.access.mail.mud.yahoo.com with NNFMP; 30 Mar 2012 15:24:48 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 441467.97189.bm@omp1030.access.mail.mud.yahoo.com Received: (qmail 80090 invoked by uid 60001); 30 Mar 2012 15:24:48 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1333121088; bh=dAFGDKaY6FoHXYSU7zTwPepG1P07oHnfL9KPrrriwxM=; h=X-YMail-OSG:Received:X-Mailer:Message-ID:Date:From:Subject:To:In-Reply-To:MIME-Version:Content-Type; b=FwAuTgEF/ZNcc0rjfffwJm+tWpqIB5BDty0tC3z7C86NlYLLealTgDzFEkix5sik82FqN1CUSJ9AtVNan9vqpJ4S3rV/jofjV2Oz+IQb3lHnnOpumryzHGPxs0BzpikzAAg9VdDbZ5ydtqVnV+6EGbY1VS+ieOdqk80dnlNtNlQ= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:X-Mailer:Message-ID:Date:From:Subject:To:In-Reply-To:MIME-Version:Content-Type; b=PDVCsngY9j96R+R6IL+6EUgFEVQt0mATFjP4qiD1X4lB9cLXwiwidDrkaKzWNYiHrY0Q+/EkEA/3D43bHRaxSsMHKAoq5y7pR6T5U1Ou2b1wgGWGOt5UaEMoA6NC6ZwayZRi2F9Bh7kNAmKGR2WGHb32sCrjzYTLCpRw2KxI5vw=; X-YMail-OSG: Bw7CZNcVM1nH956AAA6ERh96GFUn6A5G2I.9r4z9HfJaGrD XPRoAQMCDn._WyLaHN9808DGOdIkNWojKZwvl5lNLjD2CHArnZ4gFB2qQGkb fKvSZuC.1bG8XyorumZaF6b3Ymt_Ji.iJaTZ9JBoNP9lCxFwZwzwFfgTWf8k nr69WSPpnPL019iR0Pb5TJ9_laSKms.kLDab95qxMKVWobU7yEsOlryyfth8 D9_jvcj0WhExANH5TqG64sUzCbYmBXseuI3mfrjn4gIIvggPnDAo3Qt6IMea ZJ5RYd3JmXQTqU6o7Ax56QKP1F3.DxyBT8R_9cW5nbneRUCYsrXNQDEvVGSL SjBx4NDECbL4fuGRS40RaAo7PE8lKZqjIQdolVj.yDcitgkYtzLTHDopFgLo 9rX.px0izu5pOw7PCSuq1dkCWV6GNLrT5BSYCmA19Np3ZO7Cnw7HqBbVy.ZI oGYOgAVsyr074X4eALji2dsgs.m_nqAXuNqbus5ba Received: from [12.156.202.250] by web80608.mail.mud.yahoo.com via HTTP; Fri, 30 Mar 2012 08:24:48 PDT X-Mailer: YahooMailClassic/15.0.5 YahooMailWebService/0.8.117.340979 Message-ID: <1333121088.70833.YahooMailClassic@web80608.mail.mud.yahoo.com> Date: Fri, 30 Mar 2012 08:24:48 -0700 (PDT) From: "Thomas R. Schaefer" Subject: Re: bug#11125: date command calculations are not consistent To: 11125@debbugs.gnu.org, Bob Proulx In-Reply-To: <20120330033554.GA10357@hysteria.proulx.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="-2114655128-985944510-1333121088=:70833" X-Spam-Score: -1.9 (-) X-Debbugs-Envelope-To: 11125 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -1.9 (-) ---2114655128-985944510-1333121088=:70833 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Thanks Eric & Bob.=A0 Good stuff.=A0 I'm still slightly foggy on why I get = different answers subtracting 35 days from seemingly the same point in time= .. [tschaefer@schaefer-test ~]$ date=A0 -d 'last Thursday' Thu Mar 29 00:00:00 CDT 2012 [tschaefer@schaefer-test ~]$ date=A0 -d 'Thu Mar 29 00:00:00 CDT 2012 - 35 = days' Wed Feb 22 23:00:00 CST 2012 [tschaefer@schaefer-test ~]$ date -d 'last Thursday - 35 days' Thu Feb 23 00:00:00 CST 2012 But, I'm probably just to dense to get it. Thanks again for the help.=A0 The suggestion of using "noon today" when sub= tracting days from a date is an excellent one. Tom Schaefer --- On Thu, 3/29/12, Bob Proulx wrote: From: Bob Proulx Subject: Re: bug#11125: date command calculations are not consistent To: "Thomas R. Schaefer" , 11125@debbugs.gnu.org Date: Thursday, March 29, 2012, 10:35 PM Eric Blake wrote: > Thomas R. Schaefer wrote: > > In this case date does take DST into account in a relative date operati= on.. > >=20 > > [root@schaefer-test ~]# date -d "last Thursday - 21 days" > > Thu Mar=A0 1 00:00:00 CST 2012 >=20 > But notice what date -d "last Thursday" is: >=20 > $ TZ=3DCST date -d 'last Thursday CST' > Thu Mar 22 00:00:00 CST 2012 >=20 > It's relative to the 'CST' timezone, which is an hour different from the > CDT timezone. Additionally it is working near the problematic midnight time when crosing DST boundaries may cause problems. > > If the date command where being consistent in following the > > consensus that "relative date operations add or subtract in > > multiples of 24 hours, without regards to daylight savings > > boundaries" then both of the above date commands would return Wed > > Feb 29 23:00:00 CST 2012. >=20 > Only if you start from the same point in time in both commands, which > you didn't. For an example always use a time in addition to a day.=A0 Never default to midnight.=A0 Instead use 12:00 noon to avoid the DST problems. =A0 $ TZ=3DUS/Mountain date -R -d 'last Thursday' =A0 Thu, 22 Mar 2012 00:00:00 -0600 That is problematic usage.=A0 But specifying the time as 12:00 noon solves the problem. =A0 $ TZ=3DUS/Mountain date -R -d '12:00 last Thursday' =A0 Thu, 22 Mar 2012 12:00:00 -0600 Then doing calculations will be more reliable. =A0 $ TZ=3DUS/Mountain date -R -d '12:00 last Thursday - 21 days' =A0 Thu, 01 Mar 2012 12:00:00 -0700 Note that I always use -R to obtain an unambiguous format.=A0 Using the default format isn't unambiguous as there are multiple timezones with the same names. Doing calculations on weeks and months have similar issues.=A0 When doing calculations on months I always work with the middle of the month to avoid the difference in lenghts of months. Generate a reference date in the middle of the month. =A0 $ date +%Y-%m-15 =A0 2012-03-15 Use that date for month calculations. =A0 $ date --date=3D"$(date +%Y-%m-15) -1 month" +'Last month was %B.' =A0 Last month was February. Please see the FAQ for more examples: =A0 http://www.gnu.org/software/coreutils/faq/#The-date-command-is-not-work= ing-right_002e Unfortunately the human date parsing that was added to date is a rather simplistic implementation. Bob ---2114655128-985944510-1333121088=:70833 Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable
Thanks Eric & Bob.  Good stuff. = ; I'm still slightly foggy on why I get different answers subtracting 35 da= ys from seemingly the same point in time..

[tschaefer@schaefer-test = ~]$ date  -d 'last Thursday'
Thu Mar 29 00:00:00 CDT 2012
[tscha= efer@schaefer-test ~]$ date  -d 'Thu Mar 29 00:00:00 CDT 2012 - 35 day= s'
Wed Feb 22 23:00:00 CST 2012
[tschaefer@schaefer-test ~]$ date -d = 'last Thursday - 35 days'
Thu Feb 23 00:00:00 CST 2012

But, I'm p= robably just to dense to get it.

Thanks again for the help.  Th= e suggestion of using "noon today" when subtracting days from a date is an = excellent one.

Tom Schaefer

--- On Thu, 3/29/12, Bob Proul= x <bob@proulx.com> wrote:

= From: Bob Proulx <bob@proulx.com>
Subject: Re: bug#11125: date command = calculations are not consistent
To: "Thomas R. Schaefer" <schaefert@y= ahoo.com>, 11125@debbugs.gnu.org
Date: Thursday, March 29, 2012, 10:3= 5 PM

Eric Blake wrote:
> Thomas R. Sc= haefer wrote:
> > In this case date does take DST into account in = a relative date operation..
> >
> > [root@schaefer-test = ~]# date -d "last Thursday - 21 days"
> > Thu Mar  1 00:00:00= CST 2012
>
> But notice what date -d "last Thursday" is:
&= gt;
> $ TZ=3DCST date -d 'last Thursday CST'
> Thu Mar 22 00:0= 0:00 CST 2012
>
> It's relative to the 'CST' timezone, which i= s an hour different from the
> CDT timezone.

Additionally it i= s working near the problematic midnight time when
crosing DST boundaries= may cause problems.

> > If the date command where being consistent in following the
> > consensus that "relative date ope= rations add or subtract in
> > multiples of 24 hours, without rega= rds to daylight savings
> > boundaries" then both of the above dat= e commands would return Wed
> > Feb 29 23:00:00 CST 2012.
> =
> Only if you start from the same point in time in both commands, wh= ich
> you didn't.

For an example always use a time in addition= to a day.  Never default
to midnight.  Instead use 12:00 noon= to avoid the DST problems.

  $ TZ=3DUS/Mountain date -R -d 'la= st Thursday'
  Thu, 22 Mar 2012 00:00:00 -0600

That is probl= ematic usage.  But specifying the time as 12:00 noon
solves the pro= blem.

  $ TZ=3DUS/Mountain date -R -d '12:00 last Thursday'
=   Thu, 22 Mar 2012 12:00:00 -0600

Then doing calculations will = be more reliable.

  $ TZ=3DUS/Mountain date -R -d '12:00 last Thursday - 21 days'
  Thu, 01 Mar 2012 12:00:00 -0700

Note = that I always use -R to obtain an unambiguous format.  Using the
de= fault format isn't unambiguous as there are multiple timezones with
the = same names.

Doing calculations on weeks and months have similar issu= es.  When
doing calculations on months I always work with the middl= e of the
month to avoid the difference in lenghts of months.

Gene= rate a reference date in the middle of the month.

  $ date +%Y-= %m-15
  2012-03-15

Use that date for month calculations.
=
  $ date --date=3D"$(date +%Y-%m-15) -1 month" +'Last month was %B= .'
  Last month was February.

Please see the FAQ for more ex= amples:

  http://www.gnu.org/software/coreutils/faq/#The-date-comm= and-is-not-working-right_002e

Unfortunately the human date parsi= ng that was added to date is a
rather simplistic implementation.

= Bob

---2114655128-985944510-1333121088=:70833-- From unknown Sat Jun 21 03:29:26 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Wed, 02 May 2012 11:24:02 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator From debbugs-submit-bounces@debbugs.gnu.org Tue Aug 04 18:31:30 2015 Received: (at control) by debbugs.gnu.org; 4 Aug 2015 22:31:30 +0000 Received: from localhost ([127.0.0.1]:39749 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZMkk6-0000gH-9i for submit@debbugs.gnu.org; Tue, 04 Aug 2015 18:31:30 -0400 Received: from mail1.vodafone.ie ([213.233.128.43]:63964) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZMkk4-0000dy-GR for control@debbugs.gnu.org; Tue, 04 Aug 2015 18:31:28 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AhMuAAQ9wVVtTtu9/2dsb2JhbABbgklSI3QIgV2BZL8BgwOBEUwBAQEBAQGBC0EFg30KKlQNAgUWCwILAwIBAgE5BgICFQgBAYguAaQ0j2GFb5BzgSKPU4IXDC8SgTEFlHqVQZBkJoFKAQEBBwIBgic9gn0CAQI Received: from unknown (HELO localhost.localdomain) ([109.78.219.189]) by mail1.vodafone.ie with ESMTP; 04 Aug 2015 23:31:10 +0100 Message-ID: <55C13D2D.2040004@draigBrady.com> Date: Tue, 04 Aug 2015 23:31:09 +0100 From: =?UTF-8?B?UMOhZHJhaWcgQnJhZHk=?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: control@debbugs.gnu.org Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Spam-Score: 2.0 (++) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has identified this incoming email as possible spam. The original message has been attached to this so you can view it (if it isn't spam) or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: unarchive 11098 unarchive 18159 forcemerge 11098 18159 [...] Content analysis details: (2.0 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [213.233.128.43 listed in list.dnswl.org] 1.8 MISSING_SUBJECT Missing Subject: header 0.2 NO_SUBJECT Extra score for no subject X-Debbugs-Envelope-To: control X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 2.0 (++) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has identified this incoming email as possible spam. The original message has been attached to this so you can view it (if it isn't spam) or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: unarchive 11098 unarchive 18159 forcemerge 11098 18159 [...] Content analysis details: (2.0 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [213.233.128.43 listed in list.dnswl.org] 1.8 MISSING_SUBJECT Missing Subject: header 0.2 NO_SUBJECT Extra score for no subject unarchive 11098 unarchive 18159 forcemerge 11098 18159 From unknown Sat Jun 21 03:29:26 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: Did not alter fixed versions and reopened. Date: Tue, 04 Aug 2015 22:43:01 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # Did not alter fixed versions and reopened. thanks # This fakemail brought to you by your local debbugs # administrator From debbugs-submit-bounces@debbugs.gnu.org Fri Oct 19 19:14:10 2018 Received: (at control) by debbugs.gnu.org; 19 Oct 2018 23:14:10 +0000 Received: from localhost ([127.0.0.1]:59981 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gDdy6-0004jh-Ix for submit@debbugs.gnu.org; Fri, 19 Oct 2018 19:14:10 -0400 Received: from mail-pg1-f172.google.com ([209.85.215.172]:37634) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gDdy4-0004jS-DJ for control@debbugs.gnu.org; Fri, 19 Oct 2018 19:14:08 -0400 Received: by mail-pg1-f172.google.com with SMTP id c10-v6so16378310pgq.4 for ; Fri, 19 Oct 2018 16:14:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:message-id:date:user-agent:mime-version:content-language :content-transfer-encoding; bh=89N7FWHIQHjZJJV6+TLF+q9wldRaB57sUNVNuIge/V4=; b=scIZI3NCLx2wOWUdrYAXBHj4QvCbILEsvWOY16NSfzkLetKLrAvxqBQhVzn1CFSUYE bwl4yMz+5/LLLVFPc4J5UUKemVi3dbz2I9iVvpi5jo85tkOiG1BH1pt+v2088P6QAneF S50bUGZu5ojJhYl63md1ILnln2mhOSgt0RasfE2lMQuHRFdaXYfQ/rMlxz2sBPwHJCkh FWZ29jcqrRxjj5JKk/8smTAY3JIKgHSKheoxgR/3RbkYDOlDjge/tcFaQ7Ov/SmmI03t Sn9rkkzCPwyU2kK8zAk+nx5els863ADYy0Qb0jWhKMDYFydxN7waeQEbapQWJkBv1YE+ NO3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:message-id:date:user-agent:mime-version :content-language:content-transfer-encoding; bh=89N7FWHIQHjZJJV6+TLF+q9wldRaB57sUNVNuIge/V4=; b=f8rgyonzRzEOfWnAAeCKfk+On1MGYZ5jjWUXWjJuUXSj6xqk4kDWhw0TBOiHeuDTtP 3qhGe9XnpTYDYSp+4BDNa78yBh1qD5yWzr821FGooKxuVEY3Bt4nsg3nuAl/jQdtKa4U a/McZTMVvy5+/3lxmRMIwTixAXn0pI4o6ypikvsvPaJVSSZHCQDRTdMgPSiSTzZVCZZE fDJSq1qZDLUd0tdCeHkaCIFtIa8cg3kaTtAQaIrAsKbjRKsRFgOfILwtJvNKcN6SbYLz U6mwamujmozYMRTI2lmEjgK6+PJtJgTkbmvaXEhX1y0G/+XMmbqbtxC4PkuMt5uPqSpc uzww== X-Gm-Message-State: ABuFfohkEnrdn0L1aHPxWAjZWkEfiumCtL7HXVVcb7LdXDnhIHH0Qsyo O/2QYCp5LQc2TF/TYtENSEru5mg7nSo= X-Google-Smtp-Source: ACcGV63v5CE6AYVl28KnPiS5r/Msj9dXdNNxMFYjzxjPQd50RRh0aYUHK+6a4d+aT6TVIpLVg/Gs2Q== X-Received: by 2002:a63:5a0d:: with SMTP id o13-v6mr34463739pgb.267.1539990842315; Fri, 19 Oct 2018 16:14:02 -0700 (PDT) Received: from tomato.housegordon.com (moose.housegordon.com. [184.68.105.38]) by smtp.googlemail.com with ESMTPSA id k12-v6sm23006767pgo.34.2018.10.19.16.14.00 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Oct 2018 16:14:01 -0700 (PDT) To: control@debbugs.gnu.org From: Assaf Gordon Message-ID: Date: Fri, 19 Oct 2018 17:14:00 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Score: 2.0 (++) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: merge 15785 11098 [...] Content analysis details: (2.0 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (assafgordon[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [209.85.215.172 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [209.85.215.172 listed in wl.mailspike.net] 1.8 MISSING_SUBJECT Missing Subject: header 0.2 NO_SUBJECT Extra score for no subject X-Debbugs-Envelope-To: control X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 1.0 (+) merge 15785 11098 From debbugs-submit-bounces@debbugs.gnu.org Wed Oct 24 17:58:59 2018 Received: (at control) by debbugs.gnu.org; 24 Oct 2018 21:58:59 +0000 Received: from localhost ([127.0.0.1]:40921 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gFRB5-0003LK-3e for submit@debbugs.gnu.org; Wed, 24 Oct 2018 17:58:59 -0400 Received: from mail-pg1-f172.google.com ([209.85.215.172]:36731) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gFRB3-0003L4-EM for control@debbugs.gnu.org; Wed, 24 Oct 2018 17:58:57 -0400 Received: by mail-pg1-f172.google.com with SMTP id l6-v6so2982731pgp.3 for ; Wed, 24 Oct 2018 14:58:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:message-id:date:user-agent:mime-version:content-language :content-transfer-encoding; bh=ybwsFcZOJ4XqnENbrZz6Y7xHX9QN259PKfsbURBotQ4=; b=VbrP2ABK8aqPLCrwT0sFctGdbUJeKlXxIvXwzmhEszK9MAqpnud6inJzek2SCSztIa bL/V0xxdRd1kv7UIwIi8B/LFWeYRSjbfGkGGkZG5bltrD2ndt2aA0RUeeDUWCda9xfFx 0Qgt/Gx49X4okdQJ2GJ+fwJGPfmTI2aCr4pH1wjsHGx4FnD0UU8uMgxLuQ/8GFYVhEeY 5qPFh/STWFaAUEAUM3JnU6CDJsF5CBekfsoBVNiSsECBPciOOsVMCTvQHBi/HrNT8c3n xMPVeh+74zr0qkfm0VV4jzG+xk2P6GVM6tC0U1ToWcRRrUgOl3hrJnujTJ1knvDOjVOr PIqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:message-id:date:user-agent:mime-version :content-language:content-transfer-encoding; bh=ybwsFcZOJ4XqnENbrZz6Y7xHX9QN259PKfsbURBotQ4=; b=Qqd+Fi5382LoLqnv6OCtoWq4exbGIwtOsi/sqMsFmRsVbc00q5rE/d/e0dyCN0vVjE tRXBbCc3TyVL8FUVhFwAVMK1/DTJWIn0Gt4mL9pI51ka4x3yWn8PIJrHnH06CjvA0sdy lBXh1L2fEWbelHD+CvUR+BWwYkJj432g00daUq5B1BbNi3zyJ0RzSINj5C7lmEaQnfdh sD9ROzgCYYkCP+4Zx8oTy7oOfyz9GtEE4pZ3CsqNDUJDpBRPDU3UlqkIUNUgAGgbBQKv jZ5RzN4xHkvfwQkoGvCm2pknhkzqo5tbNO5Da8EnYWrGvtQDgCsQEsBS6sMZVVeheSOU h1Bg== X-Gm-Message-State: AGRZ1gJlDPbg6AHgp6Vb2t8pEMfqoALoEWL692FHfDkFrxXGD01g/ygo e0vlti+Sl7rSAjAf7XhWk49rA+XK1OM= X-Google-Smtp-Source: AJdET5exvW4CCbCrNz7wkfiZVbqDCk30Zqy0z1VOoClEysTLNPu08mn6CslukvPuOUZb4i9u9KWiZg== X-Received: by 2002:a63:4e4e:: with SMTP id o14-v6mr4194100pgl.181.1540418330717; Wed, 24 Oct 2018 14:58:50 -0700 (PDT) Received: from tomato.housegordon.com (moose.housegordon.com. [184.68.105.38]) by smtp.googlemail.com with ESMTPSA id u190-v6sm22723811pgu.3.2018.10.24.14.58.49 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Oct 2018 14:58:49 -0700 (PDT) To: control@debbugs.gnu.org From: Assaf Gordon Message-ID: <56b2fc82-5675-fd62-419a-a7117f131c09@gmail.com> Date: Wed, 24 Oct 2018 15:58:48 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Score: 2.0 (++) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: close 11098 [...] Content analysis details: (2.0 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [209.85.215.172 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (assafgordon[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record 1.8 MISSING_SUBJECT Missing Subject: header 0.2 NO_SUBJECT Extra score for no subject X-Debbugs-Envelope-To: control X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 1.0 (+) close 11098 From unknown Sat Jun 21 03:29:26 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Thu, 22 Nov 2018 12:24:03 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator