Mercurial > hg > xemacs-beta
comparison lisp/utils/timezone.el @ 70:131b0175ea99 r20-0b30
Import from CVS: tag r20-0b30
author | cvs |
---|---|
date | Mon, 13 Aug 2007 09:02:59 +0200 |
parents | 0293115a14e9 |
children | 6a378aca36af |
comparison
equal
deleted
inserted
replaced
69:804d1389bcd6 | 70:131b0175ea99 |
---|---|
127 | 127 |
128 (defun timezone-make-time-string (hour minute second) | 128 (defun timezone-make-time-string (hour minute second) |
129 "Make time string from HOUR, MINUTE, and SECOND." | 129 "Make time string from HOUR, MINUTE, and SECOND." |
130 (format "%02d:%02d:%02d" hour minute second)) | 130 (format "%02d:%02d:%02d" hour minute second)) |
131 | 131 |
132 ;;;###autoload | |
133 (define-error 'invalid-date "Invalid date string") | |
134 | |
135 (defun timezone-parse-date (date) | 132 (defun timezone-parse-date (date) |
136 "Parse DATE and return a vector [YEAR MONTH DAY TIME TIMEZONE]. | 133 "Parse DATE and return a vector [YEAR MONTH DAY TIME TIMEZONE]. |
137 19 is prepended to year if necessary. Timezone may be nil if nothing. | 134 19 is prepended to year if necessary. Timezone may be nil if nothing. |
138 Understands the following styles: | 135 Understands the following styles: |
139 (1) 14 Apr 89 03:20[:12] [GMT] | 136 (1) 14 Apr 89 03:20[:12] [GMT] |
141 (3) Mon Jan 16 16:12[:37] [GMT] 1989 | 138 (3) Mon Jan 16 16:12[:37] [GMT] 1989 |
142 (4) 6 May 1992 1641-JST (Wednesday) | 139 (4) 6 May 1992 1641-JST (Wednesday) |
143 (5) 22-AUG-1993 10:59:12.82 | 140 (5) 22-AUG-1993 10:59:12.82 |
144 (6) Thu, 11 Apr 16:17:12 91 [MET] | 141 (6) Thu, 11 Apr 16:17:12 91 [MET] |
145 (7) Mon, 6 Jul 16:47:20 T 1992 [MET]" | 142 (7) Mon, 6 Jul 16:47:20 T 1992 [MET]" |
146 (condition-case nil | |
147 (progn | |
148 ;; Get rid of any text properties. | 143 ;; Get rid of any text properties. |
149 (and (stringp date) | 144 (and (stringp date) |
150 (or (text-properties-at 0 date) | 145 (or (text-properties-at 0 date) |
151 (next-property-change 0 date)) | 146 (next-property-change 0 date)) |
152 (setq date (copy-sequence date)) | 147 (setq date (copy-sequence date)) |
194 (progn | 189 (progn |
195 (setq year | 190 (setq year |
196 (substring date (match-beginning year) (match-end year))) | 191 (substring date (match-beginning year) (match-end year))) |
197 ;; It is now Dec 1992. 8 years before the end of the World. | 192 ;; It is now Dec 1992. 8 years before the end of the World. |
198 (if (< (length year) 4) | 193 (if (< (length year) 4) |
199 ;; 2 digit years are bogus, so guess the century | 194 (setq year (concat "19" (substring year -2 nil)))) |
200 (let ((yr (string-to-int year))) | |
201 (when (>= yr 100) | |
202 ;; What does a three digit year mean? | |
203 (setq yr (- yr 100))) | |
204 (setq year (format "%d%02d" | |
205 (if (< yr 70) | |
206 20 | |
207 19) | |
208 yr)))) | |
209 (let ((string (substring date | 195 (let ((string (substring date |
210 (match-beginning month) | 196 (match-beginning month) |
211 (+ (match-beginning month) 3)))) | 197 (+ (match-beginning month) 3)))) |
212 (setq month | 198 (setq month |
213 (int-to-string | 199 (int-to-string |
222 (substring date (match-beginning zone) (match-end zone)))) | 208 (substring date (match-beginning zone) (match-end zone)))) |
223 ;; Return a vector. | 209 ;; Return a vector. |
224 (if year | 210 (if year |
225 (vector year month day time zone) | 211 (vector year month day time zone) |
226 (vector "0" "0" "0" "0" nil)) | 212 (vector "0" "0" "0" "0" nil)) |
227 ) | 213 )) |
228 ) | |
229 (t (signal 'invalid-date (list date)))) | |
230 ) | |
231 | 214 |
232 (defun timezone-parse-time (time) | 215 (defun timezone-parse-time (time) |
233 "Parse TIME (HH:MM:SS) and return a vector [hour minute second]. | 216 "Parse TIME (HH:MM:SS) and return a vector [hour minute second]. |
234 Recognize HH:MM:SS, HH:MM, HHMMSS, HHMM." | 217 Recognize HH:MM:SS, HH:MM, HHMMSS, HHMM." |
235 (let ((time (or time "")) | 218 (let ((time (or time "")) |