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#74848: [PATCH] calendar: check for presuppositions in `calendar-date-is-valid-p' Date: Fri, 13 Dec 2024 13:02:36 +0100 Message-ID: <87o71fpz8j.fsf@ohm.mail-host-address-is-not-set> 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="2318"; mail-complaints-to="usenet@ciao.gmane.io" To: 74848@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Dec 13 13:03:27 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 1tM4OD-0000OQ-Ss for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 13 Dec 2024 13:03:27 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tM4O1-0007Ww-Lh; Fri, 13 Dec 2024 07:03:14 -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 1tM4Nq-0007Wb-TX for bug-gnu-emacs@gnu.org; Fri, 13 Dec 2024 07:03:04 -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 1tM4Nq-0008Bg-Kg for bug-gnu-emacs@gnu.org; Fri, 13 Dec 2024 07:03:02 -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=vAvkamcwai46rvd8rzMvto75Fyq2cTJjPlSJ8ZuTbQI=; b=ar8byse88Y1poWA1Y+WQRS8Rjpq7Bv+kSzdBxT4NHhmo+QVhh5hy5xQJ3VhQWLKJ5A2fX4iIu8QBJY0ngxWTkSYz5f/+dHeTMoGPrraikKrLf/cmPI8aNIud6U+ZWdB/F6bSn9oQnxPvaV0PclaeBbkX4wjcFHOO/FljA+B/gsF3wNWSioYVM/tqVTj3re/zZNNO02aZDQG0FrGEOduR8ejrOaKGUJfdHLbQ6X+5X5Hf2JaI7JncGaJ2GlH5yjXlwYxjHThXTq+NidacW5jp3bOFydseizqiRY5zcee0T4Jq1yYu7gyWMSwWyx3mlnYsOYv6Q93BuqlPCHJsIqr4dg==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tM4Nq-0002L6-0x for bug-gnu-emacs@gnu.org; Fri, 13 Dec 2024 07:03: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: Fri, 13 Dec 2024 12:03:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 74848 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.17340913698960 (code B ref -1); Fri, 13 Dec 2024 12:03:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 13 Dec 2024 12:02:49 +0000 Original-Received: from localhost ([127.0.0.1]:41866 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tM4Nc-0002KR-CB for submit@debbugs.gnu.org; Fri, 13 Dec 2024 07:02:49 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:42138) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tM4NY-0002KD-T6 for submit@debbugs.gnu.org; Fri, 13 Dec 2024 07:02:46 -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 1tM4NX-0007Sv-Tj for bug-gnu-emacs@gnu.org; Fri, 13 Dec 2024 07:02:44 -0500 Original-Received: from fout-a3-smtp.messagingengine.com ([103.168.172.146]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tM4NW-00089f-3Q for bug-gnu-emacs@gnu.org; Fri, 13 Dec 2024 07:02:43 -0500 Original-Received: from phl-compute-03.internal (phl-compute-03.phl.internal [10.202.2.43]) by mailfout.phl.internal (Postfix) with ESMTP id 775E11384156 for ; Fri, 13 Dec 2024 07:02:39 -0500 (EST) Original-Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-03.internal (MEProxy); Fri, 13 Dec 2024 07:02:39 -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=1734091359; x=1734177759; bh=vAvkamcwai 46rvd8rzMvto75Fyq2cTJjPlSJ8ZuTbQI=; b=qnRqCOlCT3LVR14N8NmG49+DCb 8XlmccR1lVanVRZCrnXErqDn3ewZ01OLvg+kEXHuMkIjgv894E7rKsXQDPTkH7sE lKMKKguuW98MaVeHNUKWsYXsK7CqZjWkHJj6iOwRnmJs47m3gYRlsrCBRMUSAzKJ NcxecUORtTmbVI1glYt8ibqLf/zId1sHIoA2u7xJFon+50nWA2fUWUnvi+0qCHCR nAm5HHxz6ulBX3mcuupCD+4HkMMUuxITgKdoA3KAu6OPfkzUd0pk1Clq1KCtk5pQ Hr7/1yuULp4dD2kZO4bsMy8WnTNnSEMHJlPZSde2jMJrJ5Lu3QHCWeX/68ag== 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=1734091359; x= 1734177759; bh=vAvkamcwai46rvd8rzMvto75Fyq2cTJjPlSJ8ZuTbQI=; b=n F4frzoaOa4LH54SdfozHZ9oVoS7bOsOArngTUddcz18RQcZkRIelOoB+sc5DjTRj ASRZOlNuKCRN5S/C/DOTmOKLFl0IMo/2BfQ3fZS9ZqVhIwUFqV64Mni3SyXdLxPR JzzPt0GCVf+n+hcSQN8DbSJCJUEkTpPCoCcHLhums8ec0Z9+a1ROW3iJ2IbQVY7j Mh/BP/+obuEjinOGJlhpxJsfN3BXuIq8QXGzToEXkYZiG+bUjRbQc0GmVgAE0SQI mvWOwmP2h+s+cSYLFDmk+RFKeuIahctdeZxMQTiKhl7YxDSjqV+xu5JoBqodYTYZ WCAigOtWUhj1YyuZwPa1w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrkeejgdefhecutefuodetggdotefrodftvf 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 ; Fri, 13 Dec 2024 07:02:38 -0500 (EST) Received-SPF: pass client-ip=103.168.172.146; envelope-from=rwl@recursewithless.net; helo=fout-a3-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_HELO_PASS=-0.001, SPF_PASS=-0.001 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:296971 Archived-At: --=-=-= Content-Type: text/plain Tags: patch Tags: patch Hi all, Here is a patch to make calendar-date-is-valid-p return nil, instead of signaling an error, when it is passed a value that isn't a list of the form (MONTH DAY YEAR). This (a) makes the function a proper predicate, as its name suggests, which (b) is necessary in some of the new iCalendar code I've been working on (to be posted soon). (I've deleted the build information about the Emacs I'm sending from, because it is different from Emacs master, against which the patch is formatted.) This is my first time submitting a patch with submit-emacs-patch, so please let me know if I did anything wrong. Thanks! Richard --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=0001-calendar-check-for-presuppositions-in-calendar-date-.patch >From 794c27fac28260498b26e1cb60aa7576ca487f08 Mon Sep 17 00:00:00 2001 From: Richard Lawrence Date: Fri, 13 Dec 2024 10:41:02 +0100 Subject: [PATCH] calendar: check for presuppositions in `calendar-date-is-valid-p' This function previously would signal an error if passed a value which was not a three-element list of integers, making it not unusable as a predicate for valid date values. --- lisp/calendar/calendar.el | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/lisp/calendar/calendar.el b/lisp/calendar/calendar.el index 345687d1775..7c883617aca 100644 --- a/lisp/calendar/calendar.el +++ b/lisp/calendar/calendar.el @@ -2459,19 +2459,22 @@ calendar-nongregorian-visible-p (defun calendar-date-is-valid-p (date) "Return t if DATE is a valid date." - (let ((month (calendar-extract-month date)) - (day (calendar-extract-day date)) - (year (calendar-extract-year date))) - (and (<= 1 month) (<= month 12) - ;; (calendar-read-date t) used to return a date with day = nil. - ;; Should not be valid (?), since many funcs prob assume integer. - ;; (calendar-read-date 'noday) returns (month year), which - ;; currently results in calendar-extract-year returning nil. - day year (<= 1 day) (<= day (calendar-last-day-of-month month year)) - ;; BC dates left as non-valid, to suppress errors from - ;; complex holiday algorithms not suitable for years BC. - ;; Note there are side effects on calendar navigation. - (<= 1 year)))) + (when (and (listp date) + (length= date 3)) + (let ((month (calendar-extract-month date)) + (day (calendar-extract-day date)) + (year (calendar-extract-year date))) + (and (integerp month) (integerp day) (integerp year) + (<= 1 month) (<= month 12) + ;; (calendar-read-date t) used to return a date with day = nil. + ;; Should not be valid (?), since many funcs prob assume integer. + ;; (calendar-read-date 'noday) returns (month year), which + ;; currently results in calendar-extract-year returning nil. + day year (<= 1 day) (<= day (calendar-last-day-of-month month year)) + ;; BC dates left as non-valid, to suppress errors from + ;; complex holiday algorithms not suitable for years BC. + ;; Note there are side effects on calendar navigation. + (<= 1 year))))) (defun calendar-date-equal (date1 date2) "Return t if the DATE1 and DATE2 are the same." -- 2.39.5 --=-=-=--