diff options
| author | Glenn Morris | 2008-02-14 08:59:43 +0000 |
|---|---|---|
| committer | Glenn Morris | 2008-02-14 08:59:43 +0000 |
| commit | 6afa3d67702997b48f3732a6097b480b587bbb36 (patch) | |
| tree | 85785a8a7f98fb95587b595404b3234e5b9fa239 /lisp | |
| parent | f3ff0fe9acc03f05f6077cf075eb27aedd101210 (diff) | |
| download | emacs-6afa3d67702997b48f3732a6097b480b587bbb36.tar.gz emacs-6afa3d67702997b48f3732a6097b480b587bbb36.zip | |
Re-fill copyright years.
(format-seconds): New function.
(emacs-uptime): Use format-seconds.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/ChangeLog | 5 | ||||
| -rw-r--r-- | lisp/calendar/time-date.el | 113 |
2 files changed, 90 insertions, 28 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index a7a873a74bb..3739d945dbb 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -7,10 +7,13 @@ | |||
| 7 | 7 | ||
| 8 | 2008-02-14 Glenn Morris <rgm@gnu.org> | 8 | 2008-02-14 Glenn Morris <rgm@gnu.org> |
| 9 | 9 | ||
| 10 | * calendar/time-date.el (format-seconds): New function. | ||
| 11 | (emacs-uptime): Use format-seconds. | ||
| 12 | |||
| 10 | * Makefile.in (custom-deps, finder-data, autoloads, recompile): | 13 | * Makefile.in (custom-deps, finder-data, autoloads, recompile): |
| 11 | Remove `LC_ALL=C', since it's included in $(emacs) now. | 14 | Remove `LC_ALL=C', since it's included in $(emacs) now. |
| 12 | 15 | ||
| 13 | 2008-02-14 Zhang Wei <id.brep@gmail.com> (tiny change) | 16 | 2008-02-14 Zhang Wei <id.brep@gmail.com> (tiny change) |
| 14 | 17 | ||
| 15 | * textmodes/org-publish.el (org-publish-timestamp-filename): | 18 | * textmodes/org-publish.el (org-publish-timestamp-filename): |
| 16 | Replace colon characters in filename too. | 19 | Replace colon characters in filename too. |
diff --git a/lisp/calendar/time-date.el b/lisp/calendar/time-date.el index 1f325379a48..9141dd5ed72 100644 --- a/lisp/calendar/time-date.el +++ b/lisp/calendar/time-date.el | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | ;;; time-date.el --- Date and time handling functions | 1 | ;;; time-date.el --- Date and time handling functions |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 | 3 | ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, |
| 4 | ;; Free Software Foundation, Inc. | 4 | ;; 2007, 2008 Free Software Foundation, Inc. |
| 5 | 5 | ||
| 6 | ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org> | 6 | ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org> |
| 7 | ;; Masanobu Umeda <umerin@mse.kyutech.ac.jp> | 7 | ;; Masanobu Umeda <umerin@mse.kyutech.ac.jp> |
| @@ -256,34 +256,93 @@ If DATE is malformed, return a time value of zeros." | |||
| 256 | 256 | ||
| 257 | 257 | ||
| 258 | ;;;###autoload | 258 | ;;;###autoload |
| 259 | (defun format-seconds (string seconds &optional nonzero) | ||
| 260 | "Use format control STRING to format the number SECONDS. | ||
| 261 | The valid format specifiers are: | ||
| 262 | %y is the number of (365-day) years. | ||
| 263 | %d is the number of days. | ||
| 264 | %h is the number of hours. | ||
| 265 | %m is the number of minutes. | ||
| 266 | %s is the number of seconds. | ||
| 267 | %% is a literal \"%\". | ||
| 268 | |||
| 269 | Upper-case specifiers are followed by the unit-name (e.g. \"years\"). | ||
| 270 | Lower-case specifiers return only the unit. | ||
| 271 | |||
| 272 | \"%\" may be followed by a number specifying a width, with an | ||
| 273 | optional leading \".\" for zero-padding. For example, \"%.3Y\" will | ||
| 274 | return something of the form \"001 year\". | ||
| 275 | |||
| 276 | If the optional argument NONZERO is non-nil, then nothing is output until | ||
| 277 | the first non-zero unit (or the last unit) is encountered. In this case, | ||
| 278 | specifiers must be used in order of decreasing size. | ||
| 279 | |||
| 280 | This does not work for input SECONDS greater than `most-positive-fixnum'." | ||
| 281 | (let ((start 0) | ||
| 282 | (units '(("y" "year" 31536000) | ||
| 283 | ("d" "day" 86400) | ||
| 284 | ("h" "hour" 3600) | ||
| 285 | ("m" "minute" 60) | ||
| 286 | ("s" "second" 1))) | ||
| 287 | (case-fold-search t) | ||
| 288 | spec match outunits unit prev name next) | ||
| 289 | (setq nonzero (not nonzero)) | ||
| 290 | (while (string-match "%\\.?[0-9]*\\(.\\)" string start) | ||
| 291 | (setq start (match-end 0) | ||
| 292 | spec (match-string 1 string)) | ||
| 293 | (unless (string-equal spec "%") | ||
| 294 | (or (setq match (assoc-string spec units t)) | ||
| 295 | (error "Bad format specifier: `%s'" spec)) | ||
| 296 | (if (assoc-string spec outunits t) | ||
| 297 | (error "Multiple instances of specifier: `%s'" spec)) | ||
| 298 | (unless nonzero | ||
| 299 | (setq unit (nth 2 match)) | ||
| 300 | (and prev (> unit prev) | ||
| 301 | (error "Units are not in decreasing order of size")) | ||
| 302 | (setq prev unit)) | ||
| 303 | (push match outunits))) | ||
| 304 | ;; Cf article-make-date-line in gnus-art. | ||
| 305 | (dolist (ulist units) | ||
| 306 | (setq spec (car ulist) | ||
| 307 | name (cadr ulist) | ||
| 308 | unit (nth 2 ulist)) | ||
| 309 | (when (string-match (format "%%\\(\\.?[0-9]+\\)?\\(%s\\)" spec) string) | ||
| 310 | (setq num (floor seconds unit) | ||
| 311 | seconds (- seconds (* num unit))) | ||
| 312 | (or nonzero | ||
| 313 | (setq nonzero (not (zerop num))) | ||
| 314 | ;; Start of the next unit specifier, if there is one. | ||
| 315 | (setq next (save-match-data | ||
| 316 | (string-match "%\\.?[0-9]*[a-z]" | ||
| 317 | string (match-end 0))))) | ||
| 318 | ;; If there are no more specifiers, we have to print this one, | ||
| 319 | ;; even if it is zero. | ||
| 320 | (or nonzero (setq nonzero (not next))) | ||
| 321 | (setq string | ||
| 322 | (if nonzero | ||
| 323 | (replace-match | ||
| 324 | (format (concat "%" (match-string 1 string) "d%s") num | ||
| 325 | (if (string-equal (match-string 2 string) spec) | ||
| 326 | "" ; lower-case, no unit-name | ||
| 327 | (format " %s%s" name | ||
| 328 | (if (= num 1) "" "s")))) | ||
| 329 | t t string) | ||
| 330 | ;; If we haven't found a non-zero unit yet, delete | ||
| 331 | ;; everything up to the next format specifier. | ||
| 332 | (substring string next)))))) | ||
| 333 | (replace-regexp-in-string "%%" "%" string)) | ||
| 334 | |||
| 335 | |||
| 336 | ;; This doesn't really belong here - perhaps in time.el? | ||
| 337 | ;;;###autoload | ||
| 259 | (defun emacs-uptime () | 338 | (defun emacs-uptime () |
| 260 | "Return a string giving the uptime of this instance of Emacs." | 339 | "Return a string giving the uptime of this instance of Emacs." |
| 261 | (interactive) | 340 | (interactive) |
| 262 | (let* ((sec (time-to-seconds | 341 | (let ((str |
| 263 | (time-subtract (current-time) emacs-startup-time))) | 342 | (format-seconds "%Y, %D, %H, %M, %S" |
| 264 | (prev) | 343 | (time-to-seconds |
| 265 | (num) | 344 | (time-subtract (current-time) emacs-startup-time)) |
| 266 | (str | 345 | t))) |
| 267 | ;; cf article-make-date-line in gnus-art. | ||
| 268 | ;; Worth having a general time-date `format-seconds' | ||
| 269 | ;; function that converts a number of seconds into so many | ||
| 270 | ;; years, hours, etc? | ||
| 271 | (mapconcat | ||
| 272 | (lambda (unit) | ||
| 273 | (if (zerop (setq num (floor sec (cdr unit)))) | ||
| 274 | "" | ||
| 275 | (setq sec (- sec (* num (cdr unit)))) | ||
| 276 | (prog1 | ||
| 277 | (format "%s%d %s%s" (if prev ", " "") num | ||
| 278 | (symbol-name (car unit)) | ||
| 279 | (if (= num 1) "" "s")) | ||
| 280 | (setq prev t)))) | ||
| 281 | '((year . 31536000) ; 365-day year | ||
| 282 | (day . 86400) | ||
| 283 | (hour . 3600) | ||
| 284 | (minute . 60) | ||
| 285 | (second . 1)) | ||
| 286 | ""))) | ||
| 287 | (if (interactive-p) | 346 | (if (interactive-p) |
| 288 | (message "%s" str) | 347 | (message "%s" str) |
| 289 | str))) | 348 | str))) |