Mercurial > emacs
comparison lisp/timezone.el @ 32290:0d473fed67ba
(timezone-parse-date): Doc fix. Fix regexps for (5)
without timezone and (8) with timezone to enforce some whitespace.
Simplify code somewhat.
author | Dave Love <fx@gnu.org> |
---|---|
date | Sun, 08 Oct 2000 16:26:04 +0000 |
parents | 005bb11b61bb |
children | b174db545cfd |
comparison
equal
deleted
inserted
replaced
32289:1c042b411eda | 32290:0d473fed67ba |
---|---|
118 "Make time string from HOUR, MINUTE, and SECOND." | 118 "Make time string from HOUR, MINUTE, and SECOND." |
119 (format "%02d:%02d:%02d" hour minute second)) | 119 (format "%02d:%02d:%02d" hour minute second)) |
120 | 120 |
121 (defun timezone-parse-date (date) | 121 (defun timezone-parse-date (date) |
122 "Parse DATE and return a vector [YEAR MONTH DAY TIME TIMEZONE]. | 122 "Parse DATE and return a vector [YEAR MONTH DAY TIME TIMEZONE]. |
123 19 is prepended to year if necessary. Timezone may be nil if nothing. | 123 Two-digit dates are `windowed'. Those <69 have 2000 added; otherwise 1900 |
124 is added. Three-digit dates have 1900 added. | |
125 TIMEZONE is nil for DATEs without a zone field. | |
126 | |
124 Understands the following styles: | 127 Understands the following styles: |
125 (1) 14 Apr 89 03:20[:12] [GMT] | 128 (1) 14 Apr 89 03:20[:12] [GMT] |
126 (2) Fri, 17 Mar 89 4:01[:33] [GMT] | 129 (2) Fri, 17 Mar 89 4:01[:33] [GMT] |
127 (3) Mon Jan 16 16:12[:37] [GMT] 1989 | 130 (3) Mon Jan 16 16:12[:37] [GMT] 1989 |
128 (4) 6 May 1992 1641-JST (Wednesday) | 131 (4) 6 May 1992 1641-JST (Wednesday) |
180 ((string-match | 183 ((string-match |
181 "\\([0-9]+\\)-\\([A-Za-z]+\\)-\\([0-9]+\\)[ \t]+\\([0-9]+:[0-9]+:[0-9]+\\)\\(\\.[0-9]+\\)?" date) | 184 "\\([0-9]+\\)-\\([A-Za-z]+\\)-\\([0-9]+\\)[ \t]+\\([0-9]+:[0-9]+:[0-9]+\\)\\(\\.[0-9]+\\)?" date) |
182 ;; Styles: (5) without timezone. | 185 ;; Styles: (5) without timezone. |
183 (setq year 3 month 2 day 1 time 4 zone nil)) | 186 (setq year 3 month 2 day 1 time 4 zone nil)) |
184 ((string-match | 187 ((string-match |
185 "\\([0-9]+\\)-\\([0-9]+\\)-\\([0-9]+\\)[ \t]+\\([0-9]+:[0-9]+:[0-9]+\\)[ \t]*\\([-+a-zA-Z0-9]+\\)" date) | 188 "\\([0-9]+\\)-\\([0-9]+\\)-\\([0-9]+\\)[ \t]+\\([0-9]+:[0-9]+:[0-9]+\\)[ \t]+\\([-+a-zA-Z0-9]+\\)" date) |
186 ;; Styles: (8) with timezone. | 189 ;; Styles: (8) with timezone. |
187 (setq year 1 month 2 day 3 time 4 zone 5)) | 190 (setq year 1 month 2 day 3 time 4 zone 5)) |
188 ((string-match | 191 ((string-match |
189 "\\([0-9]+\\)-\\([0-9]+\\)-\\([0-9]+\\)[ \t]+\\([0-9]+:[0-9]+\\)[ \t]*\\([-+a-zA-Z0-9:]+\\)" date) | 192 "\\([0-9]+\\)-\\([0-9]+\\)-\\([0-9]+\\)[ \t]+\\([0-9]+:[0-9]+\\)[ \t]+\\([-+a-zA-Z0-9:]+\\)" date) |
190 ;; Styles: (8) with timezone with a colon in it. | 193 ;; Styles: (8) with timezone with a colon in it. |
191 (setq year 1 month 2 day 3 time 4 zone 5)) | 194 (setq year 1 month 2 day 3 time 4 zone 5)) |
192 ((string-match | 195 ((string-match |
193 "\\([0-9]+\\)-\\([0-9]+\\)-\\([0-9]+\\)[ \t]+\\([0-9]+:[0-9]+:[0-9]+\\)" date) | 196 "\\([0-9]+\\)-\\([0-9]+\\)-\\([0-9]+\\)[ \t]+\\([0-9]+:[0-9]+:[0-9]+\\)" date) |
194 ;; Styles: (8) without timezone. | 197 ;; Styles: (8) without timezone. |
337 (setq minute (- minute (* 60 hour-fix))) | 340 (setq minute (- minute (* 60 hour-fix))) |
338 ;; HOUR may be larger than 24 or smaller than 0. | 341 ;; HOUR may be larger than 24 or smaller than 0. |
339 (cond ((<= 24 hour) ;24 -> 00 | 342 (cond ((<= 24 hour) ;24 -> 00 |
340 (setq hour (- hour 24)) | 343 (setq hour (- hour 24)) |
341 (setq day (1+ day)) | 344 (setq day (1+ day)) |
342 (if (< (timezone-last-day-of-month month year) day) | 345 (when (< (timezone-last-day-of-month month year) day) |
343 (progn | 346 (setq month (1+ month)) |
344 (setq month (1+ month)) | 347 (setq day 1) |
345 (setq day 1) | 348 (when (< 12 month) |
346 (if (< 12 month) | 349 (setq month 1) |
347 (progn | 350 (setq year (1+ year))))) |
348 (setq month 1) | |
349 (setq year (1+ year)) | |
350 )) | |
351 ))) | |
352 ((> 0 hour) | 351 ((> 0 hour) |
353 (setq hour (+ hour 24)) | 352 (setq hour (+ hour 24)) |
354 (setq day (1- day)) | 353 (setq day (1- day)) |
355 (if (> 1 day) | 354 (when (> 1 day) |
356 (progn | 355 (setq month (1- month)) |
357 (setq month (1- month)) | 356 (when (> 1 month) |
358 (if (> 1 month) | 357 (setq month 12) |
359 (progn | 358 (setq year (1- year))) |
360 (setq month 12) | 359 (setq day (timezone-last-day-of-month month year))))) |
361 (setq year (1- year)) | |
362 )) | |
363 (setq day (timezone-last-day-of-month month year)) | |
364 ))) | |
365 ) | |
366 (vector year month day hour minute second timezone))) | 360 (vector year month day hour minute second timezone))) |
367 | 361 |
368 ;; Partly copied from Calendar program by Edward M. Reingold. | 362 ;; Partly copied from Calendar program by Edward M. Reingold. |
369 ;; Thanks a lot. | 363 ;; Thanks a lot. |
370 | 364 |