Mercurial > emacs
annotate lisp/calendar/time-date.el @ 110330:b68d97301050
time-date.el (format-seconds): Comment fix.
author | Katsumi Yamaoka <yamaoka@jpl.org> |
---|---|
date | Tue, 14 Sep 2010 06:01:14 +0000 |
parents | 8d09094063d0 |
children | eb4a332b45f5 |
rev | line source |
---|---|
61260
ae865a366a88
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-230
Miles Bader <miles@gnu.org>
parents:
60847
diff
changeset
|
1 ;;; time-date.el --- Date and time handling functions |
67465
a55ee709ec8d
Update copyright pending Emacs 22.
Glenn Morris <rgm@gnu.org>
parents:
65824
diff
changeset
|
2 |
91831 | 3 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, |
106815 | 4 ;; 2007, 2008, 2009, 2010 Free Software Foundation, Inc. |
43049
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
5 |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org> |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
7 ;; Masanobu Umeda <umerin@mse.kyutech.ac.jp> |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
8 ;; Keywords: mail news util |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
9 |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
10 ;; This file is part of GNU Emacs. |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
11 |
94653
e49abd957e81
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
12 ;; GNU Emacs is free software: you can redistribute it and/or modify |
43049
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
13 ;; it under the terms of the GNU General Public License as published by |
94653
e49abd957e81
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
14 ;; the Free Software Foundation, either version 3 of the License, or |
e49abd957e81
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
15 ;; (at your option) any later version. |
43049
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
16 |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
17 ;; GNU Emacs is distributed in the hope that it will be useful, |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
94653
e49abd957e81
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
43049
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
20 ;; GNU General Public License for more details. |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
21 |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
22 ;; You should have received a copy of the GNU General Public License |
94653
e49abd957e81
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
43049
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
24 |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
25 ;;; Commentary: |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
26 |
60847
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
27 ;; Time values come in three formats. The oldest format is a cons |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
28 ;; cell of the form (HIGH . LOW). This format is obsolete, but still |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
29 ;; supported. The two other formats are the lists (HIGH LOW) and |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
30 ;; (HIGH LOW MICRO). The first two formats specify HIGH * 2^16 + LOW |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
31 ;; seconds; the third format specifies HIGH * 2^16 + LOW + MICRO / |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
32 ;; 1000000 seconds. We should have 0 <= MICRO < 1000000 and 0 <= LOW |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
33 ;; < 2^16. If the time value represents a point in time, then HIGH is |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
34 ;; nonnegative. If the time value is a time difference, then HIGH can |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
35 ;; be negative as well. The macro `with-decoded-time-value' and the |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
36 ;; function `encode-time-value' make it easier to deal with these |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
37 ;; three formats. See `time-subtract' for an example of how to use |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
38 ;; them. |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
39 |
43049
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
40 ;;; Code: |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
41 |
100993 | 42 ;; Only necessary for `declare' when compiling Gnus with Emacs 21. |
43 (eval-when-compile (require 'cl)) | |
44 | |
60847
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
45 (defmacro with-decoded-time-value (varlist &rest body) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
46 "Decode a time value and bind it according to VARLIST, then eval BODY. |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
47 |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
48 The value of the last form in BODY is returned. |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
49 |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
50 Each element of the list VARLIST is a list of the form |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
51 \(HIGH-SYMBOL LOW-SYMBOL MICRO-SYMBOL [TYPE-SYMBOL] TIME-VALUE). |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
52 The time value TIME-VALUE is decoded and the result it bound to |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
53 the symbols HIGH-SYMBOL, LOW-SYMBOL and MICRO-SYMBOL. |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
54 |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
55 The optional TYPE-SYMBOL is bound to the type of the time value. |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
56 Type 0 is the cons cell (HIGH . LOW), type 1 is the list (HIGH |
79502
392f18d2007a
(with-decoded-time-value): Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
79501
diff
changeset
|
57 LOW), and type 2 is the list (HIGH LOW MICRO)." |
60847
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
58 (declare (indent 1) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
59 (debug ((&rest (symbolp symbolp symbolp &or [symbolp form] form)) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
60 body))) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
61 (if varlist |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
62 (let* ((elt (pop varlist)) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
63 (high (pop elt)) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
64 (low (pop elt)) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
65 (micro (pop elt)) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
66 (type (unless (eq (length elt) 1) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
67 (pop elt))) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
68 (time-value (car elt)) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
69 (gensym (make-symbol "time"))) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
70 `(let* ,(append `((,gensym ,time-value) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
71 (,high (pop ,gensym)) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
72 ,low ,micro) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
73 (when type `(,type))) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
74 (if (consp ,gensym) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
75 (progn |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
76 (setq ,low (pop ,gensym)) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
77 (if ,gensym |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
78 ,(append `(setq ,micro (car ,gensym)) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
79 (when type `(,type 2))) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
80 ,(append `(setq ,micro 0) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
81 (when type `(,type 1))))) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
82 ,(append `(setq ,low ,gensym ,micro 0) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
83 (when type `(,type 0)))) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
84 (with-decoded-time-value ,varlist ,@body))) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
85 `(progn ,@body))) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
86 |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
87 (defun encode-time-value (high low micro type) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
88 "Encode HIGH, LOW, and MICRO into a time value of type TYPE. |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
89 Type 0 is the cons cell (HIGH . LOW), type 1 is the list (HIGH LOW), |
79501
5bd82d58227e
Ari Roponen <ari.roponen at gmail.com> (tiny change)
Glenn Morris <rgm@gnu.org>
parents:
78216
diff
changeset
|
90 and type 2 is the list (HIGH LOW MICRO)." |
60847
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
91 (cond |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
92 ((eq type 0) (cons high low)) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
93 ((eq type 1) (list high low)) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
94 ((eq type 2) (list high low micro)))) |
43049
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
95 |
65824
4f45bcb69451
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-572
Miles Bader <miles@gnu.org>
parents:
64085
diff
changeset
|
96 (autoload 'parse-time-string "parse-time") |
43049
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
97 (autoload 'timezone-make-date-arpa-standard "timezone") |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
98 |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
99 ;;;###autoload |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
100 (defun date-to-time (date) |
106900
e3970f7c14d4
Doc fix for current-time-string and date-to-time (Bug#5408)
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
101 "Parse a string DATE that represents a date-time and return a time value. |
e3970f7c14d4
Doc fix for current-time-string and date-to-time (Bug#5408)
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
102 If DATE lacks timezone information, GMT is assumed." |
43049
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
103 (condition-case () |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
104 (apply 'encode-time |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
105 (parse-time-string |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
106 ;; `parse-time-string' isn't sufficiently general or |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
107 ;; robust. It fails to grok some of the formats that |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
56797
diff
changeset
|
108 ;; timezone does (e.g. dodgy post-2000 stuff from some |
43049
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
109 ;; Elms) and either fails or returns bogus values. Lars |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
110 ;; reverted this change, but that loses non-trivially |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
111 ;; often for me. -- fx |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
112 (timezone-make-date-arpa-standard date))) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
113 (error (error "Invalid date: %s" date)))) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
114 |
104798
b04b1ea82ee0
(time-to-seconds): In Emacs, make it an obsolete alias for float-time.
Glenn Morris <rgm@gnu.org>
parents:
100993
diff
changeset
|
115 ;; Bit of a mess. Emacs has float-time since at least 21.1. |
b04b1ea82ee0
(time-to-seconds): In Emacs, make it an obsolete alias for float-time.
Glenn Morris <rgm@gnu.org>
parents:
100993
diff
changeset
|
116 ;; This file is synced to Gnus, and XEmacs packages may have been written |
b04b1ea82ee0
(time-to-seconds): In Emacs, make it an obsolete alias for float-time.
Glenn Morris <rgm@gnu.org>
parents:
100993
diff
changeset
|
117 ;; using time-to-seconds from the Gnus library. |
104890
2e22af528b76
* calendar/time-date.el (autoload):
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
104798
diff
changeset
|
118 ;;;###autoload(if (and (fboundp 'float-time) |
2e22af528b76
* calendar/time-date.el (autoload):
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
104798
diff
changeset
|
119 ;;;###autoload (subrp (symbol-function 'float-time))) |
2e22af528b76
* calendar/time-date.el (autoload):
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
104798
diff
changeset
|
120 ;;;###autoload (progn |
2e22af528b76
* calendar/time-date.el (autoload):
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
104798
diff
changeset
|
121 ;;;###autoload (defalias 'time-to-seconds 'float-time) |
2e22af528b76
* calendar/time-date.el (autoload):
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
104798
diff
changeset
|
122 ;;;###autoload (make-obsolete 'time-to-seconds 'float-time "21.1")) |
2e22af528b76
* calendar/time-date.el (autoload):
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
104798
diff
changeset
|
123 ;;;###autoload (autoload 'time-to-seconds "time-date")) |
104798
b04b1ea82ee0
(time-to-seconds): In Emacs, make it an obsolete alias for float-time.
Glenn Morris <rgm@gnu.org>
parents:
100993
diff
changeset
|
124 |
104890
2e22af528b76
* calendar/time-date.el (autoload):
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
104798
diff
changeset
|
125 (eval-and-compile |
2e22af528b76
* calendar/time-date.el (autoload):
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
104798
diff
changeset
|
126 (unless (and (fboundp 'float-time) |
2e22af528b76
* calendar/time-date.el (autoload):
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
104798
diff
changeset
|
127 (subrp (symbol-function 'float-time))) |
104798
b04b1ea82ee0
(time-to-seconds): In Emacs, make it an obsolete alias for float-time.
Glenn Morris <rgm@gnu.org>
parents:
100993
diff
changeset
|
128 (defun time-to-seconds (time) |
b04b1ea82ee0
(time-to-seconds): In Emacs, make it an obsolete alias for float-time.
Glenn Morris <rgm@gnu.org>
parents:
100993
diff
changeset
|
129 "Convert time value TIME to a floating point number." |
b04b1ea82ee0
(time-to-seconds): In Emacs, make it an obsolete alias for float-time.
Glenn Morris <rgm@gnu.org>
parents:
100993
diff
changeset
|
130 (with-decoded-time-value ((high low micro time)) |
104890
2e22af528b76
* calendar/time-date.el (autoload):
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
104798
diff
changeset
|
131 (+ (* 1.0 high 65536) |
2e22af528b76
* calendar/time-date.el (autoload):
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
104798
diff
changeset
|
132 low |
2e22af528b76
* calendar/time-date.el (autoload):
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
104798
diff
changeset
|
133 (/ micro 1000000.0)))))) |
2e22af528b76
* calendar/time-date.el (autoload):
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
104798
diff
changeset
|
134 |
2e22af528b76
* calendar/time-date.el (autoload):
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
104798
diff
changeset
|
135 (eval-when-compile |
2e22af528b76
* calendar/time-date.el (autoload):
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
104798
diff
changeset
|
136 (unless (fboundp 'with-no-warnings) |
2e22af528b76
* calendar/time-date.el (autoload):
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
104798
diff
changeset
|
137 (defmacro with-no-warnings (&rest body) |
2e22af528b76
* calendar/time-date.el (autoload):
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
104798
diff
changeset
|
138 `(progn ,@body)))) |
43049
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
139 |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
140 ;;;###autoload |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
141 (defun seconds-to-time (seconds) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
142 "Convert SECONDS (a floating point number) to a time value." |
61424
ad05d91d3598
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-243
Miles Bader <miles@gnu.org>
parents:
61260
diff
changeset
|
143 (list (floor seconds 65536) |
ad05d91d3598
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-243
Miles Bader <miles@gnu.org>
parents:
61260
diff
changeset
|
144 (floor (mod seconds 65536)) |
43049
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
145 (floor (* (- seconds (ffloor seconds)) 1000000)))) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
146 |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
147 ;;;###autoload |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
148 (defun time-less-p (t1 t2) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
149 "Say whether time value T1 is less than time value T2." |
60847
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
150 (with-decoded-time-value ((high1 low1 micro1 t1) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
151 (high2 low2 micro2 t2)) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
152 (or (< high1 high2) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
153 (and (= high1 high2) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
154 (or (< low1 low2) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
155 (and (= low1 low2) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
156 (< micro1 micro2))))))) |
43049
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
157 |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
158 ;;;###autoload |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
159 (defun days-to-time (days) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
160 "Convert DAYS into a time value." |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
161 (let* ((seconds (* 1.0 days 60 60 24)) |
61424
ad05d91d3598
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-243
Miles Bader <miles@gnu.org>
parents:
61260
diff
changeset
|
162 (high (condition-case nil (floor (/ seconds 65536)) |
60847
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
163 (range-error most-positive-fixnum)))) |
61424
ad05d91d3598
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-243
Miles Bader <miles@gnu.org>
parents:
61260
diff
changeset
|
164 (list high (condition-case nil (floor (- seconds (* 1.0 high 65536))) |
ad05d91d3598
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-243
Miles Bader <miles@gnu.org>
parents:
61260
diff
changeset
|
165 (range-error 65535))))) |
43049
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
166 |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
167 ;;;###autoload |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
168 (defun time-since (time) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
169 "Return the time elapsed since TIME. |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
170 TIME should be either a time value or a date-time string." |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
171 (when (stringp time) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
172 ;; Convert date strings to internal time. |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
173 (setq time (date-to-time time))) |
60847
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
174 (time-subtract (current-time) time)) |
43049
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
175 |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
176 ;;;###autoload |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
177 (defalias 'subtract-time 'time-subtract) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
178 |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
179 ;;;###autoload |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
180 (defun time-subtract (t1 t2) |
92632
870c7b456283
(date-to-time, time-subtract, time-add, safe-date-to-time): Doc fixes.
Glenn Morris <rgm@gnu.org>
parents:
91863
diff
changeset
|
181 "Subtract two time values, T1 minus T2. |
43049
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
182 Return the difference in the format of a time value." |
60847
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
183 (with-decoded-time-value ((high low micro type t1) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
184 (high2 low2 micro2 type2 t2)) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
185 (setq high (- high high2) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
186 low (- low low2) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
187 micro (- micro micro2) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
188 type (max type type2)) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
189 (when (< micro 0) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
190 (setq low (1- low) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
191 micro (+ micro 1000000))) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
192 (when (< low 0) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
193 (setq high (1- high) |
61424
ad05d91d3598
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-243
Miles Bader <miles@gnu.org>
parents:
61260
diff
changeset
|
194 low (+ low 65536))) |
60847
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
195 (encode-time-value high low micro type))) |
43049
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
196 |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
197 ;;;###autoload |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
198 (defun time-add (t1 t2) |
92632
870c7b456283
(date-to-time, time-subtract, time-add, safe-date-to-time): Doc fixes.
Glenn Morris <rgm@gnu.org>
parents:
91863
diff
changeset
|
199 "Add two time values T1 and T2. One should represent a time difference." |
60847
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
200 (with-decoded-time-value ((high low micro type t1) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
201 (high2 low2 micro2 type2 t2)) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
202 (setq high (+ high high2) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
203 low (+ low low2) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
204 micro (+ micro micro2) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
205 type (max type type2)) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
206 (when (>= micro 1000000) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
207 (setq low (1+ low) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
208 micro (- micro 1000000))) |
61424
ad05d91d3598
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-243
Miles Bader <miles@gnu.org>
parents:
61260
diff
changeset
|
209 (when (>= low 65536) |
60847
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
210 (setq high (1+ high) |
61424
ad05d91d3598
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-243
Miles Bader <miles@gnu.org>
parents:
61260
diff
changeset
|
211 low (- low 65536))) |
60847
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
212 (encode-time-value high low micro type))) |
43049
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
213 |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
214 ;;;###autoload |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
215 (defun date-to-day (date) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
216 "Return the number of days between year 1 and DATE. |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
217 DATE should be a date-time string." |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
218 (time-to-days (date-to-time date))) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
219 |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
220 ;;;###autoload |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
221 (defun days-between (date1 date2) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
222 "Return the number of days between DATE1 and DATE2. |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
223 DATE1 and DATE2 should be date-time strings." |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
224 (- (date-to-day date1) (date-to-day date2))) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
225 |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
226 ;;;###autoload |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
227 (defun date-leap-year-p (year) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
228 "Return t if YEAR is a leap year." |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
229 (or (and (zerop (% year 4)) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
230 (not (zerop (% year 100)))) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
231 (zerop (% year 400)))) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
232 |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
233 ;;;###autoload |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
234 (defun time-to-day-in-year (time) |
55002
8e406d7e53be
(time-to-day-in-year): Fix docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
52401
diff
changeset
|
235 "Return the day number within the year corresponding to TIME." |
43049
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
236 (let* ((tim (decode-time time)) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
237 (month (nth 4 tim)) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
238 (day (nth 3 tim)) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
239 (year (nth 5 tim)) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
240 (day-of-year (+ day (* 31 (1- month))))) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
241 (when (> month 2) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
242 (setq day-of-year (- day-of-year (/ (+ 23 (* 4 month)) 10))) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
243 (when (date-leap-year-p year) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
244 (setq day-of-year (1+ day-of-year)))) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
245 day-of-year)) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
246 |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
247 ;;;###autoload |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
248 (defun time-to-days (time) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
249 "The number of days between the Gregorian date 0001-12-31bce and TIME. |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
250 TIME should be a time value. |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
251 The Gregorian date Sunday, December 31, 1bce is imaginary." |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
252 (let* ((tim (decode-time time)) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
253 (month (nth 4 tim)) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
254 (day (nth 3 tim)) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
255 (year (nth 5 tim))) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
256 (+ (time-to-day-in-year time) ; Days this year |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
257 (* 365 (1- year)) ; + Days in prior years |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
258 (/ (1- year) 4) ; + Julian leap years |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
259 (- (/ (1- year) 100)) ; - century years |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
260 (/ (1- year) 400)))) ; + Gregorian leap years |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
261 |
104890
2e22af528b76
* calendar/time-date.el (autoload):
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
104798
diff
changeset
|
262 (eval-and-compile |
2e22af528b76
* calendar/time-date.el (autoload):
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
104798
diff
changeset
|
263 (if (and (fboundp 'float-time) |
2e22af528b76
* calendar/time-date.el (autoload):
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
104798
diff
changeset
|
264 (subrp (symbol-function 'float-time))) |
2e22af528b76
* calendar/time-date.el (autoload):
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
104798
diff
changeset
|
265 (defun time-to-number-of-days (time) |
2e22af528b76
* calendar/time-date.el (autoload):
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
104798
diff
changeset
|
266 "Return the number of days represented by TIME. |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
56797
diff
changeset
|
267 The number of days will be returned as a floating point number." |
104890
2e22af528b76
* calendar/time-date.el (autoload):
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
104798
diff
changeset
|
268 (/ (float-time time) (* 60 60 24))) |
2e22af528b76
* calendar/time-date.el (autoload):
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
104798
diff
changeset
|
269 (defun time-to-number-of-days (time) |
2e22af528b76
* calendar/time-date.el (autoload):
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
104798
diff
changeset
|
270 "Return the number of days represented by TIME. |
2e22af528b76
* calendar/time-date.el (autoload):
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
104798
diff
changeset
|
271 The number of days will be returned as a floating point number." |
2e22af528b76
* calendar/time-date.el (autoload):
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
104798
diff
changeset
|
272 (/ (with-no-warnings (time-to-seconds time)) (* 60 60 24))))) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
56797
diff
changeset
|
273 |
43049
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
274 ;;;###autoload |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
275 (defun safe-date-to-time (date) |
92632
870c7b456283
(date-to-time, time-subtract, time-add, safe-date-to-time): Doc fixes.
Glenn Morris <rgm@gnu.org>
parents:
91863
diff
changeset
|
276 "Parse a string DATE that represents a date-time and return a time value. |
43049
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
277 If DATE is malformed, return a time value of zeros." |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
278 (condition-case () |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
279 (date-to-time date) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
280 (error '(0 0)))) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
281 |
91737 | 282 |
283 ;;;###autoload | |
91863
5f14edcf524f
(format-seconds): Remove `nonzero' argument in favor of `%z' specifier.
Glenn Morris <rgm@gnu.org>
parents:
91836
diff
changeset
|
284 (defun format-seconds (string seconds) |
91831 | 285 "Use format control STRING to format the number SECONDS. |
286 The valid format specifiers are: | |
287 %y is the number of (365-day) years. | |
288 %d is the number of days. | |
289 %h is the number of hours. | |
290 %m is the number of minutes. | |
291 %s is the number of seconds. | |
91863
5f14edcf524f
(format-seconds): Remove `nonzero' argument in favor of `%z' specifier.
Glenn Morris <rgm@gnu.org>
parents:
91836
diff
changeset
|
292 %z is a non-printing control flag (see below). |
91831 | 293 %% is a literal \"%\". |
294 | |
295 Upper-case specifiers are followed by the unit-name (e.g. \"years\"). | |
296 Lower-case specifiers return only the unit. | |
297 | |
298 \"%\" may be followed by a number specifying a width, with an | |
299 optional leading \".\" for zero-padding. For example, \"%.3Y\" will | |
300 return something of the form \"001 year\". | |
301 | |
91863
5f14edcf524f
(format-seconds): Remove `nonzero' argument in favor of `%z' specifier.
Glenn Morris <rgm@gnu.org>
parents:
91836
diff
changeset
|
302 The \"%z\" specifier does not print anything. When it is used, specifiers |
5f14edcf524f
(format-seconds): Remove `nonzero' argument in favor of `%z' specifier.
Glenn Morris <rgm@gnu.org>
parents:
91836
diff
changeset
|
303 must be given in order of decreasing size. To the left of \"%z\", nothing |
5f14edcf524f
(format-seconds): Remove `nonzero' argument in favor of `%z' specifier.
Glenn Morris <rgm@gnu.org>
parents:
91836
diff
changeset
|
304 is output until the first non-zero unit is encountered. |
91831 | 305 |
91863
5f14edcf524f
(format-seconds): Remove `nonzero' argument in favor of `%z' specifier.
Glenn Morris <rgm@gnu.org>
parents:
91836
diff
changeset
|
306 This function does not work for SECONDS greater than `most-positive-fixnum'." |
91831 | 307 (let ((start 0) |
308 (units '(("y" "year" 31536000) | |
309 ("d" "day" 86400) | |
310 ("h" "hour" 3600) | |
311 ("m" "minute" 60) | |
91863
5f14edcf524f
(format-seconds): Remove `nonzero' argument in favor of `%z' specifier.
Glenn Morris <rgm@gnu.org>
parents:
91836
diff
changeset
|
312 ("s" "second" 1) |
5f14edcf524f
(format-seconds): Remove `nonzero' argument in favor of `%z' specifier.
Glenn Morris <rgm@gnu.org>
parents:
91836
diff
changeset
|
313 ("z"))) |
91831 | 314 (case-fold-search t) |
91863
5f14edcf524f
(format-seconds): Remove `nonzero' argument in favor of `%z' specifier.
Glenn Morris <rgm@gnu.org>
parents:
91836
diff
changeset
|
315 spec match usedunits zeroflag larger prev name unit num zeropos) |
91831 | 316 (while (string-match "%\\.?[0-9]*\\(.\\)" string start) |
317 (setq start (match-end 0) | |
318 spec (match-string 1 string)) | |
319 (unless (string-equal spec "%") | |
110330
b68d97301050
time-date.el (format-seconds): Comment fix.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110102
diff
changeset
|
320 ;; `assoc-string' is not available in XEmacs or Emacs 21. So when |
b68d97301050
time-date.el (format-seconds): Comment fix.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110102
diff
changeset
|
321 ;; compiling Gnus (`time-date.el' is part of Gnus) with XEmacs or |
b68d97301050
time-date.el (format-seconds): Comment fix.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110102
diff
changeset
|
322 ;; Emacs 21, we get a warning here. But `format-seconds' is not |
b68d97301050
time-date.el (format-seconds): Comment fix.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110102
diff
changeset
|
323 ;; used anywhere in Gnus so it's not a real problem. --rsteib |
91831 | 324 (or (setq match (assoc-string spec units t)) |
325 (error "Bad format specifier: `%s'" spec)) | |
91863
5f14edcf524f
(format-seconds): Remove `nonzero' argument in favor of `%z' specifier.
Glenn Morris <rgm@gnu.org>
parents:
91836
diff
changeset
|
326 (if (assoc-string spec usedunits t) |
91831 | 327 (error "Multiple instances of specifier: `%s'" spec)) |
91863
5f14edcf524f
(format-seconds): Remove `nonzero' argument in favor of `%z' specifier.
Glenn Morris <rgm@gnu.org>
parents:
91836
diff
changeset
|
328 (if (string-equal (car match) "z") |
5f14edcf524f
(format-seconds): Remove `nonzero' argument in favor of `%z' specifier.
Glenn Morris <rgm@gnu.org>
parents:
91836
diff
changeset
|
329 (setq zeroflag t) |
5f14edcf524f
(format-seconds): Remove `nonzero' argument in favor of `%z' specifier.
Glenn Morris <rgm@gnu.org>
parents:
91836
diff
changeset
|
330 (unless larger |
5f14edcf524f
(format-seconds): Remove `nonzero' argument in favor of `%z' specifier.
Glenn Morris <rgm@gnu.org>
parents:
91836
diff
changeset
|
331 (setq unit (nth 2 match) |
5f14edcf524f
(format-seconds): Remove `nonzero' argument in favor of `%z' specifier.
Glenn Morris <rgm@gnu.org>
parents:
91836
diff
changeset
|
332 larger (and prev (> unit prev)) |
5f14edcf524f
(format-seconds): Remove `nonzero' argument in favor of `%z' specifier.
Glenn Morris <rgm@gnu.org>
parents:
91836
diff
changeset
|
333 prev unit))) |
5f14edcf524f
(format-seconds): Remove `nonzero' argument in favor of `%z' specifier.
Glenn Morris <rgm@gnu.org>
parents:
91836
diff
changeset
|
334 (push match usedunits))) |
5f14edcf524f
(format-seconds): Remove `nonzero' argument in favor of `%z' specifier.
Glenn Morris <rgm@gnu.org>
parents:
91836
diff
changeset
|
335 (and zeroflag larger |
5f14edcf524f
(format-seconds): Remove `nonzero' argument in favor of `%z' specifier.
Glenn Morris <rgm@gnu.org>
parents:
91836
diff
changeset
|
336 (error "Units are not in decreasing order of size")) |
5f14edcf524f
(format-seconds): Remove `nonzero' argument in favor of `%z' specifier.
Glenn Morris <rgm@gnu.org>
parents:
91836
diff
changeset
|
337 (dolist (u units) |
5f14edcf524f
(format-seconds): Remove `nonzero' argument in favor of `%z' specifier.
Glenn Morris <rgm@gnu.org>
parents:
91836
diff
changeset
|
338 (setq spec (car u) |
5f14edcf524f
(format-seconds): Remove `nonzero' argument in favor of `%z' specifier.
Glenn Morris <rgm@gnu.org>
parents:
91836
diff
changeset
|
339 name (cadr u) |
5f14edcf524f
(format-seconds): Remove `nonzero' argument in favor of `%z' specifier.
Glenn Morris <rgm@gnu.org>
parents:
91836
diff
changeset
|
340 unit (nth 2 u)) |
91831 | 341 (when (string-match (format "%%\\(\\.?[0-9]+\\)?\\(%s\\)" spec) string) |
91863
5f14edcf524f
(format-seconds): Remove `nonzero' argument in favor of `%z' specifier.
Glenn Morris <rgm@gnu.org>
parents:
91836
diff
changeset
|
342 (if (string-equal spec "z") ; must be last in units |
5f14edcf524f
(format-seconds): Remove `nonzero' argument in favor of `%z' specifier.
Glenn Morris <rgm@gnu.org>
parents:
91836
diff
changeset
|
343 (setq string |
5f14edcf524f
(format-seconds): Remove `nonzero' argument in favor of `%z' specifier.
Glenn Morris <rgm@gnu.org>
parents:
91836
diff
changeset
|
344 (replace-regexp-in-string |
5f14edcf524f
(format-seconds): Remove `nonzero' argument in favor of `%z' specifier.
Glenn Morris <rgm@gnu.org>
parents:
91836
diff
changeset
|
345 "%z" "" |
5f14edcf524f
(format-seconds): Remove `nonzero' argument in favor of `%z' specifier.
Glenn Morris <rgm@gnu.org>
parents:
91836
diff
changeset
|
346 (substring string (min (or zeropos (match-end 0)) |
5f14edcf524f
(format-seconds): Remove `nonzero' argument in favor of `%z' specifier.
Glenn Morris <rgm@gnu.org>
parents:
91836
diff
changeset
|
347 (match-beginning 0))))) |
5f14edcf524f
(format-seconds): Remove `nonzero' argument in favor of `%z' specifier.
Glenn Morris <rgm@gnu.org>
parents:
91836
diff
changeset
|
348 ;; Cf article-make-date-line in gnus-art. |
5f14edcf524f
(format-seconds): Remove `nonzero' argument in favor of `%z' specifier.
Glenn Morris <rgm@gnu.org>
parents:
91836
diff
changeset
|
349 (setq num (floor seconds unit) |
5f14edcf524f
(format-seconds): Remove `nonzero' argument in favor of `%z' specifier.
Glenn Morris <rgm@gnu.org>
parents:
91836
diff
changeset
|
350 seconds (- seconds (* num unit))) |
5f14edcf524f
(format-seconds): Remove `nonzero' argument in favor of `%z' specifier.
Glenn Morris <rgm@gnu.org>
parents:
91836
diff
changeset
|
351 ;; Start position of the first non-zero unit. |
5f14edcf524f
(format-seconds): Remove `nonzero' argument in favor of `%z' specifier.
Glenn Morris <rgm@gnu.org>
parents:
91836
diff
changeset
|
352 (or zeropos |
5f14edcf524f
(format-seconds): Remove `nonzero' argument in favor of `%z' specifier.
Glenn Morris <rgm@gnu.org>
parents:
91836
diff
changeset
|
353 (setq zeropos (unless (zerop num) (match-beginning 0)))) |
5f14edcf524f
(format-seconds): Remove `nonzero' argument in favor of `%z' specifier.
Glenn Morris <rgm@gnu.org>
parents:
91836
diff
changeset
|
354 (setq string |
5f14edcf524f
(format-seconds): Remove `nonzero' argument in favor of `%z' specifier.
Glenn Morris <rgm@gnu.org>
parents:
91836
diff
changeset
|
355 (replace-match |
5f14edcf524f
(format-seconds): Remove `nonzero' argument in favor of `%z' specifier.
Glenn Morris <rgm@gnu.org>
parents:
91836
diff
changeset
|
356 (format (concat "%" (match-string 1 string) "d%s") num |
5f14edcf524f
(format-seconds): Remove `nonzero' argument in favor of `%z' specifier.
Glenn Morris <rgm@gnu.org>
parents:
91836
diff
changeset
|
357 (if (string-equal (match-string 2 string) spec) |
5f14edcf524f
(format-seconds): Remove `nonzero' argument in favor of `%z' specifier.
Glenn Morris <rgm@gnu.org>
parents:
91836
diff
changeset
|
358 "" ; lower-case, no unit-name |
5f14edcf524f
(format-seconds): Remove `nonzero' argument in favor of `%z' specifier.
Glenn Morris <rgm@gnu.org>
parents:
91836
diff
changeset
|
359 (format " %s%s" name |
5f14edcf524f
(format-seconds): Remove `nonzero' argument in favor of `%z' specifier.
Glenn Morris <rgm@gnu.org>
parents:
91836
diff
changeset
|
360 (if (= num 1) "" "s")))) |
5f14edcf524f
(format-seconds): Remove `nonzero' argument in favor of `%z' specifier.
Glenn Morris <rgm@gnu.org>
parents:
91836
diff
changeset
|
361 t t string)))))) |
91831 | 362 (replace-regexp-in-string "%%" "%" string)) |
363 | |
91737 | 364 |
43049
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
365 (provide 'time-date) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
366 |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
367 ;;; time-date.el ends here |