]> code.delx.au - gnu-emacs/blobdiff - lisp/timezone.el
(rmail-forward): Delete trailing blank lines.
[gnu-emacs] / lisp / timezone.el
index a461f734bfab6db029b7bb753ec96d1573873b3f..8802a65411b26ee5009bf72580249d68bc7530ed 100644 (file)
@@ -1,9 +1,10 @@
-;;; Timezone package for GNU Emacs
+;;; timezone.el --- time zone package for GNU Emacs
 
 ;; Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
 
-;;; Author: Masanobu Umeda
-;;; Maintainer: umerin@mse.kyutech.ac.jp
+;; Author: Masanobu Umeda
+;; Maintainer: umerin@mse.kyutech.ac.jp
+;; Keywords: news
 
 ;; This file is part of GNU Emacs.
 
@@ -36,6 +37,7 @@
     ("EDT" .  -400)
     ("AST" .  -400)                    ;by <clamen@CS.CMU.EDU>
     ("NST" .  -330)                    ;by <clamen@CS.CMU.EDU>
+    ("UT"  .  +000)
     ("GMT" .  +000)
     ("BST" .  +100)
     ("MET" .  +100)
@@ -118,13 +120,22 @@ Optional argument TIMEZONE specifies a time zone."
   (format "%02d:%02d:%02d" hour minute second))
 
 (defun timezone-parse-date (date)
-  "Parse DATE and return a vector [year month day time timezone].
-19 is prepended to year if necessary. Timezone may be NIL if nothing.
-Understand the following styles:
+  "Parse DATE and return a vector [YEAR MONTH DAY TIME TIMEZONE].
+19 is prepended to year if necessary.  Timezone may be nil if nothing.
+Understands the following styles:
  (1) 14 Apr 89 03:20[:12] [GMT]
  (2) Fri, 17 Mar 89 4:01[:33] [GMT]
  (3) Mon Jan 16 16:12[:37] [GMT] 1989
- (4) 6 May 1992 1641-JST (Wednesday)"
+ (4) 6 May 1992 1641-JST (Wednesday)
+ (5) 22-AUG-1993 10:59:12.82
+ (6) Thu, 11 Apr 16:17:12 91 [MET]
+ (7) Mon, 6  Jul 16:47:20 T 1992 [MET]"
+  ;; Get rid of any text properties.
+  (and (stringp date)
+       (or (text-properties-at 0 date)
+          (next-property-change 0 date))
+       (setq date (copy-sequence date))
+       (set-text-properties 0 (length date) nil date))
   (let ((date (or date ""))
        (year nil)
        (month nil)
@@ -132,6 +143,14 @@ Understand the following styles:
        (time nil)
        (zone nil))                     ;This may be nil.
     (cond ((string-match
+           "\\([^ \t,]+\\),[ \t]+\\([0-9]+\\)[ \t]+\\([^ \t,]+\\)[ \t]+\\([0-9]+:[0-9:]+\\)[ \t]+\\(T[ \t]+\\|\\)\\([0-9]+\\)[ \t]*\\'" date)
+          ;; Styles: (6) and (7) without timezone
+          (setq year 6 month 3 day 2 time 4 zone nil))
+         ((string-match
+           "\\([^ \t,]+\\),[ \t]+\\([0-9]+\\)[ \t]+\\([^ \t,]+\\)[ \t]+\\([0-9]+:[0-9:]+\\)[ \t]+\\(T[ \t]+\\|\\)\\([0-9]+\\)[ \t]*\\([-+a-zA-Z0-9]+\\)" date)
+          ;; Styles: (6) and (7) with timezone and buggy timezone
+          (setq year 6 month 3 day 2 time 4 zone 7))
+         ((string-match
            "\\([0-9]+\\)[ \t]+\\([^ \t,]+\\)[ \t]+\\([0-9]+\\)[ \t]+\\([0-9]+:[0-9:]+\\)[ \t]*\\'" date)
           ;; Styles: (1) and (2) without timezone
           (setq year 3 month 2 day 1 time 4 zone nil))
@@ -145,12 +164,16 @@ Understand the following styles:
           (setq year 4 month 1 day 2 time 3 zone nil))
          ((string-match
            "\\([^ \t,]+\\)[ \t]+\\([0-9]+\\)[ \t]+\\([0-9]+:[0-9:]+\\)[ \t]+\\([-+a-zA-Z0-9]+\\)[ \t]+\\([0-9]+\\)" date)
-          ;; Styles: (3) with timezoen
+          ;; Styles: (3) with timezone
           (setq year 5 month 1 day 2 time 3 zone 4))
          ((string-match
            "\\([0-9]+\\)[ \t]+\\([^ \t,]+\\)[ \t]+\\([0-9]+\\)[ \t]+\\([0-9]+\\)[ \t]*\\([-+a-zA-Z0-9]+\\)" date)
           ;; Styles: (4) with timezone
           (setq year 3 month 2 day 1 time 4 zone 5))
+         ((string-match
+           "\\([0-9]+\\)-\\([A-Za-z]+\\)-\\([0-9]+\\)[ \t]+\\([0-9]+:[0-9]+:[0-9]+\\)\\.[0-9]+" date)
+          ;; Styles: (5) without timezone.
+          (setq year 3 month 2 day 1 time 4 zone nil))
          )
     (if year
        (progn
@@ -159,17 +182,13 @@ Understand the following styles:
          ;; It is now Dec 1992.  8 years before the end of the World.
          (if (< (length year) 4)
              (setq year (concat "19" (substring year -2 nil))))
-         (setq month
-               (int-to-string
-                (cdr
-                 (assoc
-                  (upcase
-                   ;; Don't use `match-end' in order to take 3
-                   ;; letters from the beginning.
-                   (substring date
-                              (match-beginning month)
-                              (+ (match-beginning month) 3)))
-                  timezone-months-assoc))))
+         (let ((string (substring date
+                                  (match-beginning month)
+                                  (+ (match-beginning month) 3))))
+           (setq month
+                 (int-to-string
+                  (cdr (assoc (upcase string) timezone-months-assoc)))))
+
          (setq day
                (substring date (match-beginning day) (match-end day)))
          (setq time
@@ -274,7 +293,11 @@ If LOCAL is nil, it is assumed to be GMT.
 If TIMEZONE is nil, use the local time zone."
   (let* ((date   (timezone-parse-date date))
         (year   (string-to-int (aref date 0)))
-        (year   (if (< year 100) (+ year 1900) year))
+        (year   (cond ((< year 50)
+                       (+ year 2000))
+                      ((< year 100)
+                       (+ year 1900))
+                      (t year)))
         (month  (string-to-int (aref date 1)))
         (day    (string-to-int (aref date 2)))
         (time   (timezone-parse-time (aref date 3)))