Commit 123ddec7 authored by Paul Eggert's avatar Paul Eggert
Browse files

Simplify use of current-time and friends.

* doc/misc/org.texi (Dynamic blocks):
* lisp/allout-widgets.el (allout-widgets-hook-error-handler):
* lisp/calendar/appt.el (appt-display-message):
* lisp/calendar/icalendar.el (icalendar--convert-float-to-ical):
* lisp/calendar/timeclock.el (timeclock-in, timeclock-when-to-leave)
(timeclock-last-period, timeclock-day-base):
* lisp/eshell/em-ls.el (eshell-ls-file):
* lisp/eshell/esh-util.el (eshell-parse-ange-ls):
* lisp/generic-x.el (named-database-print-serial):
* lisp/net/newst-backend.el (newsticker--get-news-by-url-callback)
(newsticker-get-news, newsticker--sentinel-work)
(newsticker--image-get, newsticker--image-sentinel):
* lisp/net/tramp-sh.el (tramp-get-remote-touch):
* lisp/progmodes/opascal.el (opascal-debug-log):
* lisp/textmodes/remember.el (remember-mail-date)
(remember-store-in-files):
* lisp/vc/vc-annotate.el (vc-annotate-display-autoscale)
(vc-default-annotate-current-time):
* lisp/vc/vc-bzr.el (vc-bzr-shelve-snapshot):
* lisp/vc/vc-cvs.el (vc-cvs-annotate-current-time):
* lisp/vc/vc-rcs.el (vc-rcs-annotate-current-time):
* lisp/url/url-util.el (url-get-normalized-date):
* lisp/erc/erc-backend.el (TOPIC):
* lisp/gnus/gnus-delay.el (gnus-delay-article):
* lisp/gnus/gnus-sum.el (gnus-summary-read-document):
* lisp/gnus/gnus-util.el (gnus-seconds-today, gnus-seconds-month):
* lisp/gnus/message.el (message-make-expires-date):
* lisp/org/org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling):
* lisp/org/org-clock.el (org-resolve-clocks, org-clock-get-sum-start)
(org-clock-special-range):
* lisp/org/org-timer.el (org-timer-seconds):
* lisp/org/org.el (org-read-date-analyze, org-get-cursor-date):
* lisp/org/ox-html.el (org-html-format-spec):
* lisp/org/ox-icalendar.el (org-icalendar--vtodo):
Omit unnecessary call to current-time.
* lisp/calendar/time-date.el (time-to-seconds) [!float-time]:
* lisp/calendar/timeclock.el (timeclock-time-to-date):
* lisp/vc/vc-annotate.el (vc-annotate-convert-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.
* lisp/calendar/timeclock.el (timeclock-update-mode-line):
* lisp/cedet/srecode/args.el (srecode-semantic-handle-:time):
* lisp/gnus/gnus-util.el (gnus-seconds-year):
* lisp/org/org.el (org-get-cursor-date):
Don't call current-time twice to get the current time stamp,
as this can lead to inconsistent results.
* lisp/completion.el (cmpl-hours-since-origin):
* lisp/erc/erc.el (erc-emacs-time-to-erc-time):
* lisp/ido.el (ido-time-stamp):
* lisp/vc/vc-annotate.el (vc-annotate-convert-time):
Simplify by using float-time.
* lisp/completion.el (save-completions-to-file):
* lisp/url/url-cache.el (url-cache-prune-cache):
Rename local var to avoid confusion.
* lisp/gnus/gnus-util.el (gnus-float-time):
* lisp/net/rcirc.el (rcirc-float-time):
* lisp/org/org-compat.el (org-float-time):
Simplify to an alias because time-to-seconds now behaves like float-time
with respect to nil arg.
* lisp/subr.el (progress-reporter-do-update):
Don't call float-time unless needed.
* lisp/erc/erc.el (erc-current-time): Simplify by using erc-emacs-time-to-erc-time.
* lisp/org/org-clock.el (org-clock-get-table-data): Omit unnecessary, lossy
conversion from floating point to Emacs time and back.
(org-resolve-clocks): Prefer two-argument floor.
parent 14e5809d
2014-10-29 Paul Eggert <eggert@cs.ucla.edu>
Simplify use of current-time and friends.
* org.texi (Dynamic blocks): Omit unnecessary call to current-time
in example.
2014-10-28 Christopher Schmidt <ch@ristopher.com>
* calc.texi (Quick Calculator): Mention prefix argument of
......
......@@ -13126,7 +13126,7 @@ Here is a thorough example, taken from @inforef{GNU Sample Texts,,texinfo}.
#+TEXINFO_PRINTED_TITLE: GNU Sample
#+SUBTITLE: for version 2.0, last updated 4 March 2014
 
* Copying
* Copying
:PROPERTIES:
:COPYING: t
:END:
......@@ -17538,7 +17538,7 @@ The corresponding block writer function could look like this:
(defun org-dblock-write:block-update-time (params)
(let ((fmt (or (plist-get params :format) "%d. %m. %Y")))
(insert "Last block update at: "
(format-time-string fmt (current-time)))))
(format-time-string fmt))))
@end lisp
 
