From unknown Sat Aug 09 09:35:45 2025 X-Loop: help-debbugs@gnu.org Subject: bug#79078: date command: Relative dates fail with ISO 8601 time format and no zone Resent-From: Geoff Kuenning Original-Sender: "Debbugs-submit" Resent-CC: bug-coreutils@gnu.org Resent-Date: Wed, 23 Jul 2025 07:57:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 79078 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: To: 79078@debbugs.gnu.org X-Debbugs-Original-To: bug-coreutils@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.175325742115293 (code B ref -1); Wed, 23 Jul 2025 07:57:02 +0000 Received: (at submit) by debbugs.gnu.org; 23 Jul 2025 07:57:01 +0000 Received: from localhost ([127.0.0.1]:48015 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ueULV-0003yY-9p for submit@debbugs.gnu.org; Wed, 23 Jul 2025 03:57:01 -0400 Received: from lists.gnu.org ([2001:470:142::17]:58174) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1ueULS-0003yB-F4 for submit@debbugs.gnu.org; Wed, 23 Jul 2025 03:56:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ueULH-0004IS-Tu for bug-coreutils@gnu.org; Wed, 23 Jul 2025 03:56:49 -0400 Received: from mallet.cs.hmc.edu ([134.173.42.59]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ueULF-0004Rn-3b for bug-coreutils@gnu.org; Wed, 23 Jul 2025 03:56:47 -0400 Received: from bow.cs.hmc.edu (bow-vpn.cs.hmc.edu [10.81.251.5]) by mallet.cs.hmc.edu (Postfix) with ESMTPS id 105C3BA0AFC for ; Wed, 23 Jul 2025 00:56:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cs.hmc.edu; s=mallet; t=1753257395; bh=SXCVP/E29LUTaZY0MUbukvNPnhg8f1Lrti8cTb1aqXw=; h=From:To:Subject:Date; b=aGZH6ngBore3PrNK6h8tGzkTm4aSwaCtxxboYlWCEAZ2BQJvcuYC/JTElrY74fy0a isgmLL4Lu35/mu7+iec/KVFfQaNo47jSoeM/NqbUjM39ANEi055pYZd64YLbOJJTpe GuEiQqPxYV4Cj4flCcrpmooFlkj+ylaIZ0rLluTA= Received: by bow.cs.hmc.edu (Postfix, from userid 13409) id D6E51B3C17EB; Wed, 23 Jul 2025 00:56:34 -0700 (PDT) From: Geoff Kuenning User-Mail-Address: geoff@cs.hmc.edu Date: Wed, 23 Jul 2025 00:56:34 -0700 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=134.173.42.59; envelope-from=geoff@cs.hmc.edu; helo=mallet.cs.hmc.edu X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: 0.9 (/) 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.1 (/) Tested on coreutils 9.5 (gentoo) and 8.32 (OpenSuSE). There seems to be an interesting interaction in the code that=20 parses relative dates in the --date switch; relative=20 specifications used with ISO 8601 base dates can give incorrect=20 results. All tests below were run with a time zone of America/Los_Angeles. The following date commands work fine: $ date -d '2025-01-20T12:00:00Z +180 days' Sat Jul 19 05:00:00 AM PDT 2025 $ date -d '2025-01-20T12:00:00-0800 +180 days' Sat Jul 19 01:00:00 PM PDT 2025 However, omitting the time zone gives a surprising result that's=20 only one day later, and at a different time: $ date -d '2025-01-20T12:00:00 +180 days' Tue Jan 21 01:40:00 AM PST 2025 Omitting the zone offset, but not using a relative expression,=20 works: $ date -d '2025-01-20T12:00:00' Mon Jan 20 12:00:00 PM PST 2025 Using hours in a relative expression without a time zone gives a=20 different kind of error: $ date -d '2025-01-20T12:00:00 +4320 hours' date: invalid date =E2=80=982025-01-20T12:00:00 +4320 hours=E2=80=99 But including the zone shows that the +4320 hours isn't the=20 problem: $ date -d '2025-01-20T12:00:00-0800 +4320 hours' Sat Jul 19 01:00:00 PM PDT 2025 Using a non-ISO date format works with relative dates: date -d '12:00 PM Jan 20, 2025 + 180 days' Sat Jul 19 12:00:00 PM PDT 2025 Note: I haven't tested with all of the other accepted date=20 formats. A final note: from my POV, it would be fine to just reject ISO=20 8601 strings that omitted the timezone. However, in that case an=20 error more informative than just "invalid date" would be helpful=20 to users. --=20 Geoff Kuenning geoff@cs.hmc.edu=20 https://www.cs.hmc.edu/~geoff/ "There's a true schizophrenia where if you say to voters, you=20 know, do you think the federal government spends too much money and they=20 should spend less, they say yeah, absolutely. Then you name specific=20 things, like Pell grants for students and they say, no, not that. How=20 'bout NIH, medical research funding? Nah, you really shouldn't cut=20 that. And pretty soon you've proved that what the American public is=20 against is arithmetic." -- Bill Gates, March 10, 2011 From unknown Sat Aug 09 09:35:45 2025 X-Loop: help-debbugs@gnu.org Subject: bug#79078: date command: Relative dates fail with ISO 8601 time format and no zone Resent-From: =?UTF-8?Q?P=C3=A1draig?= Brady Original-Sender: "Debbugs-submit" Resent-CC: bug-coreutils@gnu.org Resent-Date: Wed, 23 Jul 2025 10:50:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 79078 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: To: Geoff Kuenning , 79078@debbugs.gnu.org Received: via spool by 79078-submit@debbugs.gnu.org id=B79078.175326779827981 (code B ref 79078); Wed, 23 Jul 2025 10:50:01 +0000 Received: (at 79078) by debbugs.gnu.org; 23 Jul 2025 10:49:58 +0000 Received: from localhost ([127.0.0.1]:48671 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ueX2s-0007HF-9I for submit@debbugs.gnu.org; Wed, 23 Jul 2025 06:49:58 -0400 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]:55807) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1ueX2q-0007Gz-6w; Wed, 23 Jul 2025 06:49:56 -0400 Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-3a531fcaa05so3083356f8f.3; Wed, 23 Jul 2025 03:49:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1753267790; x=1753872590; darn=debbugs.gnu.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :sender:from:to:cc:subject:date:message-id:reply-to; bh=RtbKxdcH4qvlHrAbQaG9VSWThfma31TDosj8lWi8aJc=; b=dXBDeIDEInxeqY17B1IWnppGQraLzwONhcBhoFU9cP5yzs4zyqa8ZYf+Q587gqFP+A ImJYGFc6W03z6GqaWndQilbXk2sKQB0UYt5IVo66fI/1y9N/Ff+NmHAcPWofQW4sp8AJ 5ZWCkm24qFtEMH92evyRPMTtwoCnhW3VycWVBqQ53ACs3QVQW3YjJlZi27FJykRM8uGa yiK/od1d9zjRdqf4BMLS8ES16h8lhBzWiKtK5DBYcnoBef+kLEwVdkAWACSOMBWIWx91 JCBj+jDTKCptVSc1NboJUNLo8ssz894ftlx5X8frfNNcMFsXBlYBYIPt9tVgM57SG03J uQuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753267790; x=1753872590; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :sender:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=RtbKxdcH4qvlHrAbQaG9VSWThfma31TDosj8lWi8aJc=; b=JT2/faBfwEChS/cCQ60F8ZzSkeBgfVRZ5wLlzmaxqRw8tk2/vRaOZPjbIiMQSmsNt4 yedRaXx2vXU4DhhZPhTgW7vXzu9NMYCUn/G/xjF2dQCI9ENHW5Zn+uyNyvMWpwq0P5ok DQ+9+wXWc9xybCOLJXTIILpkdRKNbPgkQl/QnVbUxr8qlJjOn83U8oVDiWzS09U3DZ4k blOakB9zf4xIk9RlCPqRqO7y0uS3sAxNSb50++o8XqRURWJUnsO4lgJdJkxz+3MzqKml mgUNmorWIVxMdNnxf03ka39xQh6FUv/4OWMwur2m7KTZ0PcF+wBo0kAl+l0SDw7bkiMZ 6Nuw== X-Forwarded-Encrypted: i=1; AJvYcCUfqCFpoNbSr8gljqDOBH8ZgjTB+hGlAjyPVTVWb2ndjSDKRHT3eiPNHXqYhbbGRrmIzxx8Jw==@debbugs.gnu.org, AJvYcCX+05QPxSmdtHFTGNnaOcX+gku8azk8LmhKphFZ/iIg6vsyOzYhUJTX1P2IqHqk9B8CJ8iwg+rhBg==@debbugs.gnu.org X-Gm-Message-State: AOJu0YwktgcK/12RK3ZQN/jFIiJb5N68q5CbvDoiVagXpnNtDdovkluR aSXNAdDGMX1AlJjENLnypac1YgNYdTN9tH1JT8a3VnBsMSnu/zxykIaC X-Gm-Gg: ASbGncsbPHEBG3kx6m6uZ9mbHRqO/L3LvEfeV3iGWOCCxPjEpn7byK494+TL8C/8x7v MSvVMSZUHySmkWY362Z7+sDb1LDwRmT4Y8Mci4KkGCY+UVhfH+L/2T0aUvlzIGDhZuiWQj9YP6u IizSjm6KK2YmjFgUlV+mIJGQ6mbyMy+G+opxGMwSyD9Zu1eMCLxwhTvlKm5lbc2VdI43JAAzG8E P++lBQP00CrxL3PNyVR5ZE1/dWFNqaScK4q14/kS+DQ+0v9e2iTBxw8EJ2RsGNRNJ37yD/yC2Ro Un/S6zNe+P9NV5ujG7HKEw1rnFEkRWbX/bDNyNg7aJFUqKpEfEYOIH8j6UtzwseNXNfD12zbdhe JkTUVTveqB3HByLJFXbhgMuFLGz0cwelGSuXph78rqJpexAU7QyJvcYc7vXhUIpZ7+oP9fJ1UFF pupw== X-Google-Smtp-Source: AGHT+IF0SURAlih+u2iNh3o7Jsc4/qqvHo/inGS4MLaIO4r76bh7h9jXBhIqXi+LCRxMUBYLWG6cfQ== X-Received: by 2002:a5d:5f47:0:b0:3a8:38b4:1d55 with SMTP id ffacd0b85a97d-3b768ef5b5fmr2146522f8f.28.1753267789407; Wed, 23 Jul 2025 03:49:49 -0700 (PDT) Received: from [192.168.1.31] (86-44-211-146-dynamic.agg2.lod.rsl-rtd.eircom.net. [86.44.211.146]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-3b61ca48c40sm16207564f8f.58.2025.07.23.03.49.48 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 23 Jul 2025 03:49:49 -0700 (PDT) Message-ID: Date: Wed, 23 Jul 2025 11:49:47 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Beta References: Content-Language: en-US From: =?UTF-8?Q?P=C3=A1draig?= Brady In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: 0.2 (/) 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 (/) tag 79078 notabug close 79078 stop Notes below... On 23/07/2025 08:56, Geoff Kuenning via GNU coreutils Bug Reports wrote: > Tested on coreutils 9.5 (gentoo) and 8.32 (OpenSuSE). > > There seems to be an interesting interaction in the code that > parses relative dates in the --date switch; relative > specifications used with ISO 8601 base dates can give incorrect > results. > > All tests below were run with a time zone of America/Los_Angeles. > > The following date commands work fine: > > $ date -d '2025-01-20T12:00:00Z +180 days' > Sat Jul 19 05:00:00 AM PDT 2025 > $ date -d '2025-01-20T12:00:00-0800 +180 days' > Sat Jul 19 01:00:00 PM PDT 2025 > > However, omitting the time zone gives a surprising result that's > only one day later, and at a different time: > > $ date -d '2025-01-20T12:00:00 +180 days' > Tue Jan 21 01:40:00 AM PST 2025 Adding --debug shows what's happening here: $ date --debug -d '2025-01-20T12:00:00 +180 days' date: parsed datetime part: (Y-M-D) 2025-01-20 12:00:00 UTC+02:20 date: parsed relative part: +1 day(s) I.e. the "+180" is taken as a POSIX timezone offset in minutes, and the "days" is taken as a relative +1 day. There are lots of combinations and edge cases in date inputs unfortunately. cheers, Padraig