Mercurial > emacs
annotate lisp/calendar/time-date.el @ 61311:e768c2d3772a
*** empty log message ***
author | Carsten Dominik <dominik@science.uva.nl> |
---|---|
date | Tue, 05 Apr 2005 10:07:51 +0000 |
parents | ae865a366a88 |
children | ad05d91d3598 02f1dbc4a199 |
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 |
ae865a366a88
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-230
Miles Bader <miles@gnu.org>
parents:
60847
diff
changeset
|
2 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2005 Free Software Foundation, Inc. |
43049
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
3 |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
4 ;; 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
|
5 ;; 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
|
6 ;; Keywords: mail news util |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
7 |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
8 ;; 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
|
9 |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
10 ;; GNU Emacs is free software; you can redistribute it and/or modify |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
11 ;; it under the terms of the GNU General Public License as published by |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
12 ;; the Free Software Foundation; either version 2, or (at your option) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
13 ;; any later version. |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
14 |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
15 ;; 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
|
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
18 ;; 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
|
19 |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
20 ;; You should have received a copy of the GNU General Public License |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
23 ;; Boston, MA 02111-1307, USA. |
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 |
60847
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
42 (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
|
43 "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
|
44 |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
45 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
|
46 |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
47 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
|
48 \(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
|
49 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
|
50 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
|
51 |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
52 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
|
53 Type 0 is the cons cell (HIGH . LOW), type 1 is the list (HIGH |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
54 LOW), and type 3 is the list (HIGH LOW MICRO)." |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
55 (declare (indent 1) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
56 (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
|
57 body))) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
58 (if varlist |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
59 (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
|
60 (high (pop elt)) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
61 (low (pop elt)) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
62 (micro (pop elt)) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
63 (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
|
64 (pop elt))) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
65 (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
|
66 (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
|
67 `(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
|
68 (,high (pop ,gensym)) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
69 ,low ,micro) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
70 (when type `(,type))) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
71 (if (consp ,gensym) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
72 (progn |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
73 (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
|
74 (if ,gensym |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
75 ,(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
|
76 (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
|
77 ,(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
|
78 (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
|
79 ,(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
|
80 (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
|
81 (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
|
82 `(progn ,@body))) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
83 |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
84 (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
|
85 "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
|
86 Type 0 is the cons cell (HIGH . LOW), type 1 is the list (HIGH LOW), |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
87 and type 3 is the list (HIGH LOW MICRO)." |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
88 (cond |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
89 ((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
|
90 ((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
|
91 ((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
|
92 |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
93 (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
|
94 |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
95 ;;;###autoload |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
96 (defun date-to-time (date) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
97 "Parse a string that represents a date-time and return a time value." |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
98 (condition-case () |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
99 (apply 'encode-time |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
100 (parse-time-string |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
101 ;; `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
|
102 ;; 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
|
103 ;; 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
|
104 ;; 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
|
105 ;; 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
|
106 ;; often for me. -- fx |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
107 (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
|
108 (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
|
109 |
56797
2383026ff0d9
(time-to-seconds): Add autoload cookies.
Masatake YAMATO <jet@gyve.org>
parents:
55002
diff
changeset
|
110 ;;;###autoload |
43049
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
111 (defun time-to-seconds (time) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
112 "Convert time value TIME to a floating point number. |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
113 You can use `float-time' instead." |
60847
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
114 (with-decoded-time-value ((high low micro time)) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
115 (+ (* 1.0 high #x10000) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
116 low |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
117 (/ micro 1000000.0)))) |
43049
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
118 |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
119 ;;;###autoload |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
120 (defun seconds-to-time (seconds) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
121 "Convert SECONDS (a floating point number) to 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
|
122 (list (floor seconds #x10000) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
123 (floor (mod seconds #x10000)) |
43049
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
124 (floor (* (- seconds (ffloor seconds)) 1000000)))) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
125 |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
126 ;;;###autoload |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
127 (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
|
128 "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
|
129 (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
|
130 (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
|
131 (or (< high1 high2) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
132 (and (= high1 high2) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
133 (or (< low1 low2) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
134 (and (= low1 low2) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
135 (< micro1 micro2))))))) |
43049
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
136 |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
137 ;;;###autoload |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
138 (defun days-to-time (days) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
139 "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
|
140 (let* ((seconds (* 1.0 days 60 60 24)) |
60847
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
141 (high (condition-case nil (floor (/ seconds #x10000)) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
142 (range-error most-positive-fixnum)))) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
143 (list high (condition-case nil (floor (- seconds (* 1.0 high #x10000))) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
144 (range-error #xffff))))) |
43049
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
145 |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
146 ;;;###autoload |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
147 (defun time-since (time) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
148 "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
|
149 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
|
150 (when (stringp time) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
151 ;; 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
|
152 (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
|
153 (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
|
154 |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
155 ;;;###autoload |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
156 (defalias 'subtract-time 'time-subtract) |
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 time-subtract (t1 t2) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
160 "Subtract two time values. |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
161 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
|
162 (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
|
163 (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
|
164 (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
|
165 low (- low low2) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
166 micro (- micro micro2) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
167 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
|
168 (when (< micro 0) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
169 (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
|
170 micro (+ micro 1000000))) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
171 (when (< low 0) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
172 (setq high (1- high) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
173 low (+ low #x10000))) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
174 (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
|
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 (defun time-add (t1 t2) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
178 "Add two time values. 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
|
179 (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
|
180 (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
|
181 (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
|
182 low (+ low low2) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
183 micro (+ micro micro2) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
184 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
|
185 (when (>= micro 1000000) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
186 (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
|
187 micro (- micro 1000000))) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
188 (when (>= low #x10000) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
189 (setq high (1+ high) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
190 low (- low #x10000))) |
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
191 (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
|
192 |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
193 ;;;###autoload |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
194 (defun date-to-day (date) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
195 "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
|
196 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
|
197 (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
|
198 |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
199 ;;;###autoload |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
200 (defun days-between (date1 date2) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
201 "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
|
202 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
|
203 (- (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
|
204 |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
205 ;;;###autoload |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
206 (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
|
207 "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
|
208 (or (and (zerop (% year 4)) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
209 (not (zerop (% year 100)))) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
210 (zerop (% year 400)))) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
211 |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
212 ;;;###autoload |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
213 (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
|
214 "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
|
215 (let* ((tim (decode-time time)) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
216 (month (nth 4 tim)) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
217 (day (nth 3 tim)) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
218 (year (nth 5 tim)) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
219 (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
|
220 (when (> month 2) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
221 (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
|
222 (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
|
223 (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
|
224 day-of-year)) |
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 time-to-days (time) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
228 "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
|
229 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
|
230 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
|
231 (let* ((tim (decode-time time)) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
232 (month (nth 4 tim)) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
233 (day (nth 3 tim)) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
234 (year (nth 5 tim))) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
235 (+ (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
|
236 (* 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
|
237 (/ (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
|
238 (- (/ (1- year) 100)) ; - century years |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
239 (/ (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
|
240 |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
56797
diff
changeset
|
241 (defun time-to-number-of-days (time) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
56797
diff
changeset
|
242 "Return the number of days represented by TIME. |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
56797
diff
changeset
|
243 The number of days will be returned as a floating point number." |
60847
608b5e008a8b
Add comment on time value formats. Don't require parse-time.
Lute Kamstra <lute@gnu.org>
parents:
56927
diff
changeset
|
244 (/ (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
|
245 |
43049
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
246 ;;;###autoload |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
247 (defun safe-date-to-time (date) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
248 "Parse a string that represents a date-time and return a time value. |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
249 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
|
250 (condition-case () |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
251 (date-to-time date) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
252 (error '(0 0)))) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
253 |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
254 (provide 'time-date) |
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
255 |
52401 | 256 ;;; arch-tag: addcf07b-b20a-465b-af72-550b8ac5190f |
43049
d94124a8eddf
Moved time-date.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
257 ;;; time-date.el ends here |