annotate lisp/utils/timezone.el @ 70:131b0175ea99 r20-0b30

Import from CVS: tag r20-0b30
author cvs
date Mon, 13 Aug 2007 09:02:59 +0200
parents 0293115a14e9
children 6a378aca36af
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
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (defun timezone-parse-date (date)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 "Parse DATE and return a vector [YEAR MONTH DAY TIME TIMEZONE].
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 19 is prepended to year if necessary. Timezone may be nil if nothing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 Understands the following styles:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (1) 14 Apr 89 03:20[:12] [GMT]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (2) Fri, 17 Mar 89 4:01[:33] [GMT]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (3) Mon Jan 16 16:12[:37] [GMT] 1989
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (4) 6 May 1992 1641-JST (Wednesday)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (5) 22-AUG-1993 10:59:12.82
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (6) Thu, 11 Apr 16:17:12 91 [MET]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (7) Mon, 6 Jul 16:47:20 T 1992 [MET]"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 ;; Get rid of any text properties.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (and (stringp date)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (or (text-properties-at 0 date)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (next-property-change 0 date))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (setq date (copy-sequence date))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (set-text-properties 0 (length date) nil date))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (let ((date (or date ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (year nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (month nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (day nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 (time nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (zone nil)) ;This may be nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (cond ((string-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 "\\([^ \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
157 ;; Styles: (6) and (7) without timezone
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (setq year 6 month 3 day 2 time 4 zone nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 ((string-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 "\\([^ \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
161 ;; Styles: (6) and (7) with timezone and buggy timezone
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (setq year 6 month 3 day 2 time 4 zone 7))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 ((string-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 "\\([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
165 ;; Styles: (1) and (2) without timezone
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (setq year 3 month 2 day 1 time 4 zone nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 ((string-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 "\\([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
169 ;; Styles: (1) and (2) with timezone and buggy timezone
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (setq year 3 month 2 day 1 time 4 zone 5))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 ((string-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 "\\([^ \t,]+\\)[ \t]+\\([0-9]+\\)[ \t]+\\([0-9]+:[0-9:]+\\)[ \t]+\\([0-9]+\\)" date)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 ;; Styles: (3) without timezone
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (setq year 4 month 1 day 2 time 3 zone nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 ((string-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 "\\([^ \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
177 ;; Styles: (3) with timezone
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (setq year 5 month 1 day 2 time 3 zone 4))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 ((string-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 "\\([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
181 ;; Styles: (4) with timezone
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (setq year 3 month 2 day 1 time 4 zone 5))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 ((string-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 "\\([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
185 ;; Styles: (5) without timezone.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (setq year 3 month 2 day 1 time 4 zone nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (if year
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (setq year
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (substring date (match-beginning year) (match-end year)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 ;; It is now Dec 1992. 8 years before the end of the World.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (if (< (length year) 4)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
194 (setq year (concat "19" (substring year -2 nil))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (let ((string (substring date
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (match-beginning month)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (+ (match-beginning month) 3))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (setq month
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (int-to-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (cdr (assoc (upcase string) timezone-months-assoc)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (setq day
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (substring date (match-beginning day) (match-end day)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (setq time
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (substring date (match-beginning time) (match-end time)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (if zone
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (setq zone
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (substring date (match-beginning zone) (match-end zone))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 ;; Return a vector.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (if year
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (vector year month day time zone)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (vector "0" "0" "0" "0" nil))
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
213 ))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 (defun timezone-parse-time (time)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 "Parse TIME (HH:MM:SS) and return a vector [hour minute second].
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 Recognize HH:MM:SS, HH:MM, HHMMSS, HHMM."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 (let ((time (or time ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 (hour nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (minute nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (second nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (cond ((string-match "\\`\\([0-9]+\\):\\([0-9]+\\):\\([0-9]+\\)\\'" time)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 ;; HH:MM:SS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (setq hour 1 minute 2 second 3))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 ((string-match "\\`\\([0-9]+\\):\\([0-9]+\\)\\'" time)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 ;; HH:MM
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (setq hour 1 minute 2 second nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 ((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
229 ;; HHMMSS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (setq hour 1 minute 2 second 3))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 ((string-match "\\`\\([0-9][0-9]\\)\\([0-9][0-9]\\)\\'" time)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 ;; HHMM
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (setq hour 1 minute 2 second nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 ;; Return [hour minute second]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (vector
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (if hour
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (substring time (match-beginning hour) (match-end hour)) "0")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (if minute
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (substring time (match-beginning minute) (match-end minute)) "0")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (if second
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (substring time (match-beginning second) (match-end second)) "0"))
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
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 ;; Miscellaneous
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (defun timezone-zone-to-minute (timezone)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 "Translate TIMEZONE to an integer minute offset from GMT.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 TIMEZONE can be a cons cell containing the output of current-time-zone,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 or an integer of the form +-HHMM, or a time zone name."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 ((consp timezone)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (/ (car timezone) 60))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (timezone
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 (setq timezone
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (or (cdr (assoc (upcase timezone) timezone-world-timezones))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 ;; +900
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 timezone))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (if (stringp timezone)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (setq timezone (string-to-int timezone)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 ;; Taking account of minute in timezone.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 ;; HHMM -> MM
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 (let* ((abszone (timezone-abs timezone))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (minutes (+ (* 60 (/ abszone 100)) (% abszone 100))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (if (< timezone 0) (- minutes) minutes))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (t 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (defun timezone-time-from-absolute (date seconds)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 "Compute the UTC time equivalent to DATE at time SECONDS after midnight.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 Return a list suitable as an argument to current-time-zone,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 or nil if the date cannot be thus represented.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 DATE is the number of days elapsed since the (imaginary)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 Gregorian date Sunday, December 31, 1 BC."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (let* ((current-time-origin 719162)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 ;; (timezone-absolute-from-gregorian 1 1 1970)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (days (- date current-time-origin))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (seconds-per-day (float 86400))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 (seconds (+ seconds (* days seconds-per-day)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 (current-time-arithmetic-base (float 65536))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (hi (timezone-floor (/ seconds current-time-arithmetic-base)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 (hibase (* hi current-time-arithmetic-base))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 (lo (timezone-floor (- seconds hibase))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (and (< (timezone-abs (- seconds (+ hibase lo))) 2) ;; Check for integer overflow.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (cons hi lo))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (defun timezone-time-zone-from-absolute (date seconds)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 "Compute the local time zone for DATE at time SECONDS after midnight.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 Return a list in the same format as current-time-zone's result,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 or nil if the local time zone could not be computed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 DATE is the number of days elapsed since the (imaginary)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 Gregorian date Sunday, December 31, 1 BC."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 (and (fboundp 'current-time-zone)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 (let ((utc-time (timezone-time-from-absolute date seconds)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 (and utc-time
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 (let ((zone (current-time-zone utc-time)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 (and (car zone) zone))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 (defun timezone-fix-time (date local timezone)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 "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
302 If LOCAL is nil, it is assumed to be GMT.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 If TIMEZONE is nil, use the local time zone."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 (let* ((date (timezone-parse-date date))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 (year (string-to-int (aref date 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 (year (cond ((< year 50)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 (+ year 2000))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 ((< year 100)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 (+ year 1900))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 (t year)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 (month (string-to-int (aref date 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 (day (string-to-int (aref date 2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 (time (timezone-parse-time (aref date 3)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 (hour (string-to-int (aref time 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 (minute (string-to-int (aref time 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 (second (string-to-int (aref time 2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (local (or (aref date 4) local)) ;Use original if defined
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 (timezone
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 (or timezone
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 (timezone-time-zone-from-absolute
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 (timezone-absolute-from-gregorian month day year)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 (+ second (* 60 (+ minute (* 60 hour)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 (diff (- (timezone-zone-to-minute timezone)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 (timezone-zone-to-minute local)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 (minute (+ minute diff))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 (hour-fix (timezone-floor minute 60)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 (setq hour (+ hour hour-fix))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 (setq minute (- minute (* 60 hour-fix)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 ;; HOUR may be larger than 24 or smaller than 0.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 (cond ((<= 24 hour) ;24 -> 00
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 (setq hour (- hour 24))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 (setq day (1+ day))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 (if (< (timezone-last-day-of-month month year) day)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 (setq month (1+ month))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 (setq day 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (if (< 12 month)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 (setq month 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 (setq year (1+ year))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 ((> 0 hour)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 (setq hour (+ hour 24))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 (setq day (1- day))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 (if (> 1 day)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 (setq month (1- month))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 (if (> 1 month)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 (setq month 12)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 (setq year (1- year))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 (setq day (timezone-last-day-of-month month year))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 (vector year month day hour minute second timezone)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 ;; Partly copied from Calendar program by Edward M. Reingold.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 ;; Thanks a lot.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 (defun timezone-last-day-of-month (month year)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 "The last day in MONTH during YEAR."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 (if (and (= month 2) (timezone-leap-year-p year))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 29
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 (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
367
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 (defun timezone-leap-year-p (year)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 "Returns t if YEAR is a Gregorian leap year."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 (or (and (zerop (% year 4))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 (not (zerop (% year 100))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 (zerop (% year 400))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 (defun timezone-day-number (month day year)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 "Return the day number within the year of the date month/day/year."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 (let ((day-of-year (+ day (* 31 (1- month)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 (if (> month 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 (setq day-of-year (- day-of-year (/ (+ 23 (* 4 month)) 10)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 (if (timezone-leap-year-p year)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 (setq day-of-year (1+ day-of-year)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 day-of-year))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 (defun timezone-absolute-from-gregorian (month day year)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 "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
386 The Gregorian date Sunday, December 31, 1 BC is imaginary."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 (+ (timezone-day-number month day year);; Days this year
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 (* 365 (1- year));; + Days in prior years
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 (/ (1- year) 4);; + Julian leap years
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 (- (/ (1- year) 100));; - century years
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 (/ (1- year) 400)));; + Gregorian leap years
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 (defun timezone-abs (n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 (if (fboundp 'abs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 (abs n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 (if (< n 0) (- n) n)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 (defun timezone-floor (n &optional divisor)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 (if (fboundp 'floor)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 (floor n divisor)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 (if (null divisor)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 (setq divisor 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 (if (< n 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 (- (/ (- divisor 1 n) divisor))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 (/ n divisor))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 ;;; timezone.el ends here