aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggert2019-02-22 13:24:16 -0800
committerPaul Eggert2019-02-22 13:31:01 -0800
commiteba66c1eafeef6512259c9b46face2b03c7433b8 (patch)
tree0945a1e684448ba37146dbd36cd71dc91d70dad2
parent0613e7a38efc3b0534e0ca5c5fa401e2a3bda906 (diff)
downloademacs-eba66c1eafeef6512259c9b46face2b03c7433b8.tar.gz
emacs-eba66c1eafeef6512259c9b46face2b03c7433b8.zip
Remove some timestamp format assumptions
Don’t assume that current-time and plain encode-time return timestamps in (HI LO US PS) format. * lisp/gnus/gnus-art.el (article-make-date-line) (article-lapsed-string): * lisp/gnus/gnus-demon.el (gnus-demon-time-to-step): * lisp/gnus/gnus-diary.el (gnus-user-format-function-d): * lisp/gnus/nnmaildir.el (nnmaildir-request-expire-articles): * lisp/net/pop3.el (pop3-uidl-dele): * lisp/org/ox-publish.el (org-publish-sitemap): * lisp/vc/vc-hg.el (vc-hg-state-fast): Simplify and remove assumptions about timestamp format. * lisp/gnus/gnus-art.el (article-lapsed-string): * lisp/gnus/gnus-diary.el (gnus-user-format-function-d): Do not worry about time-subtract returning nil; that's not possible. * lisp/gnus/gnus-diary.el (gnus-user-format-function-d): Avoid race due to duplicate current-time calls. * lisp/vc/vc-hg.el (vc-hg--time-to-integer): Remove; no longer used.
-rw-r--r--lisp/gnus/gnus-art.el33
-rw-r--r--lisp/gnus/gnus-demon.el8
-rw-r--r--lisp/gnus/gnus-diary.el45
-rw-r--r--lisp/gnus/nnmaildir.el9
-rw-r--r--lisp/net/pop3.el18
-rw-r--r--lisp/org/ox-publish.el10
-rw-r--r--lisp/vc/vc-hg.el8
7 files changed, 48 insertions, 83 deletions
diff --git a/lisp/gnus/gnus-art.el b/lisp/gnus/gnus-art.el
index 191f623afa3..0ea156118c6 100644
--- a/lisp/gnus/gnus-art.el
+++ b/lisp/gnus/gnus-art.el
@@ -3540,18 +3540,11 @@ possible values."
3540 (concat "Date: " (message-make-date time))) 3540 (concat "Date: " (message-make-date time)))
3541 ;; Convert to Universal Time. 3541 ;; Convert to Universal Time.
3542 ((eq type 'ut) 3542 ((eq type 'ut)
3543 (concat "Date: " 3543 (let ((system-time-locale "C"))
3544 (substring 3544 (format-time-string
3545 (message-make-date 3545 "Date: %a, %d %b %Y %T UT"
3546 (let* ((e (parse-time-string date)) 3546 (encode-time (parse-time-string date))
3547 (tm (encode-time e)) 3547 t)))
3548 (ms (car tm))
3549 (ls (- (cadr tm) (car (current-time-zone time)))))
3550 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
3551 ((> ls 65535) (list (1+ ms) (- ls 65536)))
3552 (t (list ms ls)))))
3553 0 -5)
3554 "UT"))
3555 ;; Get the original date from the article. 3548 ;; Get the original date from the article.
3556 ((eq type 'original) 3549 ((eq type 'original)
3557 (concat "Date: " (if (string-match "\n+$" date) 3550 (concat "Date: " (if (string-match "\n+$" date)
@@ -3569,13 +3562,7 @@ possible values."
3569 (concat "Date: " (format-time-string format time))))) 3562 (concat "Date: " (format-time-string format time)))))
3570 ;; ISO 8601. 3563 ;; ISO 8601.
3571 ((eq type 'iso8601) 3564 ((eq type 'iso8601)
3572 (let ((tz (car (current-time-zone time)))) 3565 (format-time-string "Date: %Y%m%dT%H%M%S%z" time))
3573 (concat
3574 "Date: "
3575 (format-time-string "%Y%m%dT%H%M%S" time)
3576 (format "%s%02d%02d"
3577 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3578 (/ (% (abs tz) 3600) 60)))))
3579 ;; Do a lapsed format. 3566 ;; Do a lapsed format.
3580 ((eq type 'lapsed) 3567 ((eq type 'lapsed)
3581 (concat "Date: " (article-lapsed-string time))) 3568 (concat "Date: " (article-lapsed-string time)))
@@ -3624,17 +3611,13 @@ possible values."
3624 ;; If the date is seriously mangled, the timezone functions are 3611 ;; If the date is seriously mangled, the timezone functions are
3625 ;; liable to bug out, so we ignore all errors. 3612 ;; liable to bug out, so we ignore all errors.
3626 (let* ((real-time (time-subtract nil time)) 3613 (let* ((real-time (time-subtract nil time))
3627 (real-sec (and real-time 3614 (real-sec (float-time real-time))
3628 (+ (* (float (car real-time)) 65536) 3615 (sec (abs real-sec))
3629 (cadr real-time))))
3630 (sec (and real-time (abs real-sec)))
3631 (segments 0) 3616 (segments 0)
3632 num prev) 3617 num prev)
3633 (unless max-segments 3618 (unless max-segments
3634 (setq max-segments (length article-time-units))) 3619 (setq max-segments (length article-time-units)))
3635 (cond 3620 (cond
3636 ((null real-time)
3637 "Unknown")
3638 ((zerop sec) 3621 ((zerop sec)
3639 "Now") 3622 "Now")
3640 (t 3623 (t
diff --git a/lisp/gnus/gnus-demon.el b/lisp/gnus/gnus-demon.el
index 4ae4c65d835..b9cb8eb71ce 100644
--- a/lisp/gnus/gnus-demon.el
+++ b/lisp/gnus/gnus-demon.el
@@ -192,11 +192,9 @@ marked with SPECIAL."
192 (elt nowParts 6) 192 (elt nowParts 6)
193 (elt nowParts 7) 193 (elt nowParts 7)
194 (elt nowParts 8))) 194 (elt nowParts 8)))
195 ;; calculate number of seconds between NOW and THEN 195 (diff (float-time (time-subtract then now))))
196 (diff (+ (* 65536 (- (car then) (car now))) 196 ;; Return number of timesteps in the number of seconds.
197 (- (cadr then) (cadr now))))) 197 (round diff gnus-demon-timestep)))
198 ;; return number of timesteps in the number of seconds
199 (round (/ diff gnus-demon-timestep))))
200 198
201(gnus-add-shutdown 'gnus-demon-cancel 'gnus) 199(gnus-add-shutdown 'gnus-demon-cancel 'gnus)
202 200
diff --git a/lisp/gnus/gnus-diary.el b/lisp/gnus/gnus-diary.el
index 51e39958798..ceb0d4a30da 100644
--- a/lisp/gnus/gnus-diary.el
+++ b/lisp/gnus/gnus-diary.el
@@ -159,32 +159,29 @@ There are currently two built-in format functions:
159 ;; Code partly stolen from article-make-date-line 159 ;; Code partly stolen from article-make-date-line
160 (let* ((extras (mail-header-extra header)) 160 (let* ((extras (mail-header-extra header))
161 (sched (gnus-diary-header-schedule extras)) 161 (sched (gnus-diary-header-schedule extras))
162 (occur (nndiary-next-occurrence sched (current-time)))
163 (now (current-time)) 162 (now (current-time))
163 (occur (nndiary-next-occurrence sched now))
164 (real-time (time-subtract occur now))) 164 (real-time (time-subtract occur now)))
165 (if (null real-time) 165 (let* ((sec (encode-time real-time 'integer))
166 "?????" 166 (past (< sec 0))
167 (let* ((sec (+ (* (float (car real-time)) 65536) (cadr real-time))) 167 delay)
168 (past (< sec 0)) 168 (and past (setq sec (- sec)))
169 delay) 169 (unless (zerop sec)
170 (and past (setq sec (- sec))) 170 ;; This is a bit convoluted, but basically we go through the time
171 (unless (zerop sec) 171 ;; units for years, weeks, etc, and divide things to see whether
172 ;; This is a bit convoluted, but basically we go through the time 172 ;; that results in positive answers.
173 ;; units for years, weeks, etc, and divide things to see whether 173 (let ((units `((year . ,(round (* 365.25 24 3600)))
174 ;; that results in positive answers. 174 (month . ,(* 31 24 3600))
175 (let ((units `((year . ,(* 365.25 24 3600)) 175 (week . ,(* 7 24 3600))
176 (month . ,(* 31 24 3600)) 176 (day . ,(* 24 3600))
177 (week . ,(* 7 24 3600)) 177 (hour . 3600)
178 (day . ,(* 24 3600)) 178 (minute . 60)))
179 (hour . 3600) 179 unit num)
180 (minute . 60))) 180 (while (setq unit (pop units))
181 unit num) 181 (unless (zerop (setq num (floor sec (cdr unit))))
182 (while (setq unit (pop units)) 182 (setq delay (append delay `((,num . ,(car unit))))))
183 (unless (zerop (setq num (ffloor (/ sec (cdr unit))))) 183 (setq sec (mod sec (cdr unit))))))
184 (setq delay (append delay `((,(floor num) . ,(car unit)))))) 184 (funcall gnus-diary-delay-format-function past delay))))
185 (setq sec (- sec (* num (cdr unit)))))))
186 (funcall gnus-diary-delay-format-function past delay)))
187 ))
188 185
189;; #### NOTE: Gnus sometimes gives me a HEADER not corresponding to any 186;; #### NOTE: Gnus sometimes gives me a HEADER not corresponding to any
190;; message, with all fields set to nil here. I don't know what it is for, and 187;; message, with all fields set to nil here. I don't know what it is for, and
diff --git a/lisp/gnus/nnmaildir.el b/lisp/gnus/nnmaildir.el
index 9df2292e783..d7117a1ce20 100644
--- a/lisp/gnus/nnmaildir.el
+++ b/lisp/gnus/nnmaildir.el
@@ -1577,14 +1577,7 @@ This variable is set by `nnmaildir-request-article'.")
1577 (when no-force 1577 (when no-force
1578 (unless (integerp time) ;; handle 'never 1578 (unless (integerp time) ;; handle 'never
1579 (throw 'return (gnus-uncompress-range ranges))) 1579 (throw 'return (gnus-uncompress-range ranges)))
1580 (setq boundary (current-time) 1580 (setq boundary (time-subtract nil time)))
1581 high (- (car boundary) (/ time 65536))
1582 low (- (cadr boundary) (% time 65536)))
1583 (if (< low 0)
1584 (setq low (+ low 65536)
1585 high (1- high)))
1586 (setcar (cdr boundary) low)
1587 (setcar boundary high))
1588 (setq dir (nnmaildir--srv-dir nnmaildir--cur-server) 1581 (setq dir (nnmaildir--srv-dir nnmaildir--cur-server)
1589 dir (nnmaildir--srvgrp-dir dir gname) 1582 dir (nnmaildir--srvgrp-dir dir gname)
1590 dir (nnmaildir--cur dir) 1583 dir (nnmaildir--cur dir)
diff --git a/lisp/net/pop3.el b/lisp/net/pop3.el
index 3aac5b5c45c..cd6a113bffe 100644
--- a/lisp/net/pop3.el
+++ b/lisp/net/pop3.el
@@ -180,8 +180,8 @@ Shorter values mean quicker response, but are more CPU intensive.")
180;; ("SERVER_B" ("USER_B1" "UIDL1" TIMESTAMP1 "UIDL2" TIMESTAMP2...) 180;; ("SERVER_B" ("USER_B1" "UIDL1" TIMESTAMP1 "UIDL2" TIMESTAMP2...)
181;; ("USER_B2" "UIDL1" TIMESTAMP1 "UIDL2" TIMESTAMP2...) 181;; ("USER_B2" "UIDL1" TIMESTAMP1 "UIDL2" TIMESTAMP2...)
182;; ...)) 182;; ...))
183;; Where TIMESTAMP is the most significant two digits of an Emacs time, 183;; Where TIMESTAMP is an Emacs time value (HI LO) representing the
184;; i.e. the return value of `current-time'. 184;; number of seconds (+ (ash HI 16) LO).
185 185
186;;;###autoload 186;;;###autoload
187(defun pop3-movemail (file) 187(defun pop3-movemail (file)
@@ -380,7 +380,9 @@ Use streaming commands."
380(defun pop3-uidl-dele (process) 380(defun pop3-uidl-dele (process)
381 "Delete messages according to `pop3-leave-mail-on-server'. 381 "Delete messages according to `pop3-leave-mail-on-server'.
382Return non-nil if it is necessary to update the local UIDL file." 382Return non-nil if it is necessary to update the local UIDL file."
383 (let* ((ctime (current-time)) 383 (let* ((ctime (encode-time nil 'list))
384 (age-limit (and (numberp pop3-leave-mail-on-server)
385 (* 86400 pop3-leave-mail-on-server)))
384 (srvr (assoc pop3-mailhost pop3-uidl-saved)) 386 (srvr (assoc pop3-mailhost pop3-uidl-saved))
385 (saved (assoc pop3-maildrop (cdr srvr))) 387 (saved (assoc pop3-maildrop (cdr srvr)))
386 i uidl mod new tstamp dele) 388 i uidl mod new tstamp dele)
@@ -397,17 +399,13 @@ Return non-nil if it is necessary to update the local UIDL file."
397 (setq new (mapcan (lambda (elt) (list elt ctime)) pop3-uidl)))) 399 (setq new (mapcan (lambda (elt) (list elt ctime)) pop3-uidl))))
398 (when new (setq mod t)) 400 (when new (setq mod t))
399 ;; List expirable messages and delete them from the data to be saved. 401 ;; List expirable messages and delete them from the data to be saved.
400 (setq ctime (when (numberp pop3-leave-mail-on-server) 402 (setq i (1- (length saved)))
401 (/ (+ (* (car ctime) 65536.0) (cadr ctime)) 86400))
402 i (1- (length saved)))
403 (while (> i 0) 403 (while (> i 0)
404 (if (member (setq uidl (nth (1- i) saved)) pop3-uidl) 404 (if (member (setq uidl (nth (1- i) saved)) pop3-uidl)
405 (progn 405 (progn
406 (setq tstamp (nth i saved)) 406 (setq tstamp (nth i saved))
407 (if (and ctime 407 (if (and age-limit
408 (> (- ctime (/ (+ (* (car tstamp) 65536.0) (cadr tstamp)) 408 (time-less-p age-limit (time-subtract ctime tstamp)))
409 86400))
410 pop3-leave-mail-on-server))
411 ;; Mails to delete. 409 ;; Mails to delete.
412 (progn 410 (progn
413 (setq mod t) 411 (setq mod t)
diff --git a/lisp/org/ox-publish.el b/lisp/org/ox-publish.el
index cd49cd0afc5..bc86a4d5635 100644
--- a/lisp/org/ox-publish.el
+++ b/lisp/org/ox-publish.el
@@ -793,13 +793,11 @@ Default for SITEMAP-FILENAME is `sitemap.org'."
793 (not (string-lessp B A)))))) 793 (not (string-lessp B A))))))
794 ((or `anti-chronologically `chronologically) 794 ((or `anti-chronologically `chronologically)
795 (let* ((adate (org-publish-find-date a project)) 795 (let* ((adate (org-publish-find-date a project))
796 (bdate (org-publish-find-date b project)) 796 (bdate (org-publish-find-date b project)))
797 (A (+ (ash (car adate) 16) (cadr adate)))
798 (B (+ (ash (car bdate) 16) (cadr bdate))))
799 (setq retval 797 (setq retval
800 (if (eq sort-files 'chronologically) 798 (not (if (eq sort-files 'chronologically)
801 (<= A B) 799 (time-less-p bdate adate)
802 (>= A B))))) 800 (time-less-p adate bdate))))))
803 (`nil nil) 801 (`nil nil)
804 (_ (user-error "Invalid sort value %s" sort-files))) 802 (_ (user-error "Invalid sort value %s" sort-files)))
805 ;; Directory-wise wins: 803 ;; Directory-wise wins:
diff --git a/lisp/vc/vc-hg.el b/lisp/vc/vc-hg.el
index 342c6d214cd..6b17e861dda 100644
--- a/lisp/vc/vc-hg.el
+++ b/lisp/vc/vc-hg.el
@@ -923,9 +923,6 @@ FILENAME must be the file's true absolute name."
923 (setf ignored (string-match (pop patterns) filename))) 923 (setf ignored (string-match (pop patterns) filename)))
924 ignored)) 924 ignored))
925 925
926(defun vc-hg--time-to-integer (ts)
927 (+ (* 65536 (car ts)) (cadr ts)))
928
929(defvar vc-hg--cached-ignore-patterns nil 926(defvar vc-hg--cached-ignore-patterns nil
930 "Cached pre-parsed hg ignore patterns.") 927 "Cached pre-parsed hg ignore patterns.")
931 928
@@ -1046,8 +1043,9 @@ hg binary."
1046 (let ((vc-hg-size (nth 2 dirstate-entry)) 1043 (let ((vc-hg-size (nth 2 dirstate-entry))
1047 (vc-hg-mtime (nth 3 dirstate-entry)) 1044 (vc-hg-mtime (nth 3 dirstate-entry))
1048 (fs-size (file-attribute-size stat)) 1045 (fs-size (file-attribute-size stat))
1049 (fs-mtime (vc-hg--time-to-integer 1046 (fs-mtime (encode-time
1050 (file-attribute-modification-time stat)))) 1047 (file-attribute-modification-time stat)
1048 'integer)))
1051 (if (and (eql vc-hg-size fs-size) (eql vc-hg-mtime fs-mtime)) 1049 (if (and (eql vc-hg-size fs-size) (eql vc-hg-mtime fs-mtime))
1052 'up-to-date 1050 'up-to-date
1053 'edited))) 1051 'edited)))