From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Richard Lawrence Newsgroups: gmane.emacs.bugs Subject: bug#74869: [PATCH] Add predicates for decoded times and time deltas Date: Sat, 14 Dec 2024 17:11:41 +0100 Message-ID: <8734iqp7lu.fsf@recursewithless.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="9644"; mail-complaints-to="usenet@ciao.gmane.io" To: 74869@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Dec 14 17:13:17 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1tMUlX-0002M5-9y for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 14 Dec 2024 17:13:17 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tMUlN-0003za-9c; Sat, 14 Dec 2024 11:13:05 -0500 Original-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 1tMUlL-0003yq-Bi for bug-gnu-emacs@gnu.org; Sat, 14 Dec 2024 11:13:03 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tMUlL-0004SD-3H for bug-gnu-emacs@gnu.org; Sat, 14 Dec 2024 11:13:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:From:To:Subject; bh=bkSRXg7vAx15DGOInaColTSdYxNHbqnH93FhfYvl/PM=; b=amCRtywBoRqbnB+1nMQDLoqwFFE2C/JEfDrDurEMwdqX62+4FE65icYXtfQuzUMhrxQa8yCvC3g5gPjEY9GLuXrPZww9Zlp1Kz2Uc4DyUB6Xh2UMI7WBIT+djqY5N5Cox+LkgWR3uanuXjY0gvoEP9ciA3PQnxGq9mR0WXwTSZKbckD/C4Ab6o/hZjwxSRi9pB4F0cDiWZ9OwpUmEnCE0iWmMHhJErT/Gtw2IFINMv5EFYnrloNBTkHqKZ2ZPBYykSv6KSso/itiwBYe73BSNXPnsUY8daPdjUBlQfT+Gg5tz+dZHbg+xWtrrvm6qBrhOZTr9yz2UuHOAbOINlIpFQ==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tMUlK-0001WO-Qp for bug-gnu-emacs@gnu.org; Sat, 14 Dec 2024 11:13:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Richard Lawrence Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 14 Dec 2024 16:13:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 74869 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.17341927315731 (code B ref -1); Sat, 14 Dec 2024 16:13:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 14 Dec 2024 16:12:11 +0000 Original-Received: from localhost ([127.0.0.1]:48105 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tMUkR-0001UD-4M for submit@debbugs.gnu.org; Sat, 14 Dec 2024 11:12:11 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:46848) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tMUkJ-0001Sp-L7 for submit@debbugs.gnu.org; Sat, 14 Dec 2024 11:12:05 -0500 Original-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 1tMUkI-0003ds-DH for bug-gnu-emacs@gnu.org; Sat, 14 Dec 2024 11:11:58 -0500 Original-Received: from fhigh-b1-smtp.messagingengine.com ([202.12.124.152]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tMUkC-0004Gi-R3 for bug-gnu-emacs@gnu.org; Sat, 14 Dec 2024 11:11:58 -0500 Original-Received: from phl-compute-12.internal (phl-compute-12.phl.internal [10.202.2.52]) by mailfhigh.stl.internal (Postfix) with ESMTP id 720F5254015C for ; Sat, 14 Dec 2024 11:11:49 -0500 (EST) Original-Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-12.internal (MEProxy); Sat, 14 Dec 2024 11:11:49 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= recursewithless.net; h=cc:content-type:content-type:date:date :from:from:in-reply-to:message-id:mime-version:reply-to:subject :subject:to:to; s=fm3; t=1734192709; x=1734279109; bh=bkSRXg7vAx 15DGOInaColTSdYxNHbqnH93FhfYvl/PM=; b=u33mnkg1+CtnLK/SkXCY3KXFV/ DpcCRHOnx5zupPZe1pU5Y5nVNs6FO8gYOUmwEl5zGnvrGH89MCc7ul5FsIaQ23kh bc9gBiL9H2699c1JbcZimfc9UryB6QouD7mGcBVaP5LW7kLbdT3BbHRZLzJQqx4P xCr8vZ58YJaUltsdaTInzbRLemtLzI/5S8RMluJBXPW7tzCB5IeWeZCG+MLRha7m AOmdVuLKhUJn53eRtAzEThuwvqpKjYmcJwUuptrmqEUgkcWUyLKDhmCzPLQphe82 F8AQ9yX/xcEbjWtEbhsz6ol0uWEur/Y7cAS/qYQxROgwqg1uobEb3aTZquGg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:message-id :mime-version:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1734192709; x= 1734279109; bh=bkSRXg7vAx15DGOInaColTSdYxNHbqnH93FhfYvl/PM=; b=Z RyN54u8+x9mhSWJL3RCpJUdy3y+A4GdiUWVKligRzx4LkAXdwZqyfyzkXIiWHGnH TtWRDVhGPVlSwRNOKG0a0A3Pj7wnEOB4/1MWqbbGv0rl6ECAjHGneZ0TkOfI96PZ zfa3JR80TtoP4h9SpJYudioPUGeBOlOExQj9kztetm5B1hcKit7yJCvIqlNiMgvT MRxqWEmACeJSperMEtAHn0RX3LQCG2eLAMkmd4wKaGMycP7wAWgWJfSBJ+X17H/R AfJ0yYaik97wWFhFHWplXILOMB/n38e2StXthMIwfHLSOD3XCYpZdYNrTlN4MRkp dtN7IDUSqwkkTIrUJvzOA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrkeelgdekfecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecunecujfgurhephffvufffkf ggtgesmhdtreertddttdenucfhrhhomheptfhitghhrghrugcunfgrfihrvghntggvuceo rhiflhesrhgvtghurhhsvgifihhthhhlvghsshdrnhgvtheqnecuggftrfgrthhtvghrnh epieduleffheekhfeihfetgeekveelieetvefhteeggefgudevueejveeghfekleelnecu vehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprhiflhesrh gvtghurhhsvgifihhthhhlvghsshdrnhgvthdpnhgspghrtghpthhtohepuddpmhhouggv pehsmhhtphhouhhtpdhrtghpthhtohepsghughdqghhnuhdqvghmrggtshesghhnuhdroh hrgh X-ME-Proxy: Feedback-ID: if7394488:Fastmail Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Sat, 14 Dec 2024 11:11:48 -0500 (EST) Received-SPF: pass client-ip=202.12.124.152; envelope-from=rwl@recursewithless.net; helo=fhigh-b1-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_PASS=-0.001, T_SPF_HELO_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:297058 Archived-At: --=-=-= Content-Type: text/plain Tags: patch This is a rough draft of a patch to add two new predicates related to decoded times: `decoded-time-p', which checks that a value is a decoded time (as documented in `decode-time'), and `decoded-time-delta-p', which checks that a value is a time delta (as documented in `decoded-time-add'). Some questions: 1) Should these functions go in simple.el? I put them there because that is where the structure definition for decoded-time is. (The definition does not generate a predicate automatically because it uses :type but not :named; see Info node `(cl)Structures'.) But at least `decoded-time-delta-p' might be better off in time-date.el, which is where `decoded-time-add' is defined. 2) Should `decoded-time-p' also check the weekday slot of decoded times? See the FIXME comment in the middle of the function: `make-decoded-time' neither sets this slot nor provides an argument to let the caller set it. This is apparently intentional: there is a comment in the definition of `make-decoded-time', ;; Do not set decoded-time-weekday or decoded-time-dst, ;; as encode-time can infer them well enough when unknown. but if the slot is not meant to be set I don't understand why it's there. It would be useful, for iCalendar purposes, to have the weekday slot automatically calculated from the date values when a decoded time is constructed. I'm not sure if this use was just not envisioned, or if there was a more substantial reason not to do it in make-decoded-time. Hopefully I got the commit message right this time, but please let me know if that needs tweaking too... Best, Richard --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=0001-Add-predicates-for-decoded-times-and-time-deltas.patch >From a9075f0dc459c1b3b0c3d2e4b7eb33553d7adac9 Mon Sep 17 00:00:00 2001 From: Richard Lawrence Date: Sat, 14 Dec 2024 16:36:45 +0100 Subject: [PATCH] Add predicates for decoded times and time deltas * lisp/simple.el (decoded-time-p): Add predicate for decoded times. * lisp/simple.el (decoded-time-delta-p): Add predicate for time deltas. --- lisp/simple.el | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/lisp/simple.el b/lisp/simple.el index f2ee4a5df67..ac06a49402f 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -11228,6 +11228,41 @@ capitalize-dwim the number of seconds east of Greenwich.") ) +(defun decoded-time-p (val) + "Return non-nil if VAL is a decoded time. +See `decode-time' for the expected format of VAL." + (and (listp val) + (length= val 9 + ;; TODO: according to `decode-time', sec can also be a "Lisp + ;; timestamp"...is there a predicate for that? + (cl-typep (decoded-time-second val) '(integer 0 60)) + (cl-typep (decoded-time-minute val) '(integer 0 59)) + (cl-typep (decoded-time-hour val) '(integer 0 23)) + (cl-typep (decoded-time-day val) '(integer 1 31)) + ;; FIXME: the weekday slot value should ideally be automatically + ;; calculated from month, day, and year on construction, like: + ;; (calendar-day-of-week (list month day year)) + ;; `make-decoded-time' does not do this at present, and also has no + ;; option to set the weekday slot. + ;; (cl-typep (decoded-time-weekday val) '(integer 0 6)) + (cl-typep (decoded-time-month val) '(integer 1 12)) + (cl-typep (decoded-time-year val) 'integer) + (cl-typep (decoded-time-dst val) '(member t nil -1)) + (cl-typep (decoded-time-zone val) '(or integer null))))) + +(defun decoded-time-delta-p (val) + "Return non-nil if VAL is a decoded time delta of the sort required by +`decoded-time-add'." + (and (listp val) + (length= val 9) + ;; weekday, dst, zone can be ignored + (cl-typep (decoded-time-second val) '(or null integer)) + (cl-typep (decoded-time-minute val) '(or null integer)) + (cl-typep (decoded-time-hour val) '(or null integer)) + (cl-typep (decoded-time-day val) '(or null integer)) + (cl-typep (decoded-time-month val) '(or null integer)) + (cl-typep (decoded-time-year val) '(or null integer)))) + ;; Document that decoded-time-dst is problematic on 6-element lists. ;; It should return -1 indicating unknown DST, but currently returns ;; nil indicating standard time. -- 2.39.5 --=-=-=--