diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2014-10-28 18:42:51 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2014-10-28 18:42:51 -0700 |
commit | 123ddec7f807f4bd7400bbbe08219afb02269c00 (patch) | |
tree | cac1153049785a70e015b32748521098956de5d8 /lisp/calendar | |
parent | 14e5809d3cc1fd89e50f88d5783219091596a271 (diff) | |
download | emacs-123ddec7f807f4bd7400bbbe08219afb02269c00.tar.gz emacs-123ddec7f807f4bd7400bbbe08219afb02269c00.tar.bz2 emacs-123ddec7f807f4bd7400bbbe08219afb02269c00.zip |
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.
Diffstat (limited to 'lisp/calendar')
-rw-r--r-- | lisp/calendar/appt.el | 2 | ||||
-rw-r--r-- | lisp/calendar/icalendar.el | 4 | ||||
-rw-r--r-- | lisp/calendar/time-date.el | 27 | ||||
-rw-r--r-- | lisp/calendar/timeclock.el | 25 |
4 files changed, 30 insertions, 28 deletions
diff --git a/lisp/calendar/appt.el b/lisp/calendar/appt.el index c90a20d92ca..7e32d890e15 100644 --- a/lisp/calendar/appt.el +++ b/lisp/calendar/appt.el @@ -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 diff --git a/lisp/calendar/icalendar.el b/lisp/calendar/icalendar.el index 43610036861..5f89318e139 100644 --- a/lisp/calendar/icalendar.el +++ b/lisp/calendar/icalendar.el @@ -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=" diff --git a/lisp/calendar/time-date.el b/lisp/calendar/time-date.el index 48fe2294354..82bc05f299f 100644 --- a/lisp/calendar/time-date.el +++ b/lisp/calendar/time-date.el @@ -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))))) @@ -287,13 +287,18 @@ DATE1 and DATE2 should be date-time strings." 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. 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 diff --git a/lisp/calendar/timeclock.el b/lisp/calendar/timeclock.el index 2b4db9a7820..fb69357b1b4 100644 --- a/lisp/calendar/timeclock.el +++ b/lisp/calendar/timeclock.el @@ -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) |