From: Richard Lawrence <rwl@recursewithless.net>
To: 74848@debbugs.gnu.org
Subject: bug#74848: [PATCH] calendar: check for presuppositions in `calendar-date-is-valid-p'
Date: Fri, 13 Dec 2024 13:02:36 +0100 [thread overview]
Message-ID: <87o71fpz8j.fsf@ohm.mail-host-address-is-not-set> (raw)
[-- Attachment #1: Type: text/plain, Size: 657 bytes --]
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
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-calendar-check-for-presuppositions-in-calendar-date-.patch --]
[-- Type: text/patch, Size: 2622 bytes --]
From 794c27fac28260498b26e1cb60aa7576ca487f08 Mon Sep 17 00:00:00 2001
From: Richard Lawrence <rwl@recursewithless.net>
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
reply other threads:[~2024-12-13 12:02 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87o71fpz8j.fsf@ohm.mail-host-address-is-not-set \
--to=rwl@recursewithless.net \
--cc=74848@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).