Mercurial > hg > xemacs-beta
comparison lisp/utils/timezone.el @ 16:0293115a14e9 r19-15b91
Import from CVS: tag r19-15b91
author | cvs |
---|---|
date | Mon, 13 Aug 2007 08:49:20 +0200 |
parents | 376386a54a3c |
children | 131b0175ea99 |
comparison
equal
deleted
inserted
replaced
15:ad457d5f7d04 | 16:0293115a14e9 |
---|---|
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of | 17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
19 ;; General Public License for more details. | 19 ;; General Public License for more details. |
20 | 20 |
21 ;; You should have received a copy of the GNU General Public License | 21 ;; You should have received a copy of the GNU General Public License |
22 ;; along with XEmacs; see the file COPYING. If not, write to the Free | 22 ;; along with XEmacs; see the file COPYING. If not, write to the |
23 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | 23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
24 ;; Boston, MA 02111-1307, USA. | |
24 | 25 |
25 ;;; Synched up with: FSF 19.30. | 26 ;;; Synched up with: FSF 19.30. |
26 | 27 |
27 ;; Modified 1 February 1994 by Kyle Jones to fix broken | 28 ;; Modified 1 February 1994 by Kyle Jones to fix broken |
28 ;; timezone-floor function. | 29 ;; timezone-floor function. |
126 | 127 |
127 (defun timezone-make-time-string (hour minute second) | 128 (defun timezone-make-time-string (hour minute second) |
128 "Make time string from HOUR, MINUTE, and SECOND." | 129 "Make time string from HOUR, MINUTE, and SECOND." |
129 (format "%02d:%02d:%02d" hour minute second)) | 130 (format "%02d:%02d:%02d" hour minute second)) |
130 | 131 |
132 ;;;###autoload | |
133 (define-error 'invalid-date "Invalid date string") | |
134 | |
131 (defun timezone-parse-date (date) | 135 (defun timezone-parse-date (date) |
132 "Parse DATE and return a vector [YEAR MONTH DAY TIME TIMEZONE]. | 136 "Parse DATE and return a vector [YEAR MONTH DAY TIME TIMEZONE]. |
133 19 is prepended to year if necessary. Timezone may be nil if nothing. | 137 19 is prepended to year if necessary. Timezone may be nil if nothing. |
134 Understands the following styles: | 138 Understands the following styles: |
135 (1) 14 Apr 89 03:20[:12] [GMT] | 139 (1) 14 Apr 89 03:20[:12] [GMT] |
137 (3) Mon Jan 16 16:12[:37] [GMT] 1989 | 141 (3) Mon Jan 16 16:12[:37] [GMT] 1989 |
138 (4) 6 May 1992 1641-JST (Wednesday) | 142 (4) 6 May 1992 1641-JST (Wednesday) |
139 (5) 22-AUG-1993 10:59:12.82 | 143 (5) 22-AUG-1993 10:59:12.82 |
140 (6) Thu, 11 Apr 16:17:12 91 [MET] | 144 (6) Thu, 11 Apr 16:17:12 91 [MET] |
141 (7) Mon, 6 Jul 16:47:20 T 1992 [MET]" | 145 (7) Mon, 6 Jul 16:47:20 T 1992 [MET]" |
146 (condition-case nil | |
147 (progn | |
142 ;; Get rid of any text properties. | 148 ;; Get rid of any text properties. |
143 (and (stringp date) | 149 (and (stringp date) |
144 (or (text-properties-at 0 date) | 150 (or (text-properties-at 0 date) |
145 (next-property-change 0 date)) | 151 (next-property-change 0 date)) |
146 (setq date (copy-sequence date)) | 152 (setq date (copy-sequence date)) |
188 (progn | 194 (progn |
189 (setq year | 195 (setq year |
190 (substring date (match-beginning year) (match-end year))) | 196 (substring date (match-beginning year) (match-end year))) |
191 ;; It is now Dec 1992. 8 years before the end of the World. | 197 ;; It is now Dec 1992. 8 years before the end of the World. |
192 (if (< (length year) 4) | 198 (if (< (length year) 4) |
193 (setq year (concat "19" (substring year -2 nil)))) | 199 ;; 2 digit years are bogus, so guess the century |
200 (let ((yr (string-to-int year))) | |
201 (when (>= yr 100) | |
202 ;; What does a three digit year mean? | |
203 (setq yr (- yr 100))) | |
204 (setq year (format "%d%02d" | |
205 (if (< yr 70) | |
206 20 | |
207 19) | |
208 yr)))) | |
194 (let ((string (substring date | 209 (let ((string (substring date |
195 (match-beginning month) | 210 (match-beginning month) |
196 (+ (match-beginning month) 3)))) | 211 (+ (match-beginning month) 3)))) |
197 (setq month | 212 (setq month |
198 (int-to-string | 213 (int-to-string |
207 (substring date (match-beginning zone) (match-end zone)))) | 222 (substring date (match-beginning zone) (match-end zone)))) |
208 ;; Return a vector. | 223 ;; Return a vector. |
209 (if year | 224 (if year |
210 (vector year month day time zone) | 225 (vector year month day time zone) |
211 (vector "0" "0" "0" "0" nil)) | 226 (vector "0" "0" "0" "0" nil)) |
212 )) | 227 ) |
228 ) | |
229 (t (signal 'invalid-date (list date)))) | |
230 ) | |
213 | 231 |
214 (defun timezone-parse-time (time) | 232 (defun timezone-parse-time (time) |
215 "Parse TIME (HH:MM:SS) and return a vector [hour minute second]. | 233 "Parse TIME (HH:MM:SS) and return a vector [hour minute second]. |
216 Recognize HH:MM:SS, HH:MM, HHMMSS, HHMM." | 234 Recognize HH:MM:SS, HH:MM, HHMMSS, HHMM." |
217 (let ((time (or time "")) | 235 (let ((time (or time "")) |