aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman2002-01-27 23:30:29 +0000
committerRichard M. Stallman2002-01-27 23:30:29 +0000
commit74fcda73dd8743f66256aa5fdaff6260dc356c54 (patch)
tree1e8f6900962f749405eccff1f833e6db8a32536d
parent94a877eff75c17809935dc19896ad900ec4ac430 (diff)
downloademacs-74fcda73dd8743f66256aa5fdaff6260dc356c54.tar.gz
emacs-74fcda73dd8743f66256aa5fdaff6260dc356c54.zip
Add autoload cookies. Many doc fixes.
(time-add): New function. (time-subtract): Renamed from subtract-time. (subtract-time): New alias for time-subtract.
-rw-r--r--lisp/gnus/ChangeLog7
-rw-r--r--lisp/gnus/time-date.el71
2 files changed, 66 insertions, 12 deletions
diff --git a/lisp/gnus/ChangeLog b/lisp/gnus/ChangeLog
index fb15fcb2a27..20fc14ba42e 100644
--- a/lisp/gnus/ChangeLog
+++ b/lisp/gnus/ChangeLog
@@ -1,3 +1,10 @@
12002-01-27 Richard M. Stallman <rms@gnu.org>
2
3 * time-date.el: Add autoload cookies. Many doc fixes.
4 (time-add): New function.
5 (time-subtract): Renamed from subtract-time.
6 (subtract-time): New alias for time-subtract.
7
12002-01-08 ShengHuo ZHU <zsh@cs.rochester.edu> 82002-01-08 ShengHuo ZHU <zsh@cs.rochester.edu>
2 9
3 * gnus-start.el (gnus-read-init-file): Cleaned up. 10 * gnus-start.el (gnus-read-init-file): Cleaned up.
diff --git a/lisp/gnus/time-date.el b/lisp/gnus/time-date.el
index 823954b54aa..c3a738a9932 100644
--- a/lisp/gnus/time-date.el
+++ b/lisp/gnus/time-date.el
@@ -32,7 +32,7 @@
32 32
33;;;###autoload 33;;;###autoload
34(defun date-to-time (date) 34(defun date-to-time (date)
35 "Convert DATE into time." 35 "Parse a string that represents a date-time and return a time value."
36 (condition-case () 36 (condition-case ()
37 (apply 'encode-time 37 (apply 'encode-time
38 (parse-time-string 38 (parse-time-string
@@ -46,25 +46,29 @@
46 (error (error "Invalid date: %s" date)))) 46 (error (error "Invalid date: %s" date))))
47 47
48(defun time-to-seconds (time) 48(defun time-to-seconds (time)
49 "Convert TIME to a floating point number." 49 "Convert time value TIME to a floating point number.
50You can use `float-time' instead."
50 (+ (* (car time) 65536.0) 51 (+ (* (car time) 65536.0)
51 (cadr time) 52 (cadr time)
52 (/ (or (nth 2 time) 0) 1000000.0))) 53 (/ (or (nth 2 time) 0) 1000000.0)))
53 54
55;;;###autoload
54(defun seconds-to-time (seconds) 56(defun seconds-to-time (seconds)
55 "Convert SECONDS (a floating point number) to an Emacs time structure." 57 "Convert SECONDS (a floating point number) to a time value."
56 (list (floor seconds 65536) 58 (list (floor seconds 65536)
57 (floor (mod seconds 65536)) 59 (floor (mod seconds 65536))
58 (floor (* (- seconds (ffloor seconds)) 1000000)))) 60 (floor (* (- seconds (ffloor seconds)) 1000000))))
59 61
62;;;###autoload
60(defun time-less-p (t1 t2) 63(defun time-less-p (t1 t2)
61 "Say whether time T1 is less than time T2." 64 "Say whether time value T1 is less than time value T2."
62 (or (< (car t1) (car t2)) 65 (or (< (car t1) (car t2))
63 (and (= (car t1) (car t2)) 66 (and (= (car t1) (car t2))
64 (< (nth 1 t1) (nth 1 t2))))) 67 (< (nth 1 t1) (nth 1 t2)))))
65 68
69;;;###autoload
66(defun days-to-time (days) 70(defun days-to-time (days)
67 "Convert DAYS into time." 71 "Convert DAYS into a time value."
68 (let* ((seconds (* 1.0 days 60 60 24)) 72 (let* ((seconds (* 1.0 days 60 60 24))
69 (rest (expt 2 16)) 73 (rest (expt 2 16))
70 (ms (condition-case nil (floor (/ seconds rest)) 74 (ms (condition-case nil (floor (/ seconds rest))
@@ -72,8 +76,10 @@
72 (list ms (condition-case nil (round (- seconds (* ms rest))) 76 (list ms (condition-case nil (round (- seconds (* ms rest)))
73 (range-error (expt 2 16)))))) 77 (range-error (expt 2 16))))))
74 78
79;;;###autoload
75(defun time-since (time) 80(defun time-since (time)
76 "Return the time since TIME, which is either an internal time or a date." 81 "Return the time elapsed since TIME.
82TIME should be either a time value or a date-time string."
77 (when (stringp time) 83 (when (stringp time)
78 ;; Convert date strings to internal time. 84 ;; Convert date strings to internal time.
79 (setq time (date-to-time time))) 85 (setq time (date-to-time time)))
@@ -83,26 +89,65 @@
83 (list (- (+ (car current) (if rest -1 0)) (car time)) 89 (list (- (+ (car current) (if rest -1 0)) (car time))
84 (- (+ (or rest 0) (nth 1 current)) (nth 1 time))))) 90 (- (+ (or rest 0) (nth 1 current)) (nth 1 time)))))
85 91
86(defun subtract-time (t1 t2) 92;;;###autoload
87 "Subtract two internal times." 93(defalias 'subtract-time 'time-subtract)
94
95;;;###autoload
96(defun time-subtract (t1 t2)
97 "Subtract two time values.
98Return the difference in the format of a time value."
88 (let ((borrow (< (cadr t1) (cadr t2)))) 99 (let ((borrow (< (cadr t1) (cadr t2))))
89 (list (- (car t1) (car t2) (if borrow 1 0)) 100 (list (- (car t1) (car t2) (if borrow 1 0))
90 (- (+ (if borrow 65536 0) (cadr t1)) (cadr t2))))) 101 (- (+ (if borrow 65536 0) (cadr t1)) (cadr t2)))))
91 102
103;;;###autoload
104(defun time-add (t1 t2)
105 "Add two time values. One should represent a time difference."
106 (let ((high (car t1))
107 (low (if (consp (cdr t1)) (nth 1 t1) (cdr t1)))
108 (micro (if (numberp (car-safe (cdr-safe (cdr t1))))
109 (nth 2 t1)
110 0))
111 (high2 (car t2))
112 (low2 (if (consp (cdr t2)) (nth 1 t2) (cdr t2)))
113 (micro2 (if (numberp (car-safe (cdr-safe (cdr t2))))
114 (nth 2 t2)
115 0)))
116 ;; Add
117 (setq micro (+ micro micro2))
118 (setq low (+ low low2))
119 (setq high (+ high high2))
120
121 ;; Normalize
122 ;; `/' rounds towards zero while `mod' returns a positive number,
123 ;; so we can't rely on (= a (+ (* 100 (/ a 100)) (mod a 100))).
124 (setq low (+ low (/ micro 1000000) (if (< micro 0) -1 0)))
125 (setq micro (mod micro 1000000))
126 (setq high (+ high (/ low 65536) (if (< low 0) -1 0)))
127 (setq low (logand low 65535))
128
129 (list high low micro)))
130
131;;;###autoload
92(defun date-to-day (date) 132(defun date-to-day (date)
93 "Return the number of days between year 1 and DATE." 133 "Return the number of days between year 1 and DATE.
134DATE should be a date-time string."
94 (time-to-days (date-to-time date))) 135 (time-to-days (date-to-time date)))
95 136
137;;;###autoload
96(defun days-between (date1 date2) 138(defun days-between (date1 date2)
97 "Return the number of days between DATE1 and DATE2." 139 "Return the number of days between DATE1 and DATE2.
140DATE1 and DATE2 should be date-time strings."
98 (- (date-to-day date1) (date-to-day date2))) 141 (- (date-to-day date1) (date-to-day date2)))
99 142
143;;;###autoload
100(defun date-leap-year-p (year) 144(defun date-leap-year-p (year)
101 "Return t if YEAR is a leap year." 145 "Return t if YEAR is a leap year."
102 (or (and (zerop (% year 4)) 146 (or (and (zerop (% year 4))
103 (not (zerop (% year 100)))) 147 (not (zerop (% year 100))))
104 (zerop (% year 400)))) 148 (zerop (% year 400))))
105 149
150;;;###autoload
106(defun time-to-day-in-year (time) 151(defun time-to-day-in-year (time)
107 "Return the day number within the year of the date month/day/year." 152 "Return the day number within the year of the date month/day/year."
108 (let* ((tim (decode-time time)) 153 (let* ((tim (decode-time time))
@@ -116,8 +161,10 @@
116 (setq day-of-year (1+ day-of-year)))) 161 (setq day-of-year (1+ day-of-year))))
117 day-of-year)) 162 day-of-year))
118 163
164;;;###autoload
119(defun time-to-days (time) 165(defun time-to-days (time)
120 "The number of days between the Gregorian date 0001-12-31bce and TIME. 166 "The number of days between the Gregorian date 0001-12-31bce and TIME.
167TIME should be a time value.
121The Gregorian date Sunday, December 31, 1bce is imaginary." 168The Gregorian date Sunday, December 31, 1bce is imaginary."
122 (let* ((tim (decode-time time)) 169 (let* ((tim (decode-time time))
123 (month (nth 4 tim)) 170 (month (nth 4 tim))
@@ -131,8 +178,8 @@ The Gregorian date Sunday, December 31, 1bce is imaginary."
131 178
132;;;###autoload 179;;;###autoload
133(defun safe-date-to-time (date) 180(defun safe-date-to-time (date)
134 "Parse DATE and return a time structure. 181 "Parse a string that represents a date-time and return a time value.
135If DATE is malformed, a zero time will be returned." 182If DATE is malformed, return a time value of zeros."
136 (condition-case () 183 (condition-case ()
137 (date-to-time date) 184 (date-to-time date)
138 (error '(0 0)))) 185 (error '(0 0))))