diff options
| author | Dave Love | 1999-08-24 16:43:44 +0000 |
|---|---|---|
| committer | Dave Love | 1999-08-24 16:43:44 +0000 |
| commit | 64606d0779a0c0e7a6a53d71dcc7399b675a5e67 (patch) | |
| tree | edff029f9b4143836f9fbe5fff16e72637472443 /lisp | |
| parent | 8de38c21fc6d23185052457b7d633f2fea12d2dc (diff) | |
| download | emacs-64606d0779a0c0e7a6a53d71dcc7399b675a5e67.tar.gz emacs-64606d0779a0c0e7a6a53d71dcc7399b675a5e67.zip | |
Mode provide to end.
(timezone-parse-date): Simplify somewhat. Assume 2-digit years <70 are
2000+.
(timezone-parse-time): Simplify somewhat.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/timezone.el | 79 |
1 files changed, 34 insertions, 45 deletions
diff --git a/lisp/timezone.el b/lisp/timezone.el index 1b22bde4ee6..ff04cd13c7f 100644 --- a/lisp/timezone.el +++ b/lisp/timezone.el | |||
| @@ -1,6 +1,6 @@ | |||
| 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 |
| @@ -25,8 +25,6 @@ | |||
| 25 | 25 | ||
| 26 | ;;; Code: | 26 | ;;; Code: |
| 27 | 27 | ||
| 28 | (provide 'timezone) | ||
| 29 | |||
| 30 | (defvar timezone-world-timezones | 28 | (defvar timezone-world-timezones |
| 31 | '(("PST" . -800) | 29 | '(("PST" . -800) |
| 32 | ("PDT" . -700) | 30 | ("PDT" . -700) |
| @@ -196,49 +194,42 @@ Understands the following styles: | |||
| 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)) |
| @@ -254,13 +245,9 @@ Recognize HH:MM:SS, HH:MM, HHMMSS, HHMM." | |||
| 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 |
| @@ -410,4 +397,6 @@ The Gregorian date Sunday, December 31, 1 BC is imaginary." | |||
| 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 |