From unknown Wed Jun 18 23:06:01 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#47476 <47476@debbugs.gnu.org> To: bug#47476 <47476@debbugs.gnu.org> Subject: Status: relative date of -1 month shows the wrong month Reply-To: bug#47476 <47476@debbugs.gnu.org> Date: Thu, 19 Jun 2025 06:06:01 +0000 retitle 47476 relative date of -1 month shows the wrong month reassign 47476 coreutils submitter 47476 Lars Nood=C3=A9n severity 47476 normal thanks From debbugs-submit-bounces@debbugs.gnu.org Mon Mar 29 11:53:38 2021 Received: (at submit) by debbugs.gnu.org; 29 Mar 2021 15:53:38 +0000 Received: from localhost ([127.0.0.1]:49352 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lQuCu-0002Vr-OA for submit@debbugs.gnu.org; Mon, 29 Mar 2021 11:53:38 -0400 Received: from mout.gmx.net ([212.227.17.21]:43523) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lQtzM-00026s-F2 for submit@debbugs.gnu.org; Mon, 29 Mar 2021 11:39:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1617032370; bh=hHsABSutWdhI68TOgKbbvISsoWxWMCKkhJWWxpWCsqo=; h=X-UI-Sender-Class:To:From:Subject:Date; b=jZzpkvfD9LVMPDC7lwIJRhvUqRVB62yxhnwtmmriA4B9z5bkX5oW0Nhn8wM50pJcy sCvnrAo/lQ7o7DzPaA6q4K1xxN2YPm8sYyygf5mcQ6Qmmk5IvuA1CoFD+vMLcQoV63 3IUqt1ANzQC+BVZ481Kuh99pUWbMuFPst2Arn11s= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [10.11.9.43] ([80.220.99.163]) by mail.gmx.net (mrgmx105 [212.227.17.174]) with ESMTPSA (Nemesis) id 1MvbG2-1ljwTU096k-00scF4 for ; Mon, 29 Mar 2021 17:39:30 +0200 To: submit@debbugs.gnu.org From: =?UTF-8?Q?Lars_Nood=c3=a9n?= Subject: relative date of -1 month shows the wrong month Message-ID: Date: Mon, 29 Mar 2021 18:39:28 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Language: en-US X-Provags-ID: V03:K1:gGn6SDjafLz9SbFHD4fPoSrRRHzoueT2aNeOSh6NvB8WIZXURiZ JvM9tBKvL3LTaJsfZJTtm2k3CBoWlDInffGzSZBdJqm02kHYcyl+VIzraglEl0LpIpNuhJG oBU2wvFLd2wWoGmkvH4a35iEKqRKWop15o3CKJeCcazNQt0tMhp2zln4k5kMev69AKUbdSC iMc/QY9nocbFNzq9fQu1w== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:JRGnyq7JD8s=:8jR97F4VW/LRT1rdWK7kfN 6wuvCMH+BVNFDZC8rr1am64hwrvAAodytAcV233UXkKvF7AyG5jrN4hQxfd9hPOe9d4DegVLZ bb53Tb6cEbG6QdC6rQMuPcWReQtYsJjYuYUFgTKqheATGvBCii4XkEFe6HxZhMNLw7V3urwm2 jDATok5Gk2cxJnKl5iOuQDgM3btsGuMZ+gHLQzmpo1Gw0mJxi1lmgswe3n3j8E9Ylqx+WQx2B tVYoj03uQNC+CYXXdeCy34q1kvDHHLA4dJHb7ovy8HjRoXO7BC8N4nzWhkEpz8aMsaWeFQ2Xj NYL9kQTGmvG7jh52ZieIazwIgQgFULfLHSeibmvniD5KT+bZYYjiG3HOFxnip8e0J48SeTHCt 4cLEu0PtX1JP/Yfwnx1tuRxpYwmT9+1oQE5bs76n1f0cVcCAXTJM/UmU6156BtzIBoM9gBdM7 d0Z51fpQcukM7o0Dc6rNAmkLzMrqrevkE2yNtEVxgyTiU+/N1/AhyPOh2zEEOkvfZAqy+7nGt F8yvpvndU2SeQ0yASQjOpOsOZQzrZRUaqRyT69qwfYMx7HMkM4jBgsDnvY4Wae8Z6qFsV5MV0 dRKSm7awXsaWkEhjct4M4U1bPN1uQtasNan/37kcIJwGDy5xJ65wpDj1tqpO5791hTiELHfi5 29ot79e5uSYc8HgYccZtsnuAbCLfnH45zvRZ5WuCqdaSjstuZEs6XeCu8Fe1PVfmr1QN+3pGw FgVH9WUMCWq4ReQRdv1QQQcoiiuTCiv/lszBvKkZBBNq8j9uUrrJm09TyUe+8YOkx3gYd5QdI SeiH/V2LZQX8njhErsmcWn5UGa3G/jZ+Le1l0NgDCF//YWjLqRemXKFvZkmjw4WZc4NGD1+X/ djS1GZ/GYwJkP4HOogFAVddOL6BWD7r+OBiD0FKP+gxVtW+TzU7DKxK+c56RtMtEaZT5n4XYh 5ZOsxMY8x56YwtSiPwjsRrHouSNqrqLijGFyFhQcpUGjiDttvy34zUSjOAYpBMdOqNDDwjUty ciVJ7Y4TAmUQTU8H+gQeWkMRoAP9MYLbGEDf9zV9FmlTEJsshf0PGcuWPyY3pmj8jSm3l1AnU 860e5hdvmEEq/mDyJ1D3Ijx3T70/a8U4S3qsz8b71/wH0M93RSwsbS0vqAAHTTSfIZwW8LOnQ kiGlKCkMkS4ldlsKxwKk3dal11q8EYq7y0szbFJgp9LmPA+C/brtl9biPfjdBNVe6rsjY= X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Mon, 29 Mar 2021 11:53:35 -0400 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.7 (-) Severity: normal Package: coreutils Version: 8.32-4 On March 29, 2021, if a relative date of '-1 month' is passed to 'date', then the output shows March instead of February. $ date; date -d '-1 month'; date -d '1 month ago'; date -d 'last month'; Mon 29 Mar 2021 06:35:43 PM EEST Mon 01 Mar 2021 05:35:43 PM EET Mon 01 Mar 2021 05:35:43 PM EET Mon 01 Mar 2021 05:35:43 PM EET The output shows March when it clearly should show February instead. This impairs the usefulness of the program a lot on certain days. From debbugs-submit-bounces@debbugs.gnu.org Mon Mar 29 12:25:52 2021 Received: (at 47476) by debbugs.gnu.org; 29 Mar 2021 16:25:52 +0000 Received: from localhost ([127.0.0.1]:49416 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lQui8-0003Pg-Eh for submit@debbugs.gnu.org; Mon, 29 Mar 2021 12:25:52 -0400 Received: from mail-wr1-f43.google.com ([209.85.221.43]:41534) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lQui6-0003PT-2S for 47476@debbugs.gnu.org; Mon, 29 Mar 2021 12:25:51 -0400 Received: by mail-wr1-f43.google.com with SMTP id b9so13451621wrt.8 for <47476@debbugs.gnu.org>; Mon, 29 Mar 2021 09:25:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:subject:to:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=+aYLinVIJuY1/m2Wf8oWbWQWob9xEZDI1aW+tEV2qWI=; b=RL5HuOBDj/+9vaMm2c0PAw420CDkH+x9CoUWLCcx9JAwCoE2Pa1ChLIFPTGlG6rX46 J+/9xJeW34hQtPSFJwAI0eg0ZwSeIU/1hOMNj9uJh6TIyE2sou8Ww0JDJ1WxrRUE77o/ K8AXE/F62wnVu9S4zhK9b2WoszvbPbv5pQHTI+3e7XCYGOb/NW095ycelrhwQRnI9/L1 DU71nruJkUKLX9cCzM4c3lnCQ/5VbaZdiDLYqgGTWblFG3LN8jYxk2C8LTv8YoHYeXWb HXMA8B4qFvern3BPKYKBri/A9DzwYt1wb8L5eoOPV9ac/Z93i1lw3Y2LKFSyxxpLZ3+P rZAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:to:references:from:message-id :date:user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=+aYLinVIJuY1/m2Wf8oWbWQWob9xEZDI1aW+tEV2qWI=; b=fIxlqg9wq76hpm2+9PLnjVS6mYUF2ry7jq8tShvfoM1i6Wk55DeAwjHVPQXuM7tdFF Gg14rBA2zA70b7dNf2kkaym6sKyBcx9tdLGW9F78vb73+bsnNq4o7hmi40k2+dAV+epW QV2ZzZW+Zhn8d4Ax62S2/cXh9MKxysgY52I1DaU+Fdf/RxzIhEIEwedEZDO7TOw+F3bU 3hSGJjvu9RR7rY677PojtcLBdkUbIMVKIAfJF2PqZwN9LzCF/XG//9FFAYIhIeUBvcov 5ODtQrzH+q6dfoYbRmlnUN+//rTFF10k4rQGwBcsjItjhK3fcpEUExbIQF6IlilTfwvh UF0Q== X-Gm-Message-State: AOAM533lUI0F5mcEoPrrxBB8iqDLy3/chkDp3CveLQe39dM/tA0aZGjW ZwfVAFjRDXOOUMpDS+DHOFBUJovIURptPOOm X-Google-Smtp-Source: ABdhPJzFHzY7LRMaSlBjVFU6qUMtkHLcbdIBeFoLm3peusWfzzRfNrQUX9BZi2BM88GMQUMds7S+wg== X-Received: by 2002:a5d:49ca:: with SMTP id t10mr29391820wrs.76.1617035144003; Mon, 29 Mar 2021 09:25:44 -0700 (PDT) Received: from localhost.localdomain (86-42-14-227-dynamic.agg2.lod.rsl-rtd.eircom.net. [86.42.14.227]) by smtp.googlemail.com with UTF8SMTPSA id j12sm30822397wrx.59.2021.03.29.09.25.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 29 Mar 2021 09:25:43 -0700 (PDT) Subject: Re: bug#47476: relative date of -1 month shows the wrong month To: =?UTF-8?Q?Lars_Nood=c3=a9n?= , 47476@debbugs.gnu.org References: From: =?UTF-8?Q?P=c3=a1draig_Brady?= Message-ID: <9ba69b84-9f01-3788-83b9-f1274d3639b1@draigBrady.com> Date: Mon, 29 Mar 2021 17:25:42 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:84.0) Gecko/20100101 Thunderbird/84.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-Spam-Score: 0.5 (/) X-Debbugs-Envelope-To: 47476 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: -0.5 (/) On 29/03/2021 16:39, Lars Noodén wrote: > Severity: normal > Package: coreutils > Version: 8.32-4 > > On March 29, 2021, if a relative date of '-1 month' is passed to 'date', > then the output shows March instead of February. > > $ date; date -d '-1 month'; date -d '1 month ago'; date -d 'last month'; > Mon 29 Mar 2021 06:35:43 PM EEST > Mon 01 Mar 2021 05:35:43 PM EET > Mon 01 Mar 2021 05:35:43 PM EET > Mon 01 Mar 2021 05:35:43 PM EET > > The output shows March when it clearly should show February instead. > This impairs the usefulness of the program a lot on certain days. This is a commonly reported issue. I agree the current operation is confusing. I'm working on a change to make the adjustment relative to the input resolution. I.e. operate on a month basis in this case rather than days etc. The current FAQ (linked below) suggests the workaround of: date --date="$(date +%Y-%m-15) -1 month" +'Last month was %B.' cheers, Pádraig https://www.gnu.org/software/coreutils/faq/coreutils-faq.html#The-date-command-is-not-working-right_002e From debbugs-submit-bounces@debbugs.gnu.org Tue Mar 30 05:40:08 2021 Received: (at 47476) by debbugs.gnu.org; 30 Mar 2021 09:40:09 +0000 Received: from localhost ([127.0.0.1]:50418 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lRAr2-00066t-E7 for submit@debbugs.gnu.org; Tue, 30 Mar 2021 05:40:08 -0400 Received: from mail-wr1-f44.google.com ([209.85.221.44]:38691) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lRAqz-00066I-Uh for 47476@debbugs.gnu.org; Tue, 30 Mar 2021 05:40:07 -0400 Received: by mail-wr1-f44.google.com with SMTP id z2so15561047wrl.5 for <47476@debbugs.gnu.org>; Tue, 30 Mar 2021 02:40:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=ThjRaYC7XZ4Pd+0qTkyHW+M51cxXBnBC6E/nuaYrWDY=; b=EItPPi8vQEe4tLB8GwAySj9M9/BRtBr551Hn65m498bdCbpM/OVZAlTTJ5+/6dAFIs PXleIk6cd5pvTPP75TRJ5NzV4LAvjIGOYD0E+7z4Aq/gjaE46IqhLjKsGUktOKWaKEVk ss+eOl4NE7LItvgMoPKhWF99NYx7UlxbpaOzUOUkEgDDfQO7o+vefsw+tyd1KCB/RhiR C6SlvwKl4IRVsKcwjC1LylqEb4LxfS4PbSfyjJ5ebBpv/zsRocFpOSbtKlfuWysGWD8M aXObVCFq+NeAdA9md2E8jT8KzwK/S2KbpE4YzTYEAS/Aijokqv/dLufCPsDbaR9jkSbw bssg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=ThjRaYC7XZ4Pd+0qTkyHW+M51cxXBnBC6E/nuaYrWDY=; b=Otw4mVF6av4CVNvS0PYiasdA+TLM9w9M4HEKodXm297UzbjW6ZS2azplfK3M1+hf32 pObcorJbpFXZ7yroqxICQUiEMJRIe6QI4iVFRa+P6FKatpw4q1uNyR0jI8xhjcsCuoT3 bBfm/S8U/IPmyc1OhOcglmcerHN/l/37zhUrHzWhfI8wMowQ8w9J0wqKJT5ME9SOR7th Mq+Lcoy6UlXHjFhZDNaXPmAy4wjbTMTRm4qbYpH+hFYk8eh7m9e2328GKbErbUXQmuEU 37LAc5s3V3UtCILgxHqhbEPrEHn23yAq80KwznDI2Nb8EvsEu3Txjs7h2G1cnqMcsAKC rCfQ== X-Gm-Message-State: AOAM533E63wc+XUTVp406ctsA9RL8n+0MRCoKKKj9gOds8n0W/o9iU1z tE02bWGv0IdoeBgKOoRl33BWArHvpdo= X-Google-Smtp-Source: ABdhPJyGQgcMxexZrj1oDG6v79iskWCU42ejTAStSNf9oI3gmhOyPumAJpiUXzFyeHR9LRObcG6ptw== X-Received: by 2002:a5d:5083:: with SMTP id a3mr33409406wrt.38.1617097199913; Tue, 30 Mar 2021 02:39:59 -0700 (PDT) Received: from [192.168.23.100] (92.40.170.79.threembb.co.uk. [92.40.170.79]) by smtp.gmail.com with ESMTPSA id a14sm36304192wrg.84.2021.03.30.02.39.58 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 30 Mar 2021 02:39:58 -0700 (PDT) Subject: Re: bug#47476: relative date of -1 month shows the wrong month To: =?UTF-8?Q?P=c3=a1draig_Brady?= , =?UTF-8?Q?Lars_Nood=c3=a9n?= , 47476@debbugs.gnu.org References: <9ba69b84-9f01-3788-83b9-f1274d3639b1@draigBrady.com> From: Chris Elvidge Message-ID: Date: Tue, 30 Mar 2021 10:39:57 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 Lightning/5.4 MIME-Version: 1.0 In-Reply-To: <9ba69b84-9f01-3788-83b9-f1274d3639b1@draigBrady.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 8bit X-Spam-Score: 0.2 (/) X-Debbugs-Envelope-To: 47476 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: -0.8 (/) On 29/03/2021 05:25 pm, Pádraig Brady wrote: > On 29/03/2021 16:39, Lars Noodén wrote: >> Severity: normal >> Package: coreutils >> Version: 8.32-4 >> >> On March 29, 2021, if a relative date of '-1 month' is passed to 'date', >> then the output shows March instead of February. >> >> $ date; date -d '-1 month'; date -d '1 month ago'; date -d 'last month'; >> Mon 29 Mar 2021 06:35:43 PM EEST >> Mon 01 Mar 2021 05:35:43 PM EET >> Mon 01 Mar 2021 05:35:43 PM EET >> Mon 01 Mar 2021 05:35:43 PM EET >> >> The output shows March when it clearly should show February instead. >> This impairs the usefulness of the program a lot on certain days. > > This is a commonly reported issue. > I agree the current operation is confusing. > I'm working on a change to make the adjustment relative to the input > resolution. > I.e. operate on a month basis in this case rather than days etc. > The current FAQ (linked below) suggests the workaround of: > > date --date="$(date +%Y-%m-15) -1 month" +'Last month was %B.' > > cheers, > Pádraig > > https://www.gnu.org/software/coreutils/faq/coreutils-faq.html#The-date-command-is-not-working-right_002e > > It's noticeable that (on my system, CYGWIN-NT and/or Raspbian) 'date -d"now -1month"' gives a definitely wrong answer, but 'dateadd now -1mo' gives a somewhat more reasonable answer. dateadd is from the dateutils package, sometimes dadd and/or dateutils.dadd. $ date +"%Y-%m-%d %H:%M:%S" 2021-03-30 10:37:00 $ date -d"now -1 month" +"%Y-%m-%d %H:%M:%S" 2021-03-02 09:37:17 $ dateadd now -1mo -f"%Y-%m-%d %H:%M:%S" 2021-02-28 09:37:27 -- Chris Elvidge From debbugs-submit-bounces@debbugs.gnu.org Sun Apr 04 23:30:33 2021 Received: (at 47476) by debbugs.gnu.org; 5 Apr 2021 03:30:33 +0000 Received: from localhost ([127.0.0.1]:36724 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lTFwe-0003ZC-NK for submit@debbugs.gnu.org; Sun, 04 Apr 2021 23:30:33 -0400 Received: from havoc.proulx.com ([96.88.95.61]:39814) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lTFwc-0003Ys-83; Sun, 04 Apr 2021 23:30:31 -0400 Received: from joseki.proulx.com (localhost [127.0.0.1]) by havoc.proulx.com (Postfix) with ESMTP id 14F7E4D5; Sun, 4 Apr 2021 21:30:24 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proulx.com; s=dkim2048; t=1617593424; bh=eF+5wVBAc9AQCAdgIESRosoFEkd3Vmi7MdtW+APPBus=; h=Date:From:To:Subject:References:In-Reply-To:From; b=XTUJ+rB4t6nmts6cRz5ODr6qdbCw8NPtFJ58CpP8kUe6h9P1YRmJ0Bi043uFlPuis Ln6HYZ1ZLa0vRyLufo0M1kiO9oezxXMMZl9xpUgriZTt0jJDuKZQSSYNrML/FE8NG4 CNdzsh+awxq335RXb/4z+FbelnZb/hjYj66xGbkDyt0AN59gPytnl7aghee281XM2M gSOOR/2cWseQ249lcWxqOMHO/iZhU2i1ElfMRIV2jL+zlbxhGCo7vjJtCiPIvPMk7O Jwa4PJ6U4rtl0dHOo51wN9cHENsocj+XImBywC0y91fpvjZrHzus9TksZAop8+uDqC mQp5iuBKTj2LQ== Received: from hysteria.proulx.com (hysteria.proulx.com [192.168.230.119]) by joseki.proulx.com (Postfix) with ESMTP id A0F89211D8; Sun, 4 Apr 2021 21:30:23 -0600 (MDT) Received: by hysteria.proulx.com (Postfix, from userid 1000) id 4A71A2DC9C; Sun, 4 Apr 2021 21:30:21 -0600 (MDT) Date: Sun, 4 Apr 2021 21:30:21 -0600 From: Bob Proulx To: 47476@debbugs.gnu.org, 47476-submitter@debbugs.gnu.org Subject: Re: bug#47476: relative date of -1 month shows the wrong month Message-ID: <20210404201154977193289@bob.proulx.com> References: <9ba69b84-9f01-3788-83b9-f1274d3639b1@draigBrady.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 47476 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 (-) Lars Nooden wrote: > On March 29, 2021, if a relative date of '-1 month' is passed to 'date', > then the output shows March instead of February. The date manual includes this section on relative months. 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! This exactly covers the initial bug report. Because March 29, 2021 minus 1 month results in the invalid date February 29, 2021 which not being a leap year does not exist. What _should_ be the result if the date one month ago does not exist? And the answer to that will mostly depend upon what purpose the question was being asked. When dealing with time in months it also depends upon what you are needing done. If it is the 7th of the month and you want to generate a date that is also the 7th but one month later or earlier then if it is March 7th and generate February 7th then that will be fewer days difference than if it is were June 7th and deciding May 7th is the month early. Due to the nature of having a different number of days in different months. But if that was what I wanted then I would determine what was the month prior and generate a new datestamp using the current day of the month. [[Aside: Off the top of my head and hopefully without a trivial bug. I welcome corrections if I made a mistake in this. But this is still not completely general purpose. $ date "+%F %T" 2021-04-04 20:50:19 $ date "+%Y-$(date --date="$(date +%Y-%m-15) -1 month" +%m)-%d %H:%M:%S" 2021-03-04 20:50:54 *HOWEVER* that still does not handle the case of the original poster's report about what happens on March 29, 2021 minus one month? It can't be February 29th! Isn't that the same as March 1st? ]] Perhaps instead of the code using 30 day months it should use the number of days in the current month? Then on March 31, 2021 -1 month since March has 31 days that would calculate February 28, 2021. Is that better or worse? $ date --date="2021-03-31 12:00 +0000 -31 days" "+%F %T" 2021-02-28 05:00:00 Potentially worse! What happens on March 1, 2021 then? $ date --date="2021-03-01 12:00 +0000 -31 days" "+%F %T" 2021-01-29 05:00:00 In that case we skip over February entirely! Chris Elvidge wrote: > Pádraig Brady wrote: > > The current FAQ (linked below) suggests the workaround of: > > > > date --date="$(date +%Y-%m-15) -1 month" +'Last month was %B.' > > > > https://www.gnu.org/software/coreutils/faq/coreutils-faq.html#The-date-command-is-not-working-right_002e > > It's noticeable that (on my system, CYGWIN-NT and/or Raspbian) 'date -d"now > -1month"' gives a definitely wrong answer, but 'dateadd now -1mo' gives a > somewhat more reasonable answer. dateadd is from the dateutils package, > sometimes dadd and/or dateutils.dadd. > > $ date +"%Y-%m-%d %H:%M:%S" > 2021-03-30 10:37:00 > > $ date -d"now -1 month" +"%Y-%m-%d %H:%M:%S" > 2021-03-02 09:37:17 So... Here is the problem with "now". Using "now" is problematic *some* of the time. Not all of the time. Never when you are trying it on the command line in the middle of the day. But there are windows of time around DST time changes when it is problematic. If you are getting the time now and it is the middle of the day say around noon then that is far away from time changes. But almost every seasonal time change there is a bug report from someone who has an automated process that ran right at the same time as time change giving them a surprising result and they are filing a bug that it gave them the wrong answer, because there was no 2am that day, or maybe there were two 2ams that day, or something. That's why it is better to test for days using noon as a reference. And why when checking for months it is better to test for months away from the change of month. Really the 10th or the 20th would be as good as the 15th but the 15th is in the middle of every month and why it ended up getting into the FAQ recommendation. > $ dateadd now -1mo -f"%Y-%m-%d %H:%M:%S" > 2021-02-28 09:37:27 I don't know anything about dateadd and it is not part of GNU Coreutils. Bob