+2014-10-29 Paul Eggert <eggert@cs.ucla.edu>
+
+ Simplify use of current-time and friends.
+ * gnus-delay.el (gnus-delay-article):
+ * gnus-sum.el (gnus-summary-read-document):
+ * gnus-util.el (gnus-seconds-today, gnus-seconds-month):
+ * message.el (message-make-expires-date):
+ Omit unnecessary call to current-time.
+ * gnus-util.el (gnus-float-time): Simplify to an alias because
+ time-to-seconds now behaves like float-time with respect to nil arg.
+ (gnus-seconds-year): Don't call current-time twice to get the current
+ time stamp, as this can lead to inconsistent results.
+ * time-date.el (time-to-seconds) [!float-time]:
+ Use current time if arg is nil, to be compatible with float-time.
+ (time-date--day-in-year): New function, with most of the guts of
+ the old time-to-day-in-year.
+ (time-to-day-in-year): Use it.
+ (time-to-days): Use it, to avoid decoding the same time stamp twice.
+
2014-10-27 Katsumi Yamaoka <yamaoka@jpl.org>
* gnus.el (gnus-mode-line-buffer-identification):
(setq hour (string-to-number (match-string 1 delay))
minute (string-to-number (match-string 2 delay)))
;; Use current time, except...
- (setq deadline (apply 'vector (decode-time (current-time))))
+ (setq deadline (apply 'vector (decode-time)))
;; ... for minute and hour.
(aset deadline 1 minute)
(aset deadline 2 hour)
((gnus-group-read-ephemeral-group
(setq vgroup (format
"nnvirtual:%s-%s" gnus-newsgroup-name
- (format-time-string "%Y%m%dT%H%M%S" (current-time))))
+ (format-time-string "%Y%m%dT%H%M%S")))
`(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
t
(cons (current-buffer) 'summary)))
;; Every version of Emacs Gnus supports has built-in float-time.
;; The featurep test silences an irritating compiler warning.
-(eval-and-compile
+(defalias 'gnus-float-time
(if (or (featurep 'emacs)
(fboundp 'float-time))
- (defalias 'gnus-float-time 'float-time)
- (defun gnus-float-time (&optional time)
- "Convert time value TIME to a floating point number.
-TIME defaults to the current time."
- (time-to-seconds (or time (current-time))))))
+ 'float-time 'time-to-seconds)
+ "Convert time value TIME to a floating point number.
+TIME defaults to the current time.")
;;; Keymap macros.
(defun gnus-seconds-today ()
"Return the number of seconds passed today."
- (let ((now (decode-time (current-time))))
+ (let ((now (decode-time)))
(+ (car now) (* (car (cdr now)) 60) (* (car (nthcdr 2 now)) 3600))))
(defun gnus-seconds-month ()
"Return the number of seconds passed this month."
- (let ((now (decode-time (current-time))))
+ (let ((now (decode-time)))
(+ (car now) (* (car (cdr now)) 60) (* (car (nthcdr 2 now)) 3600)
(* (- (car (nthcdr 3 now)) 1) 3600 24))))
(defun gnus-seconds-year ()
"Return the number of seconds passed this year."
- (let ((now (decode-time (current-time)))
- (days (format-time-string "%j" (current-time))))
+ (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)
(* (- (string-to-number days) 1) 3600 24))))
"Make date string for the Expires header. Expiry in DAYS days.
In posting styles use `(\"Expires\" (make-expires-date 30))'."
- (let* ((cur (decode-time (current-time)))
+ (let* ((cur (decode-time))
(nday (+ days (nth 3 cur))))
(setf (nth 3 cur) nday)
(message-make-date (apply 'encode-time cur))))
Each element of the list VARLIST is a list of the form
\(HIGH-SYMBOL LOW-SYMBOL MICRO-SYMBOL [PICO-SYMBOL [TYPE-SYMBOL]] TIME-VALUE).
-The time value TIME-VALUE is decoded and the result it bound to
+The time value TIME-VALUE is decoded and the result is bound to
the symbols HIGH-SYMBOL, LOW-SYMBOL and MICRO-SYMBOL.
The optional PICO-SYMBOL is bound to the picoseconds part.
(or (featurep 'emacs)
(and (fboundp 'float-time)
(subrp (symbol-function 'float-time)))
- (defun time-to-seconds (time)
- "Convert time value TIME to a floating point number."
- (with-decoded-time-value ((high low micro pico type time))
- (+ (* 1.0 high 65536)
+ (defun time-to-seconds (&optional time)
+ "Convert optional value TIME to a floating point number.
+TIME defaults to the current time."
+ (with-decoded-time-value ((high low micro pico type
+ (or time (current-time))))
+ (+ (* high 65536.0)
low
(/ (+ (* micro 1e6) pico) 1e12))))))
(not (zerop (% year 100))))
(zerop (% year 400))))
-;;;###autoload
-(defun time-to-day-in-year (time)
- "Return the day number within the year corresponding to TIME."
- (let* ((tim (decode-time time))
- (month (nth 4 tim))
+(defun time-date--day-in-year (tim)
+ "Return the day number within the year corresponding to the decoded time TIM."
+ (let* ((month (nth 4 tim))
(day (nth 3 tim))
(year (nth 5 tim))
(day-of-year (+ day (* 31 (1- month)))))
(setq day-of-year (1+ day-of-year))))
day-of-year))
+;;;###autoload
+(defun time-to-day-in-year (time)
+ "Return the day number within the year corresponding to TIME."
+ (time-date--day-in-year (decode-time time)))
+
;;;###autoload
(defun time-to-days (time)
"The number of days between the Gregorian date 0001-12-31bce and TIME.
The Gregorian date Sunday, December 31, 1bce is imaginary."
(let* ((tim (decode-time time))
(year (nth 5 tim)))
- (+ (time-to-day-in-year time) ; Days this year
+ (+ (time-date--day-in-year tim) ; Days this year
(* 365 (1- year)) ; + Days in prior years
(/ (1- year) 4) ; + Julian leap years
(- (/ (1- year) 100)) ; - century years