emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master bd26eff 03/13: Use decoded time accessors in Gnus


From: Lars Ingebrigtsen
Subject: [Emacs-diffs] master bd26eff 03/13: Use decoded time accessors in Gnus
Date: Tue, 30 Jul 2019 07:12:05 -0400 (EDT)

branch: master
commit bd26eff54779bfd5739c1d663bcabd19246682d8
Author: Lars Ingebrigtsen <address@hidden>
Commit: Lars Ingebrigtsen <address@hidden>

    Use decoded time accessors in Gnus
    
    * lisp/gnus/nnimap.el (nnimap-find-expired-articles):
    * lisp/gnus/nndiary.el (nndiary-compute-reminders)
    (nndiary-last-occurrence, nndiary-next-occurrence):
    * lisp/gnus/message.el (message-make-expires-date):
    * lisp/gnus/gnus-util.el (gnus-seconds-today)
    (gnus-seconds-month, gnus-seconds-year):
    * lisp/gnus/gnus-demon.el (gnus-demon-time-to-step):
    * lisp/gnus/gnus-art.el (article-make-date-line): Use decoded time
    accessors.
---
 lisp/gnus/gnus-art.el   | 14 +++++++-------
 lisp/gnus/gnus-demon.el | 35 +++++++++++++++++++----------------
 lisp/gnus/gnus-util.el  | 14 ++++++++++----
 lisp/gnus/message.el    |  4 ++--
 lisp/gnus/nndiary.el    | 32 +++++++++++++++++---------------
 lisp/gnus/nnimap.el     |  2 +-
 6 files changed, 56 insertions(+), 45 deletions(-)

diff --git a/lisp/gnus/gnus-art.el b/lisp/gnus/gnus-art.el
index 89f5771..a38300e 100644
--- a/lisp/gnus/gnus-art.el
+++ b/lisp/gnus/gnus-art.el
@@ -3598,22 +3598,22 @@ possible values."
          (let ((dtime (decode-time time)))
            (concat
             "Date: the "
-            (number-to-string (nth 3 dtime))
-            (let ((digit (% (nth 3 dtime) 10)))
+            (number-to-string (decoded-time-day dtime))
+            (let ((digit (% (decoded-time-day dtime) 10)))
               (cond
-               ((memq (nth 3 dtime) '(11 12 13)) "th")
+               ((memq (decoded-time-day dtime) '(11 12 13)) "th")
                ((= digit 1) "st")
                ((= digit 2) "nd")
                ((= digit 3) "rd")
                (t "th")))
             " of "
-            (nth (1- (nth 4 dtime)) gnus-english-month-names)
+            (nth (1- (decoded-time-month dtime)) gnus-english-month-names)
             " "
-            (number-to-string (nth 5 dtime))
+            (number-to-string (decoded-time-year dtime))
             " at "
-            (format "%02d" (nth 2 dtime))
+            (format "%02d" (decoded-time-hour dtime))
             ":"
-            (format "%02d" (nth 1 dtime)))))))
+            (format "%02d" (decoded-time-minute dtime)))))))
     (foo
      (format "Date: %s (from Gnus)" date))))
 
diff --git a/lisp/gnus/gnus-demon.el b/lisp/gnus/gnus-demon.el
index cb70d95..b26aaa1 100644
--- a/lisp/gnus/gnus-demon.el
+++ b/lisp/gnus/gnus-demon.el
@@ -176,22 +176,25 @@ marked with SPECIAL."
         (thenHour (elt thenParts 2))
         (thenMin (elt thenParts 1))
         ;; convert time as elements into number of seconds since EPOCH.
-        (then (encode-time 0
-                           thenMin
-                           thenHour
-                           ;; If THEN is earlier than NOW, make it
-                           ;; same time tomorrow.  Doc for encode-time
-                           ;; says that this is OK.
-                           (+ (elt nowParts 3)
-                              (if (or (< thenHour (elt nowParts 2))
-                                      (and (= thenHour (elt nowParts 2))
-                                           (<= thenMin (elt nowParts 1))))
-                                  1 0))
-                           (elt nowParts 4)
-                           (elt nowParts 5)
-                           (elt nowParts 6)
-                           (elt nowParts 7)
-                           (elt nowParts 8)))
+        (then (encode-time
+               0
+               thenMin
+               thenHour
+               ;; If THEN is earlier than NOW, make it
+               ;; same time tomorrow.  Doc for encode-time
+               ;; says that this is OK.
+               (+ (decoded-time-day nowParts)
+                  (if (or (< thenHour (decoded-time-hour nowParts))
+                          (and (= thenHour
+                                  (decoded-time-hour nowParts))
+                               (<= thenMin
+                                   (decoded-time-minute nowParts))))
+                      1 0))
+               (decoded-time-month nowParts)
+               (decoded-time-year nowParts)
+               (decoded-time-weekday nowParts)
+               (decoded-time-dst nowParts)
+               (decoded-time-zone nowParts)))
         (diff (float-time (time-subtract then now))))
     ;; Return number of timesteps in the number of seconds.
     (round diff gnus-demon-timestep)))
diff --git a/lisp/gnus/gnus-util.el b/lisp/gnus/gnus-util.el
index 31421cc..9ccdb83 100644
--- a/lisp/gnus/gnus-util.el
+++ b/lisp/gnus/gnus-util.el
@@ -359,20 +359,26 @@ Symbols are also allowed; their print names are used 
instead."
 (defun gnus-seconds-today ()
   "Return the number of seconds passed today."
   (let ((now (decode-time)))
-    (+ (car now) (* (car (cdr now)) 60) (* (car (nthcdr 2 now)) 3600))))
+    (+ (decoded-time-second now)
+       (* (decoded-time-minute now) 60)
+       (* (decoded-time-hour now) 3600))))
 
 (defun gnus-seconds-month ()
   "Return the number of seconds passed this month."
   (let ((now (decode-time)))
-    (+ (car now) (* (car (cdr now)) 60) (* (car (nthcdr 2 now)) 3600)
-       (* (- (car (nthcdr 3 now)) 1) 3600 24))))
+    (+ (decoded-time-second now)
+       (* (decoded-time-minute now) 60)
+       (* (decoded-time-hour now) 3600)
+       (* (- (decoded-time-day now) 1) 3600 24))))
 
 (defun gnus-seconds-year ()
   "Return the number of seconds passed this year."
   (let* ((current (current-time))
         (now (decode-time current))
         (days (format-time-string "%j" current)))
-    (+ (car now) (* (car (cdr now)) 60) (* (car (nthcdr 2 now)) 3600)
+    (+ (decoded-time-second now)
+       (* (decoded-time-minute now) 60)
+       (* (decoded-time-hour now) 3600)
        (* (- (string-to-number days) 1) 3600 24))))
 
 (defmacro gnus-date-get-time (date)
diff --git a/lisp/gnus/message.el b/lisp/gnus/message.el
index 3f190ed..ea7a282 100644
--- a/lisp/gnus/message.el
+++ b/lisp/gnus/message.el
@@ -5509,8 +5509,8 @@ If NOW, use that time instead."
 
 In posting styles use `(\"Expires\" (make-expires-date 30))'."
   (let* ((cur (decode-time))
-        (nday (+ days (nth 3 cur))))
-    (setf (nth 3 cur) nday)
+        (nday (+ days (decoded-time-day cur))))
+    (setf (decoded-time-day cur) nday)
     (message-make-date (encode-time cur))))
 
 (defun message-make-message-id ()
diff --git a/lisp/gnus/nndiary.el b/lisp/gnus/nndiary.el
index f8ec222..2ad0634 100644
--- a/lisp/gnus/nndiary.el
+++ b/lisp/gnus/nndiary.el
@@ -1264,12 +1264,12 @@ all.  This may very well take some time.")
         (date-elts (decode-time date))
         ;; ### NOTE: out-of-range values are accepted by encode-time. This
         ;; makes our life easier.
-        (monday (- (nth 3 date-elts)
+        (monday (- (decoded-time-day date-elts)
                    (if nndiary-week-starts-on-monday
-                       (if (zerop (nth 6 date-elts))
+                       (if (zerop (decoded-time-weekday date-elts))
                            6
-                         (- (nth 6 date-elts) 1))
-                     (nth 6 date-elts))))
+                         (- (decoded-time-weekday date-elts) 1))
+                     (decoded-time-weekday date-elts))))
         reminder res)
     ;; remove the DOW and DST entries
     (setcdr (nthcdr 5 date-elts) (nthcdr 8 date-elts))
@@ -1343,9 +1343,10 @@ all.  This may very well take some time.")
                 ;; have to know which day is the 1st one for this month.
                 ;; Maybe there's simpler, but decode-time(encode-time) will
                 ;; give us the answer.
-                (let ((first (nth 6 (decode-time
-                                     (encode-time 0 0 0 1 month year
-                                                  time-zone))))
+                (let ((first (decoded-time-weekday
+                              (decode-time
+                               (encode-time 0 0 0 1 month year
+                                            time-zone))))
                       (max (cond ((= month 2)
                                   (if (date-leap-year-p year) 29 28))
                                  ((<= month 7)
@@ -1390,11 +1391,11 @@ all.  This may very well take some time.")
   ;; If there's no next occurrence, returns the last one (if any) which is then
   ;; in the past.
   (let* ((today (decode-time now))
-        (this-minute (nth 1 today))
-        (this-hour (nth 2 today))
-        (this-day (nth 3 today))
-        (this-month (nth 4 today))
-        (this-year (nth 5 today))
+        (this-minute (decoded-time-minute today))
+        (this-hour (decoded-time-hour today))
+        (this-day (decoded-time-day today))
+        (this-month (decoded-time-month today))
+        (this-year (decoded-time-year today))
         (minute-list (sort (nndiary-flatten (nth 0 sched) 0 59) '<))
         (hour-list (sort (nndiary-flatten (nth 1 sched) 0 23) '<))
         (dom-list (nth 2 sched))
@@ -1445,9 +1446,10 @@ all.  This may very well take some time.")
                 ;; have to know which day is the 1st one for this month.
                 ;; Maybe there's simpler, but decode-time(encode-time) will
                 ;; give us the answer.
-                (let ((first (nth 6 (decode-time
-                                     (encode-time 0 0 0 1 month year
-                                                  time-zone))))
+                (let ((first (decoded-time-weekday
+                              (decode-time
+                               (encode-time 0 0 0 1 month year
+                                            time-zone))))
                       (max (cond ((= month 2)
                                   (if (date-leap-year-p year) 29 28))
                                  ((<= month 7)
diff --git a/lisp/gnus/nnimap.el b/lisp/gnus/nnimap.el
index 99a6104..c6eaa54 100644
--- a/lisp/gnus/nnimap.el
+++ b/lisp/gnus/nnimap.el
@@ -1100,7 +1100,7 @@ textual parts.")
                (format-time-string
                 (format "%%d-%s-%%Y"
                         (upcase
-                         (car (rassoc (nth 4 (decode-time cutoff))
+                         (car (rassoc (decoded-time-month (decode-time cutoff))
                                       parse-time-months))))
                 cutoff))))
          (and (car result)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]