annotate lisp/utils/timezone.el @ 9:6f2bbbbbe05a

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