annotate lisp/calendar/parse-time.el @ 110806:62865a8e7f58

Rename shadow-mode. * lisp/emacs-lisp/shadow.el (shadow-font-lock-keywords) (load-path-shadows-mode, list-load-path-shadows): Rename shadow-mode to load-path-shadows-mode, update references.
author Glenn Morris <rgm@gnu.org>
date Thu, 07 Oct 2010 10:17:18 -0700
parents 8d09094063d0
children 417b1e4d63cd
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
92959
1f109b306995 (parse-time-string): Simplify.
Glenn Morris <rgm@gnu.org>
parents: 79703
diff changeset
3 ;; Copyright (C) 1996, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
106815
1d1d5d9bd884 Add 2010 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 104612
diff changeset
4 ;; 2008, 2009, 2010 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
94653
e49abd957e81 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
43048
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
94653
e49abd957e81 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
13 ;; the Free Software Foundation, either version 3 of the License, or
e49abd957e81 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
14 ;; (at your option) any later version.
43048
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
94653
e49abd957e81 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
43048
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
23
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
24 ;;; Commentary:
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 ;; 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
27 ;; `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
28 ;; 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
29 ;; 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
30
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
31 ;; `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
32 ;; 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
33 ;; 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
34 ;; 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
35
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
36 ;;; Code:
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 (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
39
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
40 (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
41
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
42 ;; Byte-compiler warnings
48411
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
43 (defvar parse-time-elt)
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
44 (defvar parse-time-val)
43048
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
45
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
46 (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
47 (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
48 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
49
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
50 (defsubst digit-char-p (char)
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
51 (aref parse-time-digits char))
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 (defsubst parse-time-string-chars (char)
104309
d38c249bcfee * calendar/parse-time.el (parse-time-string-chars): Save match data.
Chong Yidong <cyd@stupidchicken.com>
parents: 104299
diff changeset
54 (save-match-data
d38c249bcfee * calendar/parse-time.el (parse-time-string-chars): Save match data.
Chong Yidong <cyd@stupidchicken.com>
parents: 104299
diff changeset
55 (let (case-fold-search str)
d38c249bcfee * calendar/parse-time.el (parse-time-string-chars): Save match data.
Chong Yidong <cyd@stupidchicken.com>
parents: 104299
diff changeset
56 (cond ((eq char ?+) 1)
d38c249bcfee * calendar/parse-time.el (parse-time-string-chars): Save match data.
Chong Yidong <cyd@stupidchicken.com>
parents: 104299
diff changeset
57 ((eq char ?-) -1)
d38c249bcfee * calendar/parse-time.el (parse-time-string-chars): Save match data.
Chong Yidong <cyd@stupidchicken.com>
parents: 104299
diff changeset
58 ((eq char ?:) ?d)
d38c249bcfee * calendar/parse-time.el (parse-time-string-chars): Save match data.
Chong Yidong <cyd@stupidchicken.com>
parents: 104299
diff changeset
59 ((string-match "[[:upper:]]" (setq str (string char))) ?A)
d38c249bcfee * calendar/parse-time.el (parse-time-string-chars): Save match data.
Chong Yidong <cyd@stupidchicken.com>
parents: 104299
diff changeset
60 ((string-match "[[:lower:]]" str) ?a)
d38c249bcfee * calendar/parse-time.el (parse-time-string-chars): Save match data.
Chong Yidong <cyd@stupidchicken.com>
parents: 104299
diff changeset
61 ((string-match "[[:digit:]]" str) ?0)))))
43048
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 (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
64 (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
65
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
66 (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
67 "[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
68 (let ((integer 0)
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
69 (digit 0)
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
70 (index (or start 0))
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
71 (end (or end (length string))))
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
72 (when (< index end)
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
73 (let ((sign (aref string index)))
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
74 (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
75 (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
76 index (1+ index))
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
77 (setq sign 1))
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
78 (while (and (< index end)
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
79 (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
80 (setq integer (+ (* integer 10) digit)
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
81 index (1+ index)))
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
82 (if (/= index end)
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
83 (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
84 ,(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
85 (* sign integer))))))
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
86
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
87 (defun parse-time-tokenize (string)
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
88 "Tokenize STRING into substrings."
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
89 (let ((start nil)
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
90 (end (length string))
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
91 (all-digits nil)
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
92 (list ())
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
93 (index 0)
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
94 (c nil))
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
95 (while (< index end)
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
96 (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
97 (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
98 (incf index))
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
99 (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
100 (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
101 (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
102 (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
103 (if (<= index end)
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
104 (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
105 (substring string start index))
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
106 list)))
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
107 (nreverse list)))
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
108
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
109 (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
110 ("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
111 ("jul" . 7) ("aug" . 8) ("sep" . 9)
95337
d14462d93d22 (parse-time-months, parse-time-weekdays): Add long-form month and day names.
Chong Yidong <cyd@stupidchicken.com>
parents: 94653
diff changeset
112 ("oct" . 10) ("nov" . 11) ("dec" . 12)
d14462d93d22 (parse-time-months, parse-time-weekdays): Add long-form month and day names.
Chong Yidong <cyd@stupidchicken.com>
parents: 94653
diff changeset
113 ("january" . 1) ("february" . 2)
d14462d93d22 (parse-time-months, parse-time-weekdays): Add long-form month and day names.
Chong Yidong <cyd@stupidchicken.com>
parents: 94653
diff changeset
114 ("march" . 3) ("april" . 4) ("june" . 6)
d14462d93d22 (parse-time-months, parse-time-weekdays): Add long-form month and day names.
Chong Yidong <cyd@stupidchicken.com>
parents: 94653
diff changeset
115 ("july" . 7) ("august" . 8)
d14462d93d22 (parse-time-months, parse-time-weekdays): Add long-form month and day names.
Chong Yidong <cyd@stupidchicken.com>
parents: 94653
diff changeset
116 ("september" . 9) ("october" . 10)
d14462d93d22 (parse-time-months, parse-time-weekdays): Add long-form month and day names.
Chong Yidong <cyd@stupidchicken.com>
parents: 94653
diff changeset
117 ("november" . 11) ("december" . 12)))
43048
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
118 (defvar parse-time-weekdays '(("sun" . 0) ("mon" . 1) ("tue" . 2)
95337
d14462d93d22 (parse-time-months, parse-time-weekdays): Add long-form month and day names.
Chong Yidong <cyd@stupidchicken.com>
parents: 94653
diff changeset
119 ("wed" . 3) ("thu" . 4) ("fri" . 5)
d14462d93d22 (parse-time-months, parse-time-weekdays): Add long-form month and day names.
Chong Yidong <cyd@stupidchicken.com>
parents: 94653
diff changeset
120 ("sat" . 6) ("sunday" . 0) ("monday" . 1)
d14462d93d22 (parse-time-months, parse-time-weekdays): Add long-form month and day names.
Chong Yidong <cyd@stupidchicken.com>
parents: 94653
diff changeset
121 ("tuesday" . 2) ("wednesday" . 3)
d14462d93d22 (parse-time-months, parse-time-weekdays): Add long-form month and day names.
Chong Yidong <cyd@stupidchicken.com>
parents: 94653
diff changeset
122 ("thursday" . 4) ("friday" . 5)
d14462d93d22 (parse-time-months, parse-time-weekdays): Add long-form month and day names.
Chong Yidong <cyd@stupidchicken.com>
parents: 94653
diff changeset
123 ("saturday" . 6)))
43048
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
124 (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
125 ("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
126 ("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
127 ("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
128 ("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
129 "(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
130
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
131 (defvar parse-time-rules
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
132 `(((6) parse-time-weekdays)
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
133 ((3) (1 31))
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
134 ((4) parse-time-months)
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
135 ((5) (100 4038))
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
136 ((2 1 0)
48411
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
137 ,#'(lambda () (and (stringp parse-time-elt)
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
138 (= (length parse-time-elt) 8)
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
139 (= (aref parse-time-elt 2) ?:)
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
140 (= (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
141 [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
142 ((8 7) parse-time-zoneinfo
48411
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
143 ,#'(lambda () (car parse-time-val))
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
144 ,#'(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
145 ((8)
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
146 ,#'(lambda ()
48411
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
147 (and (stringp parse-time-elt)
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
148 (= 5 (length parse-time-elt))
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
149 (or (= (aref parse-time-elt 0) ?+)
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
150 (= (aref parse-time-elt 0) ?-))))
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
151 ,#'(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
152 (* 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
153 (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
154 ((5 4 3)
48411
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
155 ,#'(lambda () (and (stringp parse-time-elt)
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
156 (= (length parse-time-elt) 10)
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
157 (= (aref parse-time-elt 4) ?-)
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
158 (= (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
159 [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
160 ((2 1 0)
48411
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
161 ,#'(lambda () (and (stringp parse-time-elt)
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
162 (= (length parse-time-elt) 5)
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
163 (= (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
164 [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
165 ((2 1 0)
48411
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
166 ,#'(lambda () (and (stringp parse-time-elt)
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
167 (= (length parse-time-elt) 4)
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
168 (= (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
169 [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
170 ((2 1 0)
48411
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
171 ,#'(lambda () (and (stringp parse-time-elt)
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
172 (= (length parse-time-elt) 7)
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
173 (= (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
174 [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
175 ((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
176 ((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
177 "(slots predicate extractor...)")
104612
c220a29e75fd Define risky-local-variable property here rather than in files.el.
Glenn Morris <rgm@gnu.org>
parents: 104309
diff changeset
178 ;;;###autoload(put 'parse-time-rules 'risky-local-variable t)
43048
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
179
52623
0edad246b289 (parse-time-string): Add autoload cookie.
André Spiegel <spiegel@gnu.org>
parents: 52401
diff changeset
180 ;;;###autoload
43048
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
181 (defun parse-time-string (string)
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
182 "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
183 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
184 unknown are returned as nil."
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
185 (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
186 (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
187 (while temp
48411
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
188 (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
189 (rules parse-time-rules)
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
190 (exit nil))
92959
1f109b306995 (parse-time-string): Simplify.
Glenn Morris <rgm@gnu.org>
parents: 79703
diff changeset
191 (while (and rules (not exit))
43048
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
192 (let* ((rule (pop rules))
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
193 (slots (pop rule))
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
194 (predicate (pop rule))
48411
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
195 (parse-time-val))
43048
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
196 (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
197 (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
198 (not (eq (car predicate)
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
199 'lambda)))
48411
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
200 (and (numberp parse-time-elt)
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
201 (<= (car predicate) parse-time-elt)
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
202 (<= parse-time-elt (cadr predicate))
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
203 parse-time-elt))
43048
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
204 ((symbolp predicate)
48411
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
205 (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
206 (symbol-value predicate))))
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
207 ((funcall predicate)))))
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
208 (setq exit t)
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
209 (while slots
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
210 (let ((new-val (and rule
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
211 (let ((this (pop rule)))
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
212 (if (vectorp this)
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
213 (parse-integer
48411
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
214 parse-time-elt
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
215 (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
216 (funcall this))))))
48411
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
217 (rplaca (nthcdr (pop slots) time)
827133772385 (parse-time-elt): Var renamed from `elt'.
Richard M. Stallman <rms@gnu.org>
parents: 43048
diff changeset
218 (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
219 time))
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
220
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
221 (provide 'parse-time)
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
222
ebb4fa093863 Moved parse-time.el from lisp/gnus to lisp/calendar.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
223 ;;; parse-time.el ends here