Mercurial > emacs
annotate lisp/calendar/parse-time.el @ 45901:1b38863a543b
*** empty log message ***
author | Juanma Barranquero <lekktu@gmail.com> |
---|---|
date | Tue, 18 Jun 2002 14:37:33 +0000 |
parents | ebb4fa093863 |
children | 827133772385 |
rev | line source |
---|---|
43048
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
1 ;;; parse-time.el --- parsing time strings |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
2 |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
3 ;; Copyright (C) 1996, 2000 by Free Software Foundation, Inc. |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
4 |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
5 ;; Author: Erik Naggum <erik@naggum.no> |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
6 ;; Keywords: util |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
7 |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
8 ;; This file is part of GNU Emacs. |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
9 |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
10 ;; GNU Emacs is free software; you can redistribute it and/or modify |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
11 ;; it under the terms of the GNU General Public License as published by |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
12 ;; the Free Software Foundation; either version 2, or (at your option) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
13 ;; any later version. |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
14 |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
15 ;; GNU Emacs is distributed in the hope that it will be useful, |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
18 ;; GNU General Public License for more details. |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
19 |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
20 ;; You should have received a copy of the GNU General Public License |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
21 ;; along with GNU Emacs; see the file COPYING. If not, write to |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
22 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
23 ;; Boston, MA 02111-1307, USA. |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
24 |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
25 ;;; Commentary: |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
26 |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
27 ;; With the introduction of the `encode-time', `decode-time', and |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
28 ;; `format-time-string' functions, dealing with time became simpler in |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
29 ;; Emacs. However, parsing time strings is still largely a matter of |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
30 ;; heuristics and no common interface has been designed. |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
31 |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
32 ;; `parse-time-string' parses a time in a string and returns a list of 9 |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
33 ;; values, just like `decode-time', where unspecified elements in the |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
34 ;; string are returned as nil. `encode-time' may be applied on these |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
35 ;; valuse to obtain an internal time value. |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
36 |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
37 ;;; Code: |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
38 |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
39 (eval-when-compile (require 'cl)) ;and ah ain't kiddin' 'bout it |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
40 |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
41 (defvar parse-time-syntax (make-vector 256 nil)) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
42 (defvar parse-time-digits (make-vector 256 nil)) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
43 |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
44 ;; Byte-compiler warnings |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
45 (defvar elt) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
46 (defvar val) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
47 |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
48 (unless (aref parse-time-digits ?0) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
49 (loop for i from ?0 to ?9 |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
50 do (aset parse-time-digits i (- i ?0)))) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
51 |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
52 (unless (aref parse-time-syntax ?0) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
53 (loop for i from ?0 to ?9 |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
54 do (aset parse-time-syntax i ?0)) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
55 (loop for i from ?A to ?Z |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
56 do (aset parse-time-syntax i ?A)) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
57 (loop for i from ?a to ?z |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
58 do (aset parse-time-syntax i ?a)) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
59 (aset parse-time-syntax ?+ 1) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
60 (aset parse-time-syntax ?- -1) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
61 (aset parse-time-syntax ?: ?d) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
62 ) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
63 |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
64 (defsubst digit-char-p (char) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
65 (aref parse-time-digits char)) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
66 |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
67 (defsubst parse-time-string-chars (char) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
68 (aref parse-time-syntax char)) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
69 |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
70 (put 'parse-error 'error-conditions '(parse-error error)) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
71 (put 'parse-error 'error-message "Parsing error") |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
72 |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
73 (defsubst parse-integer (string &optional start end) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
74 "[CL] Parse and return the integer in STRING, or nil if none." |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
75 (let ((integer 0) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
76 (digit 0) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
77 (index (or start 0)) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
78 (end (or end (length string)))) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
79 (when (< index end) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
80 (let ((sign (aref string index))) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
81 (if (or (eq sign ?+) (eq sign ?-)) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
82 (setq sign (parse-time-string-chars sign) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
83 index (1+ index)) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
84 (setq sign 1)) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
85 (while (and (< index end) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
86 (setq digit (digit-char-p (aref string index)))) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
87 (setq integer (+ (* integer 10) digit) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
88 index (1+ index))) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
89 (if (/= index end) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
90 (signal 'parse-error `("not an integer" |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
91 ,(substring string (or start 0) end))) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
92 (* sign integer)))))) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
93 |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
94 (defun parse-time-tokenize (string) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
95 "Tokenize STRING into substrings." |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
96 (let ((start nil) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
97 (end (length string)) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
98 (all-digits nil) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
99 (list ()) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
100 (index 0) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
101 (c nil)) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
102 (while (< index end) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
103 (while (and (< index end) ;skip invalid characters |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
104 (not (setq c (parse-time-string-chars (aref string index))))) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
105 (incf index)) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
106 (setq start index all-digits (eq c ?0)) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
107 (while (and (< (incf index) end) ;scan valid characters |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
108 (setq c (parse-time-string-chars (aref string index)))) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
109 (setq all-digits (and all-digits (eq c ?0)))) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
110 (if (<= index end) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
111 (push (if all-digits (parse-integer string start index) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
112 (substring string start index)) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
113 list))) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
114 (nreverse list))) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
115 |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
116 (defvar parse-time-months '(("jan" . 1) ("feb" . 2) ("mar" . 3) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
117 ("apr" . 4) ("may" . 5) ("jun" . 6) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
118 ("jul" . 7) ("aug" . 8) ("sep" . 9) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
119 ("oct" . 10) ("nov" . 11) ("dec" . 12))) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
120 (defvar parse-time-weekdays '(("sun" . 0) ("mon" . 1) ("tue" . 2) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
121 ("wed" . 3) ("thu" . 4) ("fri" . 5) ("sat" . 6))) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
122 (defvar parse-time-zoneinfo `(("z" 0) ("ut" 0) ("gmt" 0) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
123 ("pst" ,(* -8 3600)) ("pdt" ,(* -7 3600) t) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
124 ("mst" ,(* -7 3600)) ("mdt" ,(* -6 3600) t) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
125 ("cst" ,(* -6 3600)) ("cdt" ,(* -5 3600) t) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
126 ("est" ,(* -5 3600)) ("edt" ,(* -4 3600) t)) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
127 "(zoneinfo seconds-off daylight-savings-time-p)") |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
128 |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
129 (defvar parse-time-rules |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
130 `(((6) parse-time-weekdays) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
131 ((3) (1 31)) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
132 ((4) parse-time-months) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
133 ((5) (100 4038)) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
134 ((2 1 0) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
135 ,#'(lambda () (and (stringp elt) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
136 (= (length elt) 8) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
137 (= (aref elt 2) ?:) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
138 (= (aref elt 5) ?:))) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
139 [0 2] [3 5] [6 8]) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
140 ((8 7) parse-time-zoneinfo |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
141 ,#'(lambda () (car val)) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
142 ,#'(lambda () (cadr val))) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
143 ((8) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
144 ,#'(lambda () |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
145 (and (stringp elt) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
146 (= 5 (length elt)) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
147 (or (= (aref elt 0) ?+) (= (aref elt 0) ?-)))) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
148 ,#'(lambda () (* 60 (+ (parse-integer elt 3 5) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
149 (* 60 (parse-integer elt 1 3))) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
150 (if (= (aref elt 0) ?-) -1 1)))) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
151 ((5 4 3) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
152 ,#'(lambda () (and (stringp elt) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
153 (= (length elt) 10) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
154 (= (aref elt 4) ?-) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
155 (= (aref elt 7) ?-))) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
156 [0 4] [5 7] [8 10]) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
157 ((2 1 0) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
158 ,#'(lambda () (and (stringp elt) (= (length elt) 5) (= (aref elt 2) ?:))) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
159 [0 2] [3 5] ,#'(lambda () 0)) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
160 ((2 1 0) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
161 ,#'(lambda () (and (stringp elt) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
162 (= (length elt) 4) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
163 (= (aref elt 1) ?:))) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
164 [0 1] [2 4] ,#'(lambda () 0)) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
165 ((2 1 0) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
166 ,#'(lambda () (and (stringp elt) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
167 (= (length elt) 7) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
168 (= (aref elt 1) ?:))) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
169 [0 1] [2 4] [5 7]) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
170 ((5) (50 110) ,#'(lambda () (+ 1900 elt))) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
171 ((5) (0 49) ,#'(lambda () (+ 2000 elt)))) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
172 "(slots predicate extractor...)") |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
173 |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
174 (defun parse-time-string (string) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
175 "Parse the time-string STRING into (SEC MIN HOUR DAY MON YEAR DOW DST TZ). |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
176 The values are identical to those of `decode-time', but any values that are |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
177 unknown are returned as nil." |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
178 (let ((time (list nil nil nil nil nil nil nil nil nil)) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
179 (temp (parse-time-tokenize (downcase string)))) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
180 (while temp |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
181 (let ((elt (pop temp)) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
182 (rules parse-time-rules) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
183 (exit nil)) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
184 (while (and (not (null rules)) (not exit)) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
185 (let* ((rule (pop rules)) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
186 (slots (pop rule)) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
187 (predicate (pop rule)) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
188 (val)) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
189 (when (and (not (nth (car slots) time)) ;not already set |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
190 (setq val (cond ((and (consp predicate) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
191 (not (eq (car predicate) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
192 'lambda))) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
193 (and (numberp elt) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
194 (<= (car predicate) elt) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
195 (<= elt (cadr predicate)) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
196 elt)) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
197 ((symbolp predicate) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
198 (cdr (assoc elt |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
199 (symbol-value predicate)))) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
200 ((funcall predicate))))) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
201 (setq exit t) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
202 (while slots |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
203 (let ((new-val (and rule |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
204 (let ((this (pop rule))) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
205 (if (vectorp this) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
206 (parse-integer |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
207 elt (aref this 0) (aref this 1)) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
208 (funcall this)))))) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
209 (rplaca (nthcdr (pop slots) time) (or new-val val))))))))) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
210 time)) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
211 |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
212 (provide 'parse-time) |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
213 |
ebb4fa093863
Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff
changeset
|
214 ;;; parse-time.el ends here |