annotate lisp/utils/timezone.el @ 143:50e7fedfe353

Added tag r20-2b5 for changeset 1856695b1fa9
author cvs
date Mon, 13 Aug 2007 09:33:20 +0200
parents 364816949b59
children 43dd3413c7c7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; timezone.el --- time zone package for GNU Emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Author: Masanobu Umeda
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Maintainer: umerin@mse.kyutech.ac.jp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; Keywords: news
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
22 ;; along with XEmacs; see the file COPYING. If not, write to the
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
24 ;; Boston, MA 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;;; Synched up with: FSF 19.30.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;; Modified 1 February 1994 by Kyle Jones to fix broken
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;; timezone-floor function.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;; Modified 25 January 1994 by Kyle Jones so that it will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;; work under version 18 of Emacs. Provided timezone-floor
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;; and timezone-abs functions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 (provide 'timezone)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 (defvar timezone-world-timezones
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 '(("PST" . -800)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ("PDT" . -700)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 ("MST" . -700)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ("MDT" . -600)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ("CST" . -600)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ("CDT" . -500)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ("EST" . -500)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ("EDT" . -400)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 ("AST" . -400) ;by <clamen@CS.CMU.EDU>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 ("NST" . -330) ;by <clamen@CS.CMU.EDU>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 ("UT" . +000)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 ("GMT" . +000)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 ("BST" . +100)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ("MET" . +100)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ("EET" . +200)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 ("JST" . +900)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 ("GMT+1" . +100) ("GMT+2" . +200) ("GMT+3" . +300)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 ("GMT+4" . +400) ("GMT+5" . +500) ("GMT+6" . +600)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 ("GMT+7" . +700) ("GMT+8" . +800) ("GMT+9" . +900)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 ("GMT+10" . +1000) ("GMT+11" . +1100) ("GMT+12" . +1200) ("GMT+13" . +1300)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 ("GMT-1" . -100) ("GMT-2" . -200) ("GMT-3" . -300)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 ("GMT-4" . -400) ("GMT-5" . -500) ("GMT-6" . -600)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 ("GMT-7" . -700) ("GMT-8" . -800) ("GMT-9" . -900)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 ("GMT-10" . -1000) ("GMT-11" . -1100) ("GMT-12" . -1200))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 "*Time differentials of timezone from GMT in +-HHMM form.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 This list is obsolescent, and is present only for backwards compatibility,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 because time zone names are ambiguous in practice.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 Use `current-time-zone' instead.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (defvar timezone-months-assoc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 '(("JAN" . 1)("FEB" . 2)("MAR" . 3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 ("APR" . 4)("MAY" . 5)("JUN" . 6)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 ("JUL" . 7)("AUG" . 8)("SEP" . 9)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 ("OCT" . 10)("NOV" . 11)("DEC" . 12))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 "Alist of first three letters of a month and its numerical representation.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (defun timezone-make-date-arpa-standard (date &optional local timezone)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 "Convert DATE to an arpanet standard date.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 Optional 1st argument LOCAL specifies the default local timezone of the DATE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 if nil, GMT is assumed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 Optional 2nd argument TIMEZONE specifies a time zone to be represented in;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 if nil, the local time zone is assumed."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (let ((new (timezone-fix-time date local timezone)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (timezone-make-arpa-date (aref new 0) (aref new 1) (aref new 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (timezone-make-time-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (aref new 3) (aref new 4) (aref new 5))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (aref new 6))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (defun timezone-make-date-sortable (date &optional local timezone)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 "Convert DATE to a sortable date string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 Optional 1st argument LOCAL specifies the default local timezone of the DATE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 if nil, GMT is assumed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 Optional 2nd argument TIMEZONE specifies a timezone to be represented in;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 if nil, the local time zone is assumed."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (let ((new (timezone-fix-time date local timezone)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (timezone-make-sortable-date (aref new 0) (aref new 1) (aref new 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (timezone-make-time-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (aref new 3) (aref new 4) (aref new 5)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 ;; Parsers and Constructors of Date and Time
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (defun timezone-make-arpa-date (year month day time &optional timezone)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 "Make arpanet standard date string from YEAR, MONTH, DAY, and TIME.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 Optional argument TIMEZONE specifies a time zone."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (let ((zone
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (if (listp timezone)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (let* ((m (timezone-zone-to-minute timezone))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (absm (if (< m 0) (- m) m)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (format "%c%02d%02d"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (if (< m 0) ?- ?+) (/ absm 60) (% absm 60)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 timezone)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (format "%02d %s %04d %s %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 day
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (capitalize (car (rassq month timezone-months-assoc)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 year
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 time
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 zone)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (defun timezone-make-sortable-date (year month day time)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 "Make sortable date string from YEAR, MONTH, DAY, and TIME."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (format "%4d%02d%02d%s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 year month day time))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (defun timezone-make-time-string (hour minute second)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 "Make time string from HOUR, MINUTE, and SECOND."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (format "%02d:%02d:%02d" hour minute second))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131
86
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
132 ;;;###autoload
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
133 (define-error 'invalid-date "Invalid date string")
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
134
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (defun timezone-parse-date (date)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 "Parse DATE and return a vector [YEAR MONTH DAY TIME TIMEZONE].
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 19 is prepended to year if necessary. Timezone may be nil if nothing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 Understands the following styles:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (1) 14 Apr 89 03:20[:12] [GMT]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (2) Fri, 17 Mar 89 4:01[:33] [GMT]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (3) Mon Jan 16 16:12[:37] [GMT] 1989
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (4) 6 May 1992 1641-JST (Wednesday)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (5) 22-AUG-1993 10:59:12.82
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (6) Thu, 11 Apr 16:17:12 91 [MET]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (7) Mon, 6 Jul 16:47:20 T 1992 [MET]"
86
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
146 (condition-case nil
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
147 (progn
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 ;; Get rid of any text properties.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (and (stringp date)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (or (text-properties-at 0 date)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (next-property-change 0 date))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (setq date (copy-sequence date))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 (set-text-properties 0 (length date) nil date))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (let ((date (or date ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (year nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (month nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (day nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (time nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (zone nil)) ;This may be nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 (cond ((string-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 "\\([^ \t,]+\\),[ \t]+\\([0-9]+\\)[ \t]+\\([^ \t,]+\\)[ \t]+\\([0-9]+:[0-9:]+\\)[ \t]+\\(T[ \t]+\\|\\)\\([0-9]+\\)[ \t]*\\'" date)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 ;; Styles: (6) and (7) without timezone
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (setq year 6 month 3 day 2 time 4 zone nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 ((string-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 "\\([^ \t,]+\\),[ \t]+\\([0-9]+\\)[ \t]+\\([^ \t,]+\\)[ \t]+\\([0-9]+:[0-9:]+\\)[ \t]+\\(T[ \t]+\\|\\)\\([0-9]+\\)[ \t]*\\([-+a-zA-Z0-9]+\\)" date)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 ;; Styles: (6) and (7) with timezone and buggy timezone
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (setq year 6 month 3 day 2 time 4 zone 7))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 ((string-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 "\\([0-9]+\\)[ \t]+\\([^ \t,]+\\)[ \t]+\\([0-9]+\\)[ \t]+\\([0-9]+:[0-9:]+\\)[ \t]*\\'" date)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 ;; Styles: (1) and (2) without timezone
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (setq year 3 month 2 day 1 time 4 zone nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 ((string-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 "\\([0-9]+\\)[ \t]+\\([^ \t,]+\\)[ \t]+\\([0-9]+\\)[ \t]+\\([0-9]+:[0-9:]+\\)[ \t]*\\([-+a-zA-Z0-9]+\\)" date)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 ;; Styles: (1) and (2) with timezone and buggy timezone
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (setq year 3 month 2 day 1 time 4 zone 5))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 ((string-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 "\\([^ \t,]+\\)[ \t]+\\([0-9]+\\)[ \t]+\\([0-9]+:[0-9:]+\\)[ \t]+\\([0-9]+\\)" date)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 ;; Styles: (3) without timezone
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (setq year 4 month 1 day 2 time 3 zone nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 ((string-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 "\\([^ \t,]+\\)[ \t]+\\([0-9]+\\)[ \t]+\\([0-9]+:[0-9:]+\\)[ \t]+\\([-+a-zA-Z0-9]+\\)[ \t]+\\([0-9]+\\)" date)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 ;; Styles: (3) with timezone
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 (setq year 5 month 1 day 2 time 3 zone 4))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 ((string-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 "\\([0-9]+\\)[ \t]+\\([^ \t,]+\\)[ \t]+\\([0-9]+\\)[ \t]+\\([0-9]+\\)[ \t]*\\([-+a-zA-Z0-9]+\\)" date)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 ;; Styles: (4) with timezone
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (setq year 3 month 2 day 1 time 4 zone 5))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 ((string-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 "\\([0-9]+\\)-\\([A-Za-z]+\\)-\\([0-9]+\\)[ \t]+\\([0-9]+:[0-9]+:[0-9]+\\)\\.[0-9]+" date)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 ;; Styles: (5) without timezone.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (setq year 3 month 2 day 1 time 4 zone nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (if year
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (setq year
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (substring date (match-beginning year) (match-end year)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 ;; It is now Dec 1992. 8 years before the end of the World.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (if (< (length year) 4)
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 70
diff changeset
199 ;; 2 digit years are bogus, so guess the century
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 70
diff changeset
200 (let ((yr (string-to-int year)))
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 70
diff changeset
201 (when (>= yr 100)
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 70
diff changeset
202 ;; What does a three digit year mean?
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 70
diff changeset
203 (setq yr (- yr 100)))
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 70
diff changeset
204 (setq year (format "%d%02d"
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 70
diff changeset
205 (if (< yr 70)
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 70
diff changeset
206 20
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 70
diff changeset
207 19)
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 70
diff changeset
208 yr))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (let ((string (substring date
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (match-beginning month)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (+ (match-beginning month) 3))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (setq month
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (int-to-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (cdr (assoc (upcase string) timezone-months-assoc)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 (setq day
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (substring date (match-beginning day) (match-end day)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 (setq time
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 (substring date (match-beginning time) (match-end time)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (if zone
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (setq zone
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (substring date (match-beginning zone) (match-end zone))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 ;; Return a vector.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (if year
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (vector year month day time zone)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (vector "0" "0" "0" "0" nil))
86
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
227 )
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
228 )
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
229 (t (signal 'invalid-date (list date))))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
230 )
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (defun timezone-parse-time (time)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 "Parse TIME (HH:MM:SS) and return a vector [hour minute second].
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 Recognize HH:MM:SS, HH:MM, HHMMSS, HHMM."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 (let ((time (or time ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (hour nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (minute nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (second nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (cond ((string-match "\\`\\([0-9]+\\):\\([0-9]+\\):\\([0-9]+\\)\\'" time)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 ;; HH:MM:SS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (setq hour 1 minute 2 second 3))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 ((string-match "\\`\\([0-9]+\\):\\([0-9]+\\)\\'" time)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 ;; HH:MM
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (setq hour 1 minute 2 second nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 ((string-match "\\`\\([0-9][0-9]\\)\\([0-9][0-9]\\)\\([0-9][0-9]\\)\\'" time)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 ;; HHMMSS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (setq hour 1 minute 2 second 3))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 ((string-match "\\`\\([0-9][0-9]\\)\\([0-9][0-9]\\)\\'" time)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 ;; HHMM
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (setq hour 1 minute 2 second nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 ;; Return [hour minute second]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (vector
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (if hour
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (substring time (match-beginning hour) (match-end hour)) "0")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 (if minute
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 (substring time (match-beginning minute) (match-end minute)) "0")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (if second
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (substring time (match-beginning second) (match-end second)) "0"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 ;; Miscellaneous
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 (defun timezone-zone-to-minute (timezone)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 "Translate TIMEZONE to an integer minute offset from GMT.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 TIMEZONE can be a cons cell containing the output of current-time-zone,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 or an integer of the form +-HHMM, or a time zone name."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 ((consp timezone)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 (/ (car timezone) 60))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 (timezone
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (setq timezone
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 (or (cdr (assoc (upcase timezone) timezone-world-timezones))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 ;; +900
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 timezone))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (if (stringp timezone)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (setq timezone (string-to-int timezone)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 ;; Taking account of minute in timezone.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 ;; HHMM -> MM
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (let* ((abszone (timezone-abs timezone))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 (minutes (+ (* 60 (/ abszone 100)) (% abszone 100))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 (if (< timezone 0) (- minutes) minutes))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (t 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 (defun timezone-time-from-absolute (date seconds)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 "Compute the UTC time equivalent to DATE at time SECONDS after midnight.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 Return a list suitable as an argument to current-time-zone,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 or nil if the date cannot be thus represented.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 DATE is the number of days elapsed since the (imaginary)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 Gregorian date Sunday, December 31, 1 BC."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (let* ((current-time-origin 719162)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 ;; (timezone-absolute-from-gregorian 1 1 1970)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 (days (- date current-time-origin))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 (seconds-per-day (float 86400))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 (seconds (+ seconds (* days seconds-per-day)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 (current-time-arithmetic-base (float 65536))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 (hi (timezone-floor (/ seconds current-time-arithmetic-base)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 (hibase (* hi current-time-arithmetic-base))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 (lo (timezone-floor (- seconds hibase))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 (and (< (timezone-abs (- seconds (+ hibase lo))) 2) ;; Check for integer overflow.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 (cons hi lo))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 (defun timezone-time-zone-from-absolute (date seconds)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 "Compute the local time zone for DATE at time SECONDS after midnight.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 Return a list in the same format as current-time-zone's result,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 or nil if the local time zone could not be computed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 DATE is the number of days elapsed since the (imaginary)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 Gregorian date Sunday, December 31, 1 BC."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 (and (fboundp 'current-time-zone)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 (let ((utc-time (timezone-time-from-absolute date seconds)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 (and utc-time
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 (let ((zone (current-time-zone utc-time)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 (and (car zone) zone))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (defun timezone-fix-time (date local timezone)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 "Convert DATE (default timezone LOCAL) to YYYY-MM-DD-HH-MM-SS-ZONE vector.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 If LOCAL is nil, it is assumed to be GMT.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 If TIMEZONE is nil, use the local time zone."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 (let* ((date (timezone-parse-date date))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 (year (string-to-int (aref date 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 (year (cond ((< year 50)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 (+ year 2000))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 ((< year 100)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 (+ year 1900))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 (t year)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 (month (string-to-int (aref date 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 (day (string-to-int (aref date 2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 (time (timezone-parse-time (aref date 3)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 (hour (string-to-int (aref time 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 (minute (string-to-int (aref time 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 (second (string-to-int (aref time 2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 (local (or (aref date 4) local)) ;Use original if defined
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 (timezone
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 (or timezone
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (timezone-time-zone-from-absolute
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 (timezone-absolute-from-gregorian month day year)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 (+ second (* 60 (+ minute (* 60 hour)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 (diff (- (timezone-zone-to-minute timezone)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 (timezone-zone-to-minute local)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 (minute (+ minute diff))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 (hour-fix (timezone-floor minute 60)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 (setq hour (+ hour hour-fix))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 (setq minute (- minute (* 60 hour-fix)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 ;; HOUR may be larger than 24 or smaller than 0.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 (cond ((<= 24 hour) ;24 -> 00
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 (setq hour (- hour 24))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 (setq day (1+ day))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 (if (< (timezone-last-day-of-month month year) day)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 (setq month (1+ month))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 (setq day 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 (if (< 12 month)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 (setq month 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 (setq year (1+ year))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 ((> 0 hour)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 (setq hour (+ hour 24))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 (setq day (1- day))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 (if (> 1 day)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 (setq month (1- month))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 (if (> 1 month)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 (setq month 12)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 (setq year (1- year))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 (setq day (timezone-last-day-of-month month year))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 (vector year month day hour minute second timezone)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 ;; Partly copied from Calendar program by Edward M. Reingold.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 ;; Thanks a lot.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 (defun timezone-last-day-of-month (month year)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 "The last day in MONTH during YEAR."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 (if (and (= month 2) (timezone-leap-year-p year))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 29
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 (aref [31 28 31 30 31 30 31 31 30 31 30 31] (1- month))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 (defun timezone-leap-year-p (year)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 "Returns t if YEAR is a Gregorian leap year."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 (or (and (zerop (% year 4))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 (not (zerop (% year 100))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 (zerop (% year 400))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 (defun timezone-day-number (month day year)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 "Return the day number within the year of the date month/day/year."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 (let ((day-of-year (+ day (* 31 (1- month)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 (if (> month 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 (setq day-of-year (- day-of-year (/ (+ 23 (* 4 month)) 10)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 (if (timezone-leap-year-p year)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 (setq day-of-year (1+ day-of-year)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 day-of-year))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 (defun timezone-absolute-from-gregorian (month day year)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 "The number of days between the Gregorian date 12/31/1 BC and month/day/year.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 The Gregorian date Sunday, December 31, 1 BC is imaginary."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 (+ (timezone-day-number month day year);; Days this year
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 (* 365 (1- year));; + Days in prior years
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 (/ (1- year) 4);; + Julian leap years
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 (- (/ (1- year) 100));; - century years
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 (/ (1- year) 400)));; + Gregorian leap years
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 (defun timezone-abs (n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 (if (fboundp 'abs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 (abs n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 (if (< n 0) (- n) n)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 (defun timezone-floor (n &optional divisor)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 (if (fboundp 'floor)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 (floor n divisor)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 (if (null divisor)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 (setq divisor 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 (if (< n 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 (- (/ (- divisor 1 n) divisor))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 (/ n divisor))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 ;;; timezone.el ends here