diff --git a/NEWS.org b/NEWS.org index a9806422..2f808e7a 100644 --- a/NEWS.org +++ b/NEWS.org @@ -79,8 +79,9 @@ ~fields~/~field~ (alists with metadata about database fields). See the SCM reference documentation for further details (1.14.3). - - add procedures ~date-object~ to get a message's sent-date as an SRFI-19 - object; and ~utc-offset~ to get the UTC (timezone) offset for a date. + - add procedures ~date-object~ which is like ~date~, but returns message's + sent-date as an SRFI-19 object; and ~utc-offset~ to get the UTC (timezone) + offset for a date. Similarly, add ~changed-object~ to complement ~changed~ (1.14.3) * 1.12 (released on February 24, 2024) diff --git a/scm/mu-scm.scm b/scm/mu-scm.scm index 34b9645a..3fcca830 100644 --- a/scm/mu-scm.scm +++ b/scm/mu-scm.scm @@ -45,6 +45,7 @@ utc-offset changed + changed-object message-id path @@ -377,17 +378,21 @@ I.e., the offset from the UTC for the time the message was sent. (define-method (date-object (message )) "Get an SRFI-19 date object for MESSAGE's sent date. This includes the date and the timezone (if known). #f if not found." - (let ((unix-time (date message)) (offset (utc-offset message))) - (if unix-time - (time-utc->date (make-time 'time-utc 0 unix-time) - (or offset 0)) - #f))) + (when-let ((unix-time (date message))) + (time-utc->date (make-time 'time-utc 0 unix-time) + (or (utc-offset message) 0)))) (define-method (changed (message )) "Get the timestamp for the last change to MESSAGE. This is the number of seconds since epoch; #f if not found." (assoc-ref (message->alist message) 'changed)) +(define-method (changed-object (message )) + "Get an SRFI-19 date object for MESSAGE's last-change. +No time-zone offset is defined. #f if not found." + (when-let ((unix-time (changed message))) + (time-utc->date (make-time 'time-utc 0 unix-time)))) + (define-method (path (message )) "Get the file-system path for MESSAGE or #f if not found." (assoc-ref (message->alist message) 'path)) @@ -400,11 +405,8 @@ A symbol, either 'high, 'low or 'normal, or #f if not found." (define-method (language (message )) "Get the ISO-639-1 language code for the MESSAGE as a symbol, if detected. Return #f otherwise." - (let ((lang (assoc-ref (message->alist message) 'language))) - (if lang - (string->symbol lang) - #f))) -;; if-let would be nice! + (when-let ((lang (assoc-ref (message->alist message) 'language))) + (string->symbol lang))) (define-method (size (message )) "Get the size of the MESSAGE in bytes or #f if not available." @@ -426,10 +428,9 @@ the empty list." "Get the oldest (first) reference for MESSAGE, or message-id if there are none. If neither are available, return #f. This is method is useful to determine the thread a message is in." - (let ((refs (references message))) - (if (and refs (not (null? refs))) - (car refs) - (message-id message)))) + (if-let* ((refs (references message)) (_ (not (null? refs)))) + (car refs) + (message-id message))) (define-method (mailing-list (message )) "Get the mailing-list id for MESSAGE or #f if not available." diff --git a/scm/mu-scm.texi b/scm/mu-scm.texi index 40294f3a..37155c3b 100644 --- a/scm/mu-scm.texi +++ b/scm/mu-scm.texi @@ -840,16 +840,21 @@ Does this message include a calendar invitation? Returns @t{#t} or @code{#f}. @deffn {Scheme Procedure} changed message @end deffn +@deffn {Scheme Procedure} changed-object message +@end deffn Get the time of the message's last change (through @t{mu}), or @code{#f} if there is none. The time is expressed the data as the number of seconds since epoch, @t{time_t}. For example: @lisp -(last-change msg) +(changed msg) => 1703336567 @end lisp +@code{changed-object} returns a value as a SRFI-19 date object, similar to +@code{date-object}, but without any time-zone offset. + @deffn {Scheme Procedure} priority message @end deffn Get the message's priority. This is a symbol, either @t{high}, @t{normal} or