diff options
| author | Paul Eggert | 2016-05-08 12:46:00 -0700 |
|---|---|---|
| committer | Paul Eggert | 2016-05-08 12:46:22 -0700 |
| commit | e2f785991d0c696fbb2bc2f331f888d979b8da82 (patch) | |
| tree | ba345e8547f4542bfe9bbb9ef311405bd519cd97 /lisp/calendar | |
| parent | 2eb6817ba971184cc109f8530f4b3b38f65650ea (diff) | |
| download | emacs-e2f785991d0c696fbb2bc2f331f888d979b8da82.tar.gz emacs-e2f785991d0c696fbb2bc2f331f888d979b8da82.zip | |
Simplify now that float-time etc. are built-in
This was prompted by warnings about calls to now-obsolete functions.
* lisp/calendar/time-date.el (encode-time-value):
Use setq rather than a recursive call, to avoid a warning
about calling this obsolete function.
* lisp/calendar/time-date.el (encode-time-value)
(with-decoded-time-value, time-to-seconds, time-to-number-of-days):
* lisp/erc/erc.el (erc-emacs-time-to-erc-time):
* lisp/net/rcirc.el (rcirc-float-time):
* lisp/org/org-compat.el (org-float-time):
Simplify now that time-add and float-time are now built-in.
* lisp/calendar/time-date.el (time-add, time-subtract, time-less-p):
* lisp/net/newst-backend.el (time-add):
* lisp/org/org.el (time-subtract):
Remove backward-compatibility definitions; they are now built-in.
* lisp/calendar/timeclock.el (timeclock-time-to-seconds)
(timeclock-seconds-to-time):
* lisp/net/rcirc.el (rcirc-float-time):
* lisp/org/org-compat.el (org-float-time):
Now obsolete, since callers can just use float-time and
seconds-to-time. All uses changed.
* lisp/emacs-lisp/ert.el (ert-results-pop-to-timings):
* lisp/gnus/gnus-art.el (article-lapsed-string):
* lisp/gnus/gnus-diary.el (gnus-user-format-function-d):
* lisp/gnus/gnus-group.el (gnus-group-timestamp-delta):
* lisp/gnus/nndiary.el (nndiary-compute-reminders):
* lisp/net/tramp.el (tramp-time-diff):
* lisp/org/org-clock.el (org-clock-timestamps-change):
Prefer the time-subtract builtin to the subtract-time alias.
* lisp/files.el (dir-locals-find-file, dir-locals-read-from-dir):
* test/lisp/character-fold-tests.el (character-fold--speed-test):
Prefer the float-time builtin to the time-to-seconds alias.
* lisp/org/org-agenda.el, lisp/org/org-clock.el, lisp/org/org-list.el:
* lisp/org/org-timer.el, lisp/org/org.el:
Adjust to org-float-time deprecation.
Diffstat (limited to 'lisp/calendar')
| -rw-r--r-- | lisp/calendar/time-date.el | 104 | ||||
| -rw-r--r-- | lisp/calendar/timeclock.el | 60 |
2 files changed, 38 insertions, 126 deletions
diff --git a/lisp/calendar/time-date.el b/lisp/calendar/time-date.el index da3e2a267db..a1d946eac74 100644 --- a/lisp/calendar/time-date.el +++ b/lisp/calendar/time-date.el | |||
| @@ -126,16 +126,17 @@ type 2 is (HIGH LOW MICRO), and type 3 is (HIGH LOW MICRO PICO). | |||
| 126 | 126 | ||
| 127 | For backward compatibility, if only four arguments are given, | 127 | For backward compatibility, if only four arguments are given, |
| 128 | it is assumed that PICO was omitted and should be treated as zero." | 128 | it is assumed that PICO was omitted and should be treated as zero." |
| 129 | (when (null type) | ||
| 130 | (setq type pico) | ||
| 131 | (setq pico 0)) | ||
| 129 | (cond | 132 | (cond |
| 130 | ((eq type 0) (cons high low)) | 133 | ((eq type 0) (cons high low)) |
| 131 | ((eq type 1) (list high low)) | 134 | ((eq type 1) (list high low)) |
| 132 | ((eq type 2) (list high low micro)) | 135 | ((eq type 2) (list high low micro)) |
| 133 | ((eq type 3) (list high low micro pico)) | 136 | ((eq type 3) (list high low micro pico)))) |
| 134 | ((null type) (encode-time-value high low micro 0 pico)))) | ||
| 135 | 137 | ||
| 136 | (when (and (fboundp 'time-add) (subrp (symbol-function 'time-add))) | 138 | (make-obsolete 'encode-time-value nil "25.1") |
| 137 | (make-obsolete 'encode-time-value nil "25.1") | 139 | (make-obsolete 'with-decoded-time-value nil "25.1") |
| 138 | (make-obsolete 'with-decoded-time-value nil "25.1")) | ||
| 139 | 140 | ||
| 140 | (autoload 'parse-time-string "parse-time") | 141 | (autoload 'parse-time-string "parse-time") |
| 141 | (autoload 'timezone-make-date-arpa-standard "timezone") | 142 | (autoload 'timezone-make-date-arpa-standard "timezone") |
| @@ -163,27 +164,8 @@ If DATE lacks timezone information, GMT is assumed." | |||
| 163 | (apply 'signal err) | 164 | (apply 'signal err) |
| 164 | (error "Invalid date: %s" date))))))))) | 165 | (error "Invalid date: %s" date))))))))) |
| 165 | 166 | ||
| 166 | ;; Bit of a mess. Emacs has float-time since at least 21.1. | 167 | ;;;###autoload |
| 167 | ;; This file is synced to Gnus, and XEmacs packages may have been written | 168 | (defalias 'time-to-seconds 'float-time) |
| 168 | ;; using time-to-seconds from the Gnus library. | ||
| 169 | ;;;###autoload(if (or (featurep 'emacs) | ||
| 170 | ;;;###autoload (and (fboundp 'float-time) | ||
| 171 | ;;;###autoload (subrp (symbol-function 'float-time)))) | ||
| 172 | ;;;###autoload (defalias 'time-to-seconds 'float-time) | ||
| 173 | ;;;###autoload (autoload 'time-to-seconds "time-date")) | ||
| 174 | |||
| 175 | (eval-when-compile | ||
| 176 | (or (featurep 'emacs) | ||
| 177 | (and (fboundp 'float-time) | ||
| 178 | (subrp (symbol-function 'float-time))) | ||
| 179 | (defun time-to-seconds (&optional time) | ||
| 180 | "Convert optional value TIME to a floating point number. | ||
| 181 | TIME defaults to the current time." | ||
| 182 | (with-decoded-time-value ((high low micro pico _type | ||
| 183 | (or time (current-time)))) | ||
| 184 | (+ (* high 65536.0) | ||
| 185 | low | ||
| 186 | (/ (+ (* micro 1e6) pico) 1e12)))))) | ||
| 187 | 169 | ||
| 188 | ;;;###autoload | 170 | ;;;###autoload |
| 189 | (defun seconds-to-time (seconds) | 171 | (defun seconds-to-time (seconds) |
| @@ -209,68 +191,7 @@ TIME should be either a time value or a date-time string." | |||
| 209 | (time-subtract nil time)) | 191 | (time-subtract nil time)) |
| 210 | 192 | ||
| 211 | ;;;###autoload | 193 | ;;;###autoload |
| 212 | (defalias 'subtract-time 'time-subtract) | 194 | (define-obsolete-function-alias 'subtract-time 'time-subtract "26.1") |
| 213 | |||
| 214 | ;; These autoloads do nothing in Emacs 25, where the functions are builtin. | ||
| 215 | ;;;###autoload(autoload 'time-add "time-date") | ||
| 216 | ;;;###autoload(autoload 'time-subtract "time-date") | ||
| 217 | ;;;###autoload(autoload 'time-less-p "time-date") | ||
| 218 | |||
| 219 | (eval-and-compile | ||
| 220 | (when (not (and (fboundp 'time-add) (subrp (symbol-function 'time-add)))) | ||
| 221 | |||
| 222 | (defun time-add (t1 t2) | ||
| 223 | "Add two time values T1 and T2. One should represent a time difference." | ||
| 224 | (with-decoded-time-value ((high low micro pico type t1) | ||
| 225 | (high2 low2 micro2 pico2 type2 t2)) | ||
| 226 | (setq high (+ high high2) | ||
| 227 | low (+ low low2) | ||
| 228 | micro (+ micro micro2) | ||
| 229 | pico (+ pico pico2) | ||
| 230 | type (max type type2)) | ||
| 231 | (when (>= pico 1000000) | ||
| 232 | (setq micro (1+ micro) | ||
| 233 | pico (- pico 1000000))) | ||
| 234 | (when (>= micro 1000000) | ||
| 235 | (setq low (1+ low) | ||
| 236 | micro (- micro 1000000))) | ||
| 237 | (when (>= low 65536) | ||
| 238 | (setq high (1+ high) | ||
| 239 | low (- low 65536))) | ||
| 240 | (encode-time-value high low micro pico type))) | ||
| 241 | |||
| 242 | (defun time-subtract (t1 t2) | ||
| 243 | "Subtract two time values, T1 minus T2. | ||
| 244 | Return the difference in the format of a time value." | ||
| 245 | (with-decoded-time-value ((high low micro pico type t1) | ||
| 246 | (high2 low2 micro2 pico2 type2 t2)) | ||
| 247 | (setq high (- high high2) | ||
| 248 | low (- low low2) | ||
| 249 | micro (- micro micro2) | ||
| 250 | pico (- pico pico2) | ||
| 251 | type (max type type2)) | ||
| 252 | (when (< pico 0) | ||
| 253 | (setq micro (1- micro) | ||
| 254 | pico (+ pico 1000000))) | ||
| 255 | (when (< micro 0) | ||
| 256 | (setq low (1- low) | ||
| 257 | micro (+ micro 1000000))) | ||
| 258 | (when (< low 0) | ||
| 259 | (setq high (1- high) | ||
| 260 | low (+ low 65536))) | ||
| 261 | (encode-time-value high low micro pico type))) | ||
| 262 | |||
| 263 | (defun time-less-p (t1 t2) | ||
| 264 | "Return non-nil if time value T1 is earlier than time value T2." | ||
| 265 | (with-decoded-time-value ((high1 low1 micro1 pico1 _type1 t1) | ||
| 266 | (high2 low2 micro2 pico2 _type2 t2)) | ||
| 267 | (or (< high1 high2) | ||
| 268 | (and (= high1 high2) | ||
| 269 | (or (< low1 low2) | ||
| 270 | (and (= low1 low2) | ||
| 271 | (or (< micro1 micro2) | ||
| 272 | (and (= micro1 micro2) | ||
| 273 | (< pico1 pico2))))))))))) | ||
| 274 | 195 | ||
| 275 | ;;;###autoload | 196 | ;;;###autoload |
| 276 | (defun date-to-day (date) | 197 | (defun date-to-day (date) |
| @@ -324,12 +245,7 @@ The Gregorian date Sunday, December 31, 1bce is imaginary." | |||
| 324 | (defun time-to-number-of-days (time) | 245 | (defun time-to-number-of-days (time) |
| 325 | "Return the number of days represented by TIME. | 246 | "Return the number of days represented by TIME. |
| 326 | Returns a floating point number." | 247 | Returns a floating point number." |
| 327 | (/ (funcall (eval-when-compile | 248 | (/ (float-time time) (* 60 60 24))) |
| 328 | (if (or (featurep 'emacs) | ||
| 329 | (and (fboundp 'float-time) | ||
| 330 | (subrp (symbol-function 'float-time)))) | ||
| 331 | 'float-time | ||
| 332 | 'time-to-seconds)) time) (* 60 60 24))) | ||
| 333 | 249 | ||
| 334 | ;;;###autoload | 250 | ;;;###autoload |
| 335 | (defun safe-date-to-time (date) | 251 | (defun safe-date-to-time (date) |
diff --git a/lisp/calendar/timeclock.el b/lisp/calendar/timeclock.el index 2bdfd98344a..3d9e2462224 100644 --- a/lisp/calendar/timeclock.el +++ b/lisp/calendar/timeclock.el | |||
| @@ -532,18 +532,17 @@ non-nil, the amount returned will be relative to past time worked." | |||
| 532 | (message "%s" string) | 532 | (message "%s" string) |
| 533 | string))) | 533 | string))) |
| 534 | 534 | ||
| 535 | (defalias 'timeclock-time-to-seconds (if (fboundp 'float-time) 'float-time | 535 | (define-obsolete-function-alias 'timeclock-time-to-seconds 'float-time "26.1") |
| 536 | 'time-to-seconds)) | 536 | (define-obsolete-function-alias 'timeclock-seconds-to-time 'seconds-to-time |
| 537 | 537 | "26.1") | |
| 538 | (defalias 'timeclock-seconds-to-time 'seconds-to-time) | ||
| 539 | 538 | ||
| 540 | ;; Should today-only be removed in favor of timeclock-relative? - gm | 539 | ;; Should today-only be removed in favor of timeclock-relative? - gm |
| 541 | (defsubst timeclock-when-to-leave (&optional today-only) | 540 | (defsubst timeclock-when-to-leave (&optional today-only) |
| 542 | "Return a time value representing the end of today's workday. | 541 | "Return a time value representing the end of today's workday. |
| 543 | If TODAY-ONLY is non-nil, the value returned will be relative only to | 542 | If TODAY-ONLY is non-nil, the value returned will be relative only to |
| 544 | the time worked today, and not to past time." | 543 | the time worked today, and not to past time." |
| 545 | (timeclock-seconds-to-time | 544 | (seconds-to-time |
| 546 | (- (timeclock-time-to-seconds) | 545 | (- (float-time) |
| 547 | (let ((discrep (timeclock-find-discrep))) | 546 | (let ((discrep (timeclock-find-discrep))) |
| 548 | (if discrep | 547 | (if discrep |
| 549 | (if today-only | 548 | (if today-only |
| @@ -686,9 +685,8 @@ being logged for. Normally only \"in\" events specify a project." | |||
| 686 | "\n") | 685 | "\n") |
| 687 | (if (equal (downcase code) "o") | 686 | (if (equal (downcase code) "o") |
| 688 | (setq timeclock-last-period | 687 | (setq timeclock-last-period |
| 689 | (- (timeclock-time-to-seconds now) | 688 | (- (float-time now) |
| 690 | (timeclock-time-to-seconds | 689 | (float-time (cadr timeclock-last-event))) |
| 691 | (cadr timeclock-last-event))) | ||
| 692 | timeclock-discrepancy | 690 | timeclock-discrepancy |
| 693 | (+ timeclock-discrepancy | 691 | (+ timeclock-discrepancy |
| 694 | timeclock-last-period))) | 692 | timeclock-last-period))) |
| @@ -723,14 +721,14 @@ recorded to disk. If MOMENT is non-nil, use that as the current time. | |||
| 723 | This is only provided for coherency when used by | 721 | This is only provided for coherency when used by |
| 724 | `timeclock-discrepancy'." | 722 | `timeclock-discrepancy'." |
| 725 | (if (equal (car timeclock-last-event) "i") | 723 | (if (equal (car timeclock-last-event) "i") |
| 726 | (- (timeclock-time-to-seconds moment) | 724 | (- (float-time moment) |
| 727 | (timeclock-time-to-seconds (cadr timeclock-last-event))) | 725 | (float-time (cadr timeclock-last-event))) |
| 728 | timeclock-last-period)) | 726 | timeclock-last-period)) |
| 729 | 727 | ||
| 730 | (defsubst timeclock-entry-length (entry) | 728 | (defsubst timeclock-entry-length (entry) |
| 731 | "Return the length of ENTRY in seconds." | 729 | "Return the length of ENTRY in seconds." |
| 732 | (- (timeclock-time-to-seconds (cadr entry)) | 730 | (- (float-time (cadr entry)) |
| 733 | (timeclock-time-to-seconds (car entry)))) | 731 | (float-time (car entry)))) |
| 734 | 732 | ||
| 735 | (defsubst timeclock-entry-begin (entry) | 733 | (defsubst timeclock-entry-begin (entry) |
| 736 | "Return the start time of ENTRY." | 734 | "Return the start time of ENTRY." |
| @@ -765,8 +763,8 @@ This is only provided for coherency when used by | |||
| 765 | 763 | ||
| 766 | (defsubst timeclock-entry-list-span (entry-list) | 764 | (defsubst timeclock-entry-list-span (entry-list) |
| 767 | "Return the total time in seconds spanned by ENTRY-LIST." | 765 | "Return the total time in seconds spanned by ENTRY-LIST." |
| 768 | (- (timeclock-time-to-seconds (timeclock-entry-list-end entry-list)) | 766 | (- (float-time (timeclock-entry-list-end entry-list)) |
| 769 | (timeclock-time-to-seconds (timeclock-entry-list-begin entry-list)))) | 767 | (float-time (timeclock-entry-list-begin entry-list)))) |
| 770 | 768 | ||
| 771 | (defsubst timeclock-entry-list-break (entry-list) | 769 | (defsubst timeclock-entry-list-break (entry-list) |
| 772 | "Return the total break time (span - length) in ENTRY-LIST." | 770 | "Return the total break time (span - length) in ENTRY-LIST." |
| @@ -1137,7 +1135,7 @@ discrepancy, today's discrepancy, and the time worked today." | |||
| 1137 | last-date-limited nil) | 1135 | last-date-limited nil) |
| 1138 | (if beg | 1136 | (if beg |
| 1139 | (error "Error in format of timelog file!") | 1137 | (error "Error in format of timelog file!") |
| 1140 | (setq beg (timeclock-time-to-seconds (cadr event)))))) | 1138 | (setq beg (float-time (cadr event)))))) |
| 1141 | ((equal (downcase (car event)) "o") | 1139 | ((equal (downcase (car event)) "o") |
| 1142 | (if (and (nth 2 event) | 1140 | (if (and (nth 2 event) |
| 1143 | (> (length (nth 2 event)) 0)) | 1141 | (> (length (nth 2 event)) 0)) |
| @@ -1145,7 +1143,7 @@ discrepancy, today's discrepancy, and the time worked today." | |||
| 1145 | (if (not beg) | 1143 | (if (not beg) |
| 1146 | (error "Error in format of timelog file!") | 1144 | (error "Error in format of timelog file!") |
| 1147 | (setq timeclock-last-period | 1145 | (setq timeclock-last-period |
| 1148 | (- (timeclock-time-to-seconds (cadr event)) beg) | 1146 | (- (float-time (cadr event)) beg) |
| 1149 | accum (+ timeclock-last-period accum) | 1147 | accum (+ timeclock-last-period accum) |
| 1150 | beg nil)) | 1148 | beg nil)) |
| 1151 | (if (equal last-date todays-date) | 1149 | (if (equal last-date todays-date) |
| @@ -1225,8 +1223,8 @@ HTML-P is non-nil, HTML markup is added." | |||
| 1225 | (insert project "</b><br>\n") | 1223 | (insert project "</b><br>\n") |
| 1226 | (insert project "*\n")) | 1224 | (insert project "*\n")) |
| 1227 | (let ((proj-data (cdr (assoc project (timeclock-project-alist log)))) | 1225 | (let ((proj-data (cdr (assoc project (timeclock-project-alist log)))) |
| 1228 | (two-weeks-ago (timeclock-seconds-to-time | 1226 | (two-weeks-ago (seconds-to-time |
| 1229 | (- (timeclock-time-to-seconds today) | 1227 | (- (float-time today) |
| 1230 | (* 2 7 24 60 60)))) | 1228 | (* 2 7 24 60 60)))) |
| 1231 | two-week-len today-len) | 1229 | two-week-len today-len) |
| 1232 | (while proj-data | 1230 | (while proj-data |
| @@ -1278,17 +1276,17 @@ HTML-P is non-nil, HTML markup is added." | |||
| 1278 | <th>-1 year</th> | 1276 | <th>-1 year</th> |
| 1279 | </tr>") | 1277 | </tr>") |
| 1280 | (let* ((day-list (timeclock-day-list)) | 1278 | (let* ((day-list (timeclock-day-list)) |
| 1281 | (thirty-days-ago (timeclock-seconds-to-time | 1279 | (thirty-days-ago (seconds-to-time |
| 1282 | (- (timeclock-time-to-seconds today) | 1280 | (- (float-time today) |
| 1283 | (* 30 24 60 60)))) | 1281 | (* 30 24 60 60)))) |
| 1284 | (three-months-ago (timeclock-seconds-to-time | 1282 | (three-months-ago (seconds-to-time |
| 1285 | (- (timeclock-time-to-seconds today) | 1283 | (- (float-time today) |
| 1286 | (* 90 24 60 60)))) | 1284 | (* 90 24 60 60)))) |
| 1287 | (six-months-ago (timeclock-seconds-to-time | 1285 | (six-months-ago (seconds-to-time |
| 1288 | (- (timeclock-time-to-seconds today) | 1286 | (- (float-time today) |
| 1289 | (* 180 24 60 60)))) | 1287 | (* 180 24 60 60)))) |
| 1290 | (one-year-ago (timeclock-seconds-to-time | 1288 | (one-year-ago (seconds-to-time |
| 1291 | (- (timeclock-time-to-seconds today) | 1289 | (- (float-time today) |
| 1292 | (* 365 24 60 60)))) | 1290 | (* 365 24 60 60)))) |
| 1293 | (time-in (vector (list t) (list t) (list t) (list t) (list t))) | 1291 | (time-in (vector (list t) (list t) (list t) (list t) (list t))) |
| 1294 | (time-out (vector (list t) (list t) (list t) (list t) (list t))) | 1292 | (time-out (vector (list t) (list t) (list t) (list t) (list t))) |
| @@ -1303,12 +1301,11 @@ HTML-P is non-nil, HTML markup is added." | |||
| 1303 | (unless (time-less-p | 1301 | (unless (time-less-p |
| 1304 | (timeclock-day-begin day) | 1302 | (timeclock-day-begin day) |
| 1305 | (aref lengths i)) | 1303 | (aref lengths i)) |
| 1306 | (let ((base (timeclock-time-to-seconds | 1304 | (let ((base (float-time |
| 1307 | (timeclock-day-base | 1305 | (timeclock-day-base |
| 1308 | (timeclock-day-begin day))))) | 1306 | (timeclock-day-begin day))))) |
| 1309 | (nconc (aref time-in i) | 1307 | (nconc (aref time-in i) |
| 1310 | (list (- (timeclock-time-to-seconds | 1308 | (list (- (float-time (timeclock-day-begin day)) |
| 1311 | (timeclock-day-begin day)) | ||
| 1312 | base))) | 1309 | base))) |
| 1313 | (let ((span (timeclock-day-span day)) | 1310 | (let ((span (timeclock-day-span day)) |
| 1314 | (len (timeclock-day-length day)) | 1311 | (len (timeclock-day-length day)) |
| @@ -1320,8 +1317,7 @@ HTML-P is non-nil, HTML markup is added." | |||
| 1320 | (when (and (> span 0) | 1317 | (when (and (> span 0) |
| 1321 | (> (/ (float len) (float span)) 0.70)) | 1318 | (> (/ (float len) (float span)) 0.70)) |
| 1322 | (nconc (aref time-out i) | 1319 | (nconc (aref time-out i) |
| 1323 | (list (- (timeclock-time-to-seconds | 1320 | (list (- (float-time (timeclock-day-end day)) |
| 1324 | (timeclock-day-end day)) | ||
| 1325 | base))) | 1321 | base))) |
| 1326 | (nconc (aref breaks i) (list (- span len)))) | 1322 | (nconc (aref breaks i) (list (- span len)))) |
| 1327 | (if req | 1323 | (if req |