If you want to make sure that all dynamic blocks are always up-to-date,
......
2014-10-29 Paul Eggert <eggert@cs.ucla.edu>
Simplify use of current-time and friends.
* allout-widgets.el (allout-widgets-hook-error-handler):
* calendar/appt.el (appt-display-message):
* calendar/icalendar.el (icalendar--convert-float-to-ical):
* calendar/timeclock.el (timeclock-in, timeclock-when-to-leave)
(timeclock-last-period, timeclock-day-base):
* eshell/em-ls.el (eshell-ls-file):
* eshell/esh-util.el (eshell-parse-ange-ls):
* generic-x.el (named-database-print-serial):
* net/newst-backend.el (newsticker--get-news-by-url-callback)
(newsticker-get-news, newsticker--sentinel-work)
(newsticker--image-get, newsticker--image-sentinel):
* net/tramp-sh.el (tramp-get-remote-touch):
* progmodes/opascal.el (opascal-debug-log):
* textmodes/remember.el (remember-mail-date)
(remember-store-in-files):
* vc/vc-annotate.el (vc-annotate-display-autoscale)
(vc-default-annotate-current-time):
* vc/vc-bzr.el (vc-bzr-shelve-snapshot):
* vc/vc-cvs.el (vc-cvs-annotate-current-time):
* vc/vc-rcs.el (vc-rcs-annotate-current-time):
Omit unnecessary call to current-time.
* calendar/time-date.el (time-to-seconds) [!float-time]:
* vc/vc-annotate.el (vc-annotate-convert-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.
* calendar/timeclock.el (timeclock-time-to-date):
Arg is now optional, like current-time-string.
(timeclock-update-mode-line):
Don't call current-time twice to get the current time stamp,
as this can lead to inconsistent results.
* completion.el (cmpl-hours-since-origin):
* ido.el (ido-time-stamp):
* vc/vc-annotate.el (vc-annotate-convert-time):
Simplify by using float-time.
* completion.el (save-completions-to-file):
Rename local var to avoid confusion.
* net/rcirc.el (rcirc-float-time): Simplify to an alias because
time-to-seconds now behaves like float-time with respect to nil arg.
* subr.el (progress-reporter-do-update):
Don't call float-time unless needed.
2014-10-29 Leo Liu <sdl.web@gmail.com>
 
* net/rcirc.el (rcirc-fill-column): Use function.
......
......@@ -902,7 +902,7 @@ encompassing condition-case."
(header
(format "allout-widgets-last-hook-error stored, %s/%s %s %s"
this mode args
(format-time-string "%e-%b-%Y %r" (current-time)))))
(format-time-string "%e-%b-%Y %r"))))
;; post to *Messages* then immediately replace with more compact notice:
(message "%s" (setq allout-widgets-last-hook-error
(format "%s:\n%s" header bt)))
......
......@@ -228,7 +228,7 @@ also calls `beep' for an audible reminder."
string (car string)))
(cond ((eq appt-display-format 'window)
;; TODO use calendar-month-abbrev-array rather than %b?
(let ((time (format-time-string "%a %b %e " (current-time)))
(let ((time (format-time-string "%a %b %e "))
err)
(condition-case err
(funcall appt-disp-window-function
......
......@@ -1682,7 +1682,7 @@ entries. ENTRY-MAIN is the first line of the diary entry."
(cons (concat
;;Start today (yes this is an arbitrary choice):
"\nDTSTART;VALUE=DATE:"
(format-time-string "%Y%m%d" (current-time))
(format-time-string "%Y%m%d")
;;BUT remove today if `diary-float'
;;expression does not hold true for today:
(when
......@@ -1691,7 +1691,7 @@ entries. ENTRY-MAIN is the first line of the diary entry."
(diary-float month dayname n)))
(concat
"\nEXDATE;VALUE=DATE:"
(format-time-string "%Y%m%d" (current-time))))
(format-time-string "%Y%m%d")))
"\nRRULE:"
(if (or (numberp month) (listp month))
"FREQ=YEARLY;BYMONTH="
......
......@@ -44,7 +44,7 @@ The value of the last form in BODY is returned.
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.
......@@ -147,10 +147,12 @@ If DATE lacks timezone information, GMT is assumed."
(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))))))
......@@ -272,11 +274,9 @@ DATE1 and DATE2 should be date-time strings."
(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)))))
......@@ -286,6 +286,11 @@ DATE1 and DATE2 should be date-time strings."
(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.
......@@ -293,7 +298,7 @@ TIME should be a time value.
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
......
......@@ -320,7 +320,7 @@ display (non-nil means on)."
(cancel-timer timeclock-update-timer)
(setq timeclock-update-timer nil))))
(defsubst timeclock-time-to-date (time)
(defsubst timeclock-time-to-date (&optional time)
"Convert the TIME value to a textual date string."
(format-time-string "%Y/%m/%d" time))
......@@ -351,7 +351,7 @@ discover the name of the project."
(unless (and timeclock-last-event
(equal (timeclock-time-to-date
(cadr timeclock-last-event))
(timeclock-time-to-date (current-time))))
(timeclock-time-to-date)))
(let ((workday (or (and (numberp arg) arg)
(and arg 0)
(and timeclock-get-workday-function
......@@ -543,7 +543,7 @@ non-nil, the amount returned will be relative to past time worked."
If TODAY-ONLY is non-nil, the value returned will be relative only to
the time worked today, and not to past time."
(timeclock-seconds-to-time
(- (timeclock-time-to-seconds (current-time))
(- (timeclock-time-to-seconds)
(let ((discrep (timeclock-find-discrep)))
(if discrep
(if today-only
......@@ -647,14 +647,12 @@ that variable's documentation."
(if timeclock-use-elapsed
(timeclock-workday-elapsed)
(timeclock-workday-remaining (not timeclock-relative))))
(last-in (equal (car timeclock-last-event) "i")))
(last-in (equal (car timeclock-last-event) "i"))
(todays-date (timeclock-time-to-date)))
(when (and (< remainder 0)
(not (and timeclock-day-over
(equal timeclock-day-over
(timeclock-time-to-date
(current-time))))))
(setq timeclock-day-over
(timeclock-time-to-date (current-time)))
(equal timeclock-day-over todays-date))))
(setq timeclock-day-over todays-date)
(run-hooks 'timeclock-day-over-hook))
(setq timeclock-mode-string
(propertize
......@@ -725,9 +723,8 @@ recorded to disk. If MOMENT is non-nil, use that as the current time.
This is only provided for coherency when used by
`timeclock-discrepancy'."
(if (equal (car timeclock-last-event) "i")
(- (timeclock-time-to-seconds (or moment (current-time)))
(timeclock-time-to-seconds
(cadr timeclock-last-event)))
(- (timeclock-time-to-seconds moment)
(timeclock-time-to-seconds (cadr timeclock-last-event)))
timeclock-last-period))
(defsubst timeclock-entry-length (entry)
......@@ -1156,7 +1153,7 @@ discrepancy, today's discrepancy, and the time worked today."
(+ timeclock-last-period timeclock-elapsed)))))
(setq timeclock-last-event event
timeclock-last-event-workday
(if (equal (timeclock-time-to-date now) last-date-limited)
(if (equal todays-date last-date-limited)
last-date-seconds
timeclock-workday))
(forward-line))
......@@ -1182,7 +1179,7 @@ discrepancy, today's discrepancy, and the time worked today."
(defun timeclock-day-base (&optional time)
"Given a time within a day, return 0:0:0 within that day.
If optional argument TIME is non-nil, use that instead of the current time."
(let ((decoded (decode-time (or time (current-time)))))
(let ((decoded (decode-time time)))
(setcar (nthcdr 0 decoded) 0)
(setcar (nthcdr 1 decoded) 0)
(setcar (nthcdr 2 decoded) 0)
......
2014-10-29 Paul Eggert <eggert@cs.ucla.edu>
Simplify use of current-time and friends.
* srecode/args.el (srecode-semantic-handle-:time):
Don't call current-time twice to get the current time stamp,
as this can lead to inconsistent results.
2014-10-24 Stefan Monnier <monnier@iro.umontreal.ca>
* semantic/complete.el: Require semantic/db-find.
......
......@@ -101,35 +101,35 @@ do not contain any text from preceding or following text."
(defun srecode-semantic-handle-:time (dict)
"Add macros into the dictionary DICT based on the current :time."
;; DATE Values
(srecode-dictionary-set-value
dict "YEAR" (format-time-string "%Y" (current-time)))
(srecode-dictionary-set-value
dict "MONTHNAME" (format-time-string "%B" (current-time)))
(srecode-dictionary-set-value
dict "MONTH" (format-time-string "%m" (current-time)))
(srecode-dictionary-set-value
dict "DAY" (format-time-string "%d" (current-time)))
(srecode-dictionary-set-value
dict "WEEKDAY" (format-time-string "%a" (current-time)))
;; Time Values
(srecode-dictionary-set-value
dict "HOUR" (format-time-string "%H" (current-time)))
(srecode-dictionary-set-value
dict "HOUR12" (format-time-string "%l" (current-time)))
(srecode-dictionary-set-value
dict "AMPM" (format-time-string "%p" (current-time)))
(srecode-dictionary-set-value
dict "MINUTE" (format-time-string "%M" (current-time)))
(srecode-dictionary-set-value
dict "SECOND" (format-time-string "%S" (current-time)))
(srecode-dictionary-set-value
dict "TIMEZONE" (format-time-string "%Z" (current-time)))
;; Convenience pre-packed date/time
(srecode-dictionary-set-value
dict "DATE" (format-time-string "%D" (current-time)))
(srecode-dictionary-set-value
dict "TIME" (format-time-string "%X" (current-time)))
)
(let ((now (current-time)))
(srecode-dictionary-set-value
dict "YEAR" (format-time-string "%Y" now))
(srecode-dictionary-set-value
dict "MONTHNAME" (format-time-string "%B" now))
(srecode-dictionary-set-value
dict "MONTH" (format-time-string "%m" now))
(srecode-dictionary-set-value
dict "DAY" (format-time-string "%d" now))
(srecode-dictionary-set-value
dict "WEEKDAY" (format-time-string "%a" now))
;; Time Values
(srecode-dictionary-set-value
dict "HOUR" (format-time-string "%H" now))
(srecode-dictionary-set-value
dict "HOUR12" (format-time-string "%l" now))
(srecode-dictionary-set-value
dict "AMPM" (format-time-string "%p" now))
(srecode-dictionary-set-value
dict "MINUTE" (format-time-string "%M" now))
(srecode-dictionary-set-value
dict "SECOND" (format-time-string "%S" now))
(srecode-dictionary-set-value
dict "TIMEZONE" (format-time-string "%Z" now))
;; Convenience pre-packed date/time
(srecode-dictionary-set-value
dict "DATE" (format-time-string "%D" now))
(srecode-dictionary-set-value
dict "TIME" (format-time-string "%X" now))))
;;; :file ARGUMENT HANDLING
;;
......
......@@ -435,8 +435,7 @@ Used to decide whether to save completions.")
(defun cmpl-hours-since-origin ()
(let ((time (current-time)))
(floor (+ (* 65536.0 (nth 0 time)) (nth 1 time)) 3600)))
(floor (float-time) 3600))
;;---------------------------------------------------------------------------
;; "Symbol" parsing functions
......@@ -1950,7 +1949,7 @@ If file name is not specified, use `save-completions-file-name'."
(kept-old-versions 0)
(kept-new-versions completions-file-versions-kept)
last-use-time
(current-time (cmpl-hours-since-origin))
(this-use-time (cmpl-hours-since-origin))
(total-in-db 0)
(total-perm 0)
(total-saved 0)
......@@ -1982,13 +1981,13 @@ If file name is not specified, use `save-completions-file-name'."
;; or if
(if (> (completion-num-uses completion) 0)
;; it's been used
(setq last-use-time current-time)
(setq last-use-time this-use-time)
;; or it was saved before and
(and last-use-time
;; save-completions-retention-time is nil
(or (not save-completions-retention-time)
;; or time since last use is < ...retention-time*
(< (- current-time last-use-time)
(< (- this-use-time last-use-time)
save-completions-retention-time)))))
;; write to file
(setq total-saved (1+ total-saved))
......
2014-10-29 Paul Eggert <eggert@cs.ucla.edu>
Simplify use of current-time and friends.
* erc-backend.el (TOPIC): Omit unnecessary call to current-time.
* erc.el (erc-emacs-time-to-erc-time): Simplify by using float-time.
(erc-current-time): Simplify by using erc-emacs-time-to-erc-time.
2014-10-20 Glenn Morris <rgm@gnu.org>
* Merge in all changes up to 24.4 release.
......
......@@ -1465,8 +1465,7 @@ add things to `%s' instead."
"The channel topic has changed." nil
(let* ((ch (car (erc-response.command-args parsed)))
(topic (erc-trim-string (erc-response.contents parsed)))
(time (format-time-string erc-server-timestamp-format
(current-time))))
(time (format-time-string erc-server-timestamp-format)))
(pcase-let ((`(,nick ,login ,host)
(erc-parse-user (erc-response.sender parsed))))
(erc-update-channel-member ch nick nick nil nil nil nil nil nil host login)
......
......@@ -5956,17 +5956,15 @@ Returns a list of the form (HIGH LOW), compatible with Emacs time format."
(list (truncate (/ n 65536))
(truncate (mod n 65536)))))
(defun erc-emacs-time-to-erc-time (time)
"Convert Emacs TIME to a number of seconds since the epoch."
(when time
(+ (* (nth 0 time) 65536.0) (nth 1 time))))
; (round (+ (* (nth 0 tm) 65536.0) (nth 1 tm))))
(defalias 'erc-emacs-time-to-erc-time
(if (featurep 'xemacs) 'time-to-seconds 'float-time)
"Convert time value TIME to a floating point number.
TIME defaults to the current time.")
(defun erc-current-time ()
(defalias 'erc-current-time 'erc-emacs-time-to-erc-time
"Return the `current-time' as a number of seconds since the epoch.
See also `erc-emacs-time-to-erc-time'."
(erc-emacs-time-to-erc-time (current-time)))
See also `erc-emacs-time-to-erc-time'.")
(defun erc-time-diff (t1 t2)
"Return the time difference in seconds between T1 and T2."
......
......@@ -490,7 +490,7 @@ whose cdr is the list of file attributes."
" " (format-time-string
(concat
eshell-ls-date-format " "
(if (= (nth 5 (decode-time (current-time)))
(if (= (nth 5 (decode-time))
(nth 5 (decode-time
(nth (cond
((eq sort-method 'by-atime) 4)
......
......@@ -653,7 +653,7 @@ If NOSORT is non-nil, the list is not sorted--its order is unpredictable.
(match-string 6))))
(if (nth 0 moment)
(setcar (nthcdr 5 moment)
(nth 5 (decode-time (current-time))))
(nth 5 (decode-time)))
(setcar (nthcdr 0 moment) 0)
(setcar (nthcdr 1 moment) 0)
(setcar (nthcdr 2 moment) 0))
......
......@@ -1650,7 +1650,7 @@ like an INI file. You can add this hook to `find-file-hook'."
(defun named-database-print-serial ()
"Print a serial number based on the current date."
(interactive)
(insert (format-time-string named-database-time-string (current-time)))))
(insert (format-time-string named-database-time-string))))
(when (memq 'resolve-conf-generic-mode generic-extras-enable-list)
......
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.
2014-10-27 Katsumi Yamaoka <yamaoka@jpl.org>
 
* gnus.el (gnus-mode-line-buffer-identification):
......
......@@ -98,7 +98,7 @@ DELAY is a string, giving the length of the time. Possible values are:
(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)
......
......@@ -9333,7 +9333,7 @@ Obeys the standard process/prefix convention."
((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)))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment