unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: Richard Lawrence <rwl@recursewithless.net>
To: Paul Eggert <eggert@cs.ucla.edu>
Cc: 74689@debbugs.gnu.org
Subject: [bug#74689] [PATCH] Add predicates for decoded times and time deltas
Date: Sat, 28 Dec 2024 16:56:39 +0100	[thread overview]
Message-ID: <875xn3vm14.fsf@recursewithless.net> (raw)
In-Reply-To: <468ca0ab-a4aa-41ed-8f6c-260940f3f9f3@cs.ucla.edu>

Paul Eggert <eggert@cs.ucla.edu> writes:

> What's the use case for these proposed predicates? I'm finding it hard 
> to review the patch without knowing what it's for.

Well, one reason is just general completeness: it's always useful, for
any type, to be able to check that a value is of that type before
passing it to functions that expect that type, e.g. decoded-time-add.

More concretely, in the new implementation of iCalendar/RFC5545 I have
been working on (see Bug#74994), I decided to represent iCalendar times
and date-times as decoded times (with the idea that decoded-times are
the "native" Emacs way to represent these values). This in turn means I
need a way to verify that values are of this type before e.g. doing
calendar arithmetic with them, or serializing a decoded-time value back
out to a string. There are also many places where the iCalendar standard
allows both dates and date-times as values, and I need to dispatch based
on the type at runtime: e.g. to get the month, I need to use
`calendar-extract-month' with a plain date value, but
`decoded-time-month' with a date-time value. I need type predicates to
do such dispatching.

> Surely this should be in time-date.el rather than simple.el.

OK, makes sense -- I'll move it there.

> The implementation of decoded-time-p seems complicated and doesn't match 
> what decode-time produces. 

What seems complicated about it? (Just the use of cl-typep? That can
easily be removed.) What are the mismatches with what decode-time
produces?

> Wouldn't it be simpler to call
> (ignore-errors (equal val (decode-time (encode-time val))))?

I could certainly change it to that if it's preferable, though that
doesn't strike me personally as simpler: it's fewer lines of code, but
rests on implicit assumptions about the implementation details of
decode-time and encode-time. To me it seems simpler to explicitly encode
the constraints that decoded times are supposed to obey.

In any case, maybe the problem here is actually my original choice to
represent iCalendar date-times as decoded times. If decoded times aren't
right for that purpose, I could instead define a new type; but that
would mean I won't be able to re-use all the functions that already work
with decoded-times, unless I can adapt them to work with the new type,
and might end up writing a lot of boilerplate or duplicated code.

Hope that helps clarify things!




  reply	other threads:[~2024-12-28 16:40 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-04 16:11 [bug#74689] [PATCH 0/3] fix non-x86 world rebuild Zheng Junjie
2024-12-04 16:13 ` [bug#74689] [PATCH 1/3] Partial revert "gnu: make-bootstrap: Update gcc-static to gcc-14, for the 64bit Hurd." Zheng Junjie
2024-12-04 16:31   ` Janneke Nieuwenhuizen
2024-12-04 16:40     ` Janneke Nieuwenhuizen
2024-12-04 17:08     ` Zheng Junjie
2024-12-04 17:13       ` Janneke Nieuwenhuizen
2024-12-04 16:13 ` [bug#74689] [PATCH 2/3] Partial revert "gnu: bootstrap: %bootstrap-glibc: Also fix libm.so." Zheng Junjie
2024-12-04 16:33   ` Janneke Nieuwenhuizen
2024-12-04 16:13 ` [bug#74689] [PATCH 3/3] Partial revert "gnu: bootstrap: %bootstrap-gcc: Also wrap g++ for the 64bit Hurd." Zheng Junjie
2024-12-04 16:46   ` Janneke Nieuwenhuizen
2024-12-04 17:02     ` Zheng Junjie
2024-12-04 16:57 ` [bug#74689] [PATCH v2 1/3] Partial revert "gnu: make-bootstrap: Update gcc-static to gcc-14, " Zheng Junjie
2024-12-04 16:57   ` [bug#74689] [PATCH v2 2/3] Partial revert "gnu: bootstrap: %bootstrap-glibc: Also fix libm.so." Zheng Junjie
2024-12-04 17:06     ` Janneke Nieuwenhuizen
2024-12-04 16:57   ` [bug#74689] [PATCH v2 3/3] Partial revert "gnu: bootstrap: %bootstrap-gcc: Also wrap g++ for the 64bit Hurd." Zheng Junjie
2024-12-04 17:07     ` Janneke Nieuwenhuizen
2024-12-04 17:05   ` [bug#74689] [PATCH v2 1/3] Partial revert "gnu: make-bootstrap: Update gcc-static to gcc-14, " Janneke Nieuwenhuizen
2024-12-10 23:37 ` bug#74689: [PATCH 0/3] fix non-x86 world rebuild Ludovic Courtès
2024-12-28  0:44 ` [bug#74689] [PATCH] Add predicates for decoded times and time deltas Paul Eggert
2024-12-28 15:56   ` Richard Lawrence [this message]
2024-12-28 17:26     ` Paul Eggert

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://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=875xn3vm14.fsf@recursewithless.net \
    --to=rwl@recursewithless.net \
    --cc=74689@debbugs.gnu.org \
    --cc=eggert@cs.ucla.edu \
    /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/guix.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).