annotate lisp/calendar/parse-time.el @ 74931:94fc36e46118

(select-safe-coding-system-interactively): Use face `link' for problematic chars.
author Kenichi Handa <handa@m17n.org>
date Wed, 27 Dec 2006 05:11:42 +0000
parents 8daf7d9a0771
children 7a3f13e2dd57 4b3d39451150
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
68721
8daf7d9a0771 Add 2006 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 67465
diff changeset
3 ;; Copyright (C) 1996, 2000, 2001, 2002, 2003, 2004, 2005, 2006
67465
a55ee709ec8d Update copyright pending Emacs 22.
Glenn Morris <rgm@gnu.org>
parents: 64085
diff changeset
4 ;; Free Software Foundation, Inc.
43048
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
5
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
6 ;; 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
7 ;; Keywords: util
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
8
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
9 ;; 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
10
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
11 ;; 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
12 ;; 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
13 ;; 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
14 ;; any later version.
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
15
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
16 ;; 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
17 ;; 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
18 ;; 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
19 ;; 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
20
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
21 ;; 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
22 ;; along with GNU Emacs; see the file COPYING. If not, write to
64085
18a818a2ee7c Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 52623
diff changeset
23 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18a818a2ee7c Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 52623
diff changeset
24 ;; Boston, MA 02110-1301, USA.
43048
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
25
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
26 ;;; Commentary:
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
27
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
28 ;; 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
29 ;; `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
30 ;; 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
31 ;; 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
32
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
33 ;; `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
34 ;; 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
35 ;; string are returned as nil. `encode-time' may be applied on these
48411
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
36 ;; values to obtain an internal time value.
43048
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
37
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
38 ;;; Code:
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
39
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
40 (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
41
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
42 (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
43 (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
44
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
45 ;; Byte-compiler warnings
48411
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
46 (defvar parse-time-elt)
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
47 (defvar parse-time-val)
43048
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
48
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
49 (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
50 (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
51 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
52
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
53 (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
54 (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
55 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
56 (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
57 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
58 (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
59 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
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 ?- -1)
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
62 (aset parse-time-syntax ?: ?d)
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
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
65 (defsubst digit-char-p (char)
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
66 (aref parse-time-digits char))
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
67
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
68 (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
69 (aref parse-time-syntax char))
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
70
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
71 (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
72 (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
73
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
74 (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
75 "[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
76 (let ((integer 0)
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
77 (digit 0)
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
78 (index (or start 0))
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
79 (end (or end (length string))))
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
80 (when (< index end)
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
81 (let ((sign (aref string index)))
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
82 (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
83 (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
84 index (1+ index))
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
85 (setq sign 1))
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
86 (while (and (< index end)
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
87 (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
88 (setq integer (+ (* integer 10) digit)
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
89 index (1+ index)))
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
90 (if (/= index end)
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
91 (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
92 ,(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
93 (* sign integer))))))
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
94
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
95 (defun parse-time-tokenize (string)
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
96 "Tokenize STRING into substrings."
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
97 (let ((start nil)
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
98 (end (length string))
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
99 (all-digits nil)
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
100 (list ())
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
101 (index 0)
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
102 (c nil))
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
103 (while (< index end)
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
104 (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
105 (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
106 (incf index))
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
107 (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
108 (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
109 (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
110 (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
111 (if (<= index end)
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
112 (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
113 (substring string start index))
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
114 list)))
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
115 (nreverse list)))
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
116
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
117 (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
118 ("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
119 ("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
120 ("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
121 (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
122 ("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
123 (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
124 ("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
125 ("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
126 ("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
127 ("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
128 "(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
129
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
130 (defvar parse-time-rules
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
131 `(((6) parse-time-weekdays)
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
132 ((3) (1 31))
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
133 ((4) parse-time-months)
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
134 ((5) (100 4038))
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
135 ((2 1 0)
48411
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
136 ,#'(lambda () (and (stringp parse-time-elt)
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
137 (= (length parse-time-elt) 8)
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
138 (= (aref parse-time-elt 2) ?:)
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
139 (= (aref parse-time-elt 5) ?:)))
43048
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
140 [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
141 ((8 7) parse-time-zoneinfo
48411
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
142 ,#'(lambda () (car parse-time-val))
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
143 ,#'(lambda () (cadr parse-time-val)))
43048
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
144 ((8)
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
145 ,#'(lambda ()
48411
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
146 (and (stringp parse-time-elt)
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
147 (= 5 (length parse-time-elt))
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
148 (or (= (aref parse-time-elt 0) ?+)
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
149 (= (aref parse-time-elt 0) ?-))))
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
150 ,#'(lambda () (* 60 (+ (parse-integer parse-time-elt 3 5)
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
151 (* 60 (parse-integer parse-time-elt 1 3)))
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
152 (if (= (aref parse-time-elt 0) ?-) -1 1))))
43048
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
153 ((5 4 3)
48411
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
154 ,#'(lambda () (and (stringp parse-time-elt)
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
155 (= (length parse-time-elt) 10)
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
156 (= (aref parse-time-elt 4) ?-)
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
157 (= (aref parse-time-elt 7) ?-)))
43048
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
158 [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
159 ((2 1 0)
48411
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
160 ,#'(lambda () (and (stringp parse-time-elt)
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
161 (= (length parse-time-elt) 5)
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
162 (= (aref parse-time-elt 2) ?:)))
43048
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
163 [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
164 ((2 1 0)
48411
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
165 ,#'(lambda () (and (stringp parse-time-elt)
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
166 (= (length parse-time-elt) 4)
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
167 (= (aref parse-time-elt 1) ?:)))
43048
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
168 [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
169 ((2 1 0)
48411
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
170 ,#'(lambda () (and (stringp parse-time-elt)
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
171 (= (length parse-time-elt) 7)
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
172 (= (aref parse-time-elt 1) ?:)))
43048
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
173 [0 1] [2 4] [5 7])
48411
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
174 ((5) (50 110) ,#'(lambda () (+ 1900 parse-time-elt)))
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
175 ((5) (0 49) ,#'(lambda () (+ 2000 parse-time-elt))))
43048
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
176 "(slots predicate extractor...)")
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
177
52623
0edad246b289 (parse-time-string): Add autoload cookie.
André Spiegel <spiegel@gnu.org>
parents: 52401
diff changeset
178 ;;;###autoload
43048
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
179 (defun parse-time-string (string)
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
180 "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
181 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
182 unknown are returned as nil."
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
183 (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
184 (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
185 (while temp
48411
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
186 (let ((parse-time-elt (pop temp))
43048
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
187 (rules parse-time-rules)
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
188 (exit nil))
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
189 (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
190 (let* ((rule (pop rules))
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
191 (slots (pop rule))
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
192 (predicate (pop rule))
48411
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
193 (parse-time-val))
43048
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
194 (when (and (not (nth (car slots) time)) ;not already set
48411
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
195 (setq parse-time-val (cond ((and (consp predicate)
43048
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
196 (not (eq (car predicate)
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
197 'lambda)))
48411
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
198 (and (numberp parse-time-elt)
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
199 (<= (car predicate) parse-time-elt)
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
200 (<= parse-time-elt (cadr predicate))
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
201 parse-time-elt))
43048
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
202 ((symbolp predicate)
48411
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
203 (cdr (assoc parse-time-elt
43048
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
204 (symbol-value predicate))))
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
205 ((funcall predicate)))))
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
206 (setq exit t)
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
207 (while slots
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
208 (let ((new-val (and rule
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
209 (let ((this (pop rule)))
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
210 (if (vectorp this)
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
211 (parse-integer
48411
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
212 parse-time-elt
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
213 (aref this 0) (aref this 1))
43048
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
214 (funcall this))))))
48411
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
215 (rplaca (nthcdr (pop slots) time)
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
216 (or new-val parse-time-val)))))))))
43048
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
217 time))
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
218
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
219 (provide 'parse-time)
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
220
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 48411
diff changeset
221 ;;; arch-tag: 07066094-45a8-4c68-b307-86195e2c1103
43048
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
222 ;;; parse-time.el ends here