Mercurial > emacs
comparison lisp/timezone.el @ 25383:57e815ace9e2
Mode provide to end.
(timezone-parse-date): Simplify somewhat. Assume 2-digit years <70 are
2000+.
(timezone-parse-time): Simplify somewhat.
author | Dave Love <fx@gnu.org> |
---|---|
date | Tue, 24 Aug 1999 16:43:44 +0000 |
parents | 4708ef6e279e |
children | fbfe59033eaf |
comparison
equal
deleted
inserted
replaced
25382:925a1c3dd62a | 25383:57e815ace9e2 |
---|---|
1 ;;; timezone.el --- time zone package for GNU Emacs | 1 ;;; timezone.el --- time zone package for GNU Emacs |
2 | 2 |
3 ;; Copyright (C) 1990, 1991, 1992, 1993, 1996 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1990-1993, 1996, 1999 Free Software Foundation, Inc. |
4 | 4 |
5 ;; Author: Masanobu Umeda | 5 ;; Author: Masanobu Umeda |
6 ;; Maintainer: umerin@mse.kyutech.ac.jp | 6 ;; Maintainer: umerin@mse.kyutech.ac.jp |
7 ;; Keywords: news | 7 ;; Keywords: news |
8 | 8 |
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the | 22 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
24 ;; Boston, MA 02111-1307, USA. | 24 ;; Boston, MA 02111-1307, USA. |
25 | 25 |
26 ;;; Code: | 26 ;;; Code: |
27 | |
28 (provide 'timezone) | |
29 | 27 |
30 (defvar timezone-world-timezones | 28 (defvar timezone-world-timezones |
31 '(("PST" . -800) | 29 '(("PST" . -800) |
32 ("PDT" . -700) | 30 ("PDT" . -700) |
33 ("MST" . -700) | 31 ("MST" . -700) |
194 ((string-match | 192 ((string-match |
195 "\\([0-9]+\\)-\\([0-9]+\\)-\\([0-9]+\\)[ \t]+\\([0-9]+:[0-9]+:[0-9]+\\)" date) | 193 "\\([0-9]+\\)-\\([0-9]+\\)-\\([0-9]+\\)[ \t]+\\([0-9]+:[0-9]+:[0-9]+\\)" date) |
196 ;; Styles: (8) without timezone. | 194 ;; Styles: (8) without timezone. |
197 (setq year 1 month 2 day 3 time 4 zone nil)) | 195 (setq year 1 month 2 day 3 time 4 zone nil)) |
198 ) | 196 ) |
199 (if year | 197 (when year |
200 (progn | 198 (setq year (match-string year date)) |
201 (setq year | 199 ;; Guess ambiguous years. Assume years < 70 don't predate the |
202 (substring date (match-beginning year) (match-end year))) | 200 ;; Unix Epoch, so are 2000+. Three-digit years -- do they ever |
203 ;; It is now Dec 1992. 8 years before the end of the World. | 201 ;; occur? -- are (arbitrarily) assumed to be 21st century. |
204 (if (= (length year) 1) | 202 (if (< (length year) 4) |
205 (setq year (concat "190" (substring year -1 nil))) | 203 (let ((y (string-to-int year))) |
206 (if (< (length year) 4) | 204 (if (< y 70) |
207 (setq year (concat "19" (substring year -2 nil))))) | 205 (setq y (+ y 100))) |
208 (setq month | 206 (setq year (int-to-string (+ 1900 y))))) |
209 (if (= (aref date (+ (match-beginning month) 2)) ?-) | 207 (setq month |
210 ;; Handle numeric months, spanning exactly two digits. | 208 (if (= (aref date (+ (match-beginning month) 2)) ?-) |
211 (substring date | 209 ;; Handle numeric months, spanning exactly two digits. |
212 (match-beginning month) | 210 (substring date |
213 (+ (match-beginning month) 2)) | 211 (match-beginning month) |
214 (let* ((string (substring date | 212 (+ (match-beginning month) 2)) |
215 (match-beginning month) | 213 (let* ((string (substring date |
216 (+ (match-beginning month) 3))) | 214 (match-beginning month) |
217 (monthnum | 215 (+ (match-beginning month) 3))) |
218 (cdr (assoc (upcase string) timezone-months-assoc)))) | 216 (monthnum |
219 (if monthnum | 217 (cdr (assoc (upcase string) timezone-months-assoc)))) |
220 (int-to-string monthnum) | 218 (if monthnum |
221 nil)))) | 219 (int-to-string monthnum))))) |
222 (setq day | 220 (setq day (match-string day date)) |
223 (substring date (match-beginning day) (match-end day))) | 221 (setq time (match-string time date))) |
224 (setq time | 222 (if zone (setq zone (match-string zone date))) |
225 (substring date (match-beginning time) (match-end time))))) | |
226 (if zone | |
227 (setq zone | |
228 (substring date (match-beginning zone) (match-end zone)))) | |
229 ;; Return a vector. | 223 ;; Return a vector. |
230 (if (and year month) | 224 (if (and year month) |
231 (vector year month day time zone) | 225 (vector year month day time zone) |
232 (vector "0" "0" "0" "0" nil)) | 226 (vector "0" "0" "0" "0" nil)))) |
233 )) | |
234 | 227 |
235 (defun timezone-parse-time (time) | 228 (defun timezone-parse-time (time) |
236 "Parse TIME (HH:MM:SS) and return a vector [hour minute second]. | 229 "Parse TIME (HH:MM:SS) and return a vector [hour minute second]. |
237 Recognize HH:MM:SS, HH:MM, HHMMSS, HHMM." | 230 Recognize HH:MM:SS, HH:MM, HHMMSS, HHMM." |
238 (let ((time (or time "")) | 231 (let ((time (or time "")) |
239 (hour nil) | 232 hour minute second) |
240 (minute nil) | |
241 (second nil)) | |
242 (cond ((string-match "\\`\\([0-9]+\\):\\([0-9]+\\):\\([0-9]+\\)\\'" time) | 233 (cond ((string-match "\\`\\([0-9]+\\):\\([0-9]+\\):\\([0-9]+\\)\\'" time) |
243 ;; HH:MM:SS | 234 ;; HH:MM:SS |
244 (setq hour 1 minute 2 second 3)) | 235 (setq hour 1 minute 2 second 3)) |
245 ((string-match "\\`\\([0-9]+\\):\\([0-9]+\\)\\'" time) | 236 ((string-match "\\`\\([0-9]+\\):\\([0-9]+\\)\\'" time) |
246 ;; HH:MM | 237 ;; HH:MM |
252 ;; HHMM | 243 ;; HHMM |
253 (setq hour 1 minute 2 second nil)) | 244 (setq hour 1 minute 2 second nil)) |
254 ) | 245 ) |
255 ;; Return [hour minute second] | 246 ;; Return [hour minute second] |
256 (vector | 247 (vector |
257 (if hour | 248 (if hour (match-string hour time) "0") |
258 (substring time (match-beginning hour) (match-end hour)) "0") | 249 (if minute (match-string minute time) "0") |
259 (if minute | 250 (if second (match-string second time) "0")))) |
260 (substring time (match-beginning minute) (match-end minute)) "0") | |
261 (if second | |
262 (substring time (match-beginning second) (match-end second)) "0")) | |
263 )) | |
264 | 251 |
265 | 252 |
266 ;; Miscellaneous | 253 ;; Miscellaneous |
267 | 254 |
268 (defun timezone-zone-to-minute (timezone) | 255 (defun timezone-zone-to-minute (timezone) |
408 (* 365 (1- year));; + Days in prior years | 395 (* 365 (1- year));; + Days in prior years |
409 (/ (1- year) 4);; + Julian leap years | 396 (/ (1- year) 4);; + Julian leap years |
410 (- (/ (1- year) 100));; - century years | 397 (- (/ (1- year) 100));; - century years |
411 (/ (1- year) 400)));; + Gregorian leap years | 398 (/ (1- year) 400)));; + Gregorian leap years |
412 | 399 |
400 (provide 'timezone) | |
401 | |
413 ;;; timezone.el ends here | 402 ;;; timezone.el ends here |