home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / gnu / emacs / gnus / 1510 < prev    next >
Encoding:
Text File  |  1993-01-25  |  10.4 KB  |  310 lines

  1. Newsgroups: gnu.emacs.gnus
  2. Path: sparky!uunet!stanford.edu!EE.Stanford.EDU!sierra!mcgrant
  3. From: mcgrant@rascals.stanford.edu (Michael C. Grant)
  4. Subject: Re: Wrong type argument error
  5. In-Reply-To: todd@kastle.com's message of Mon, 25 Jan 1993 09:20:59 GMT
  6. Message-ID: <MCGRANT.93Jan25110901@rascals.stanford.edu>
  7. Sender: usenet@EE.Stanford.EDU (Usenet)
  8. Organization: Information Systems Laboratory, Stanford University
  9. References: <TODD.93Jan25092059@todd.kastle.com>
  10. Distribution: gnu
  11. Date: 25 Jan 93 11:09:01
  12. Lines: 296
  13.  
  14. In article <TODD.93Jan25092059@todd.kastle.com> 
  15. todd@kastle.com (Todd A. Scalzott) writes:
  16.  
  17.    When attempting to enter a new newsgroup with gnus, I get the following
  18.    error:
  19.  
  20.        Wrong type argument:  integerp, nil
  21.  
  22.    Using the latest gnus and nntp.  
  23.  
  24.    Anyone else?
  25.  
  26. Yep. timezone.el can't handle certain date formats. I fixed it in my
  27. version and sent it to the gnus bug lists, and apparently some sort of
  28. fix will be in the most recent updates if it's not already in this new
  29. 3.14.3 beta release.
  30.  
  31. Here's a new timezone.el if you want to fix it now. Make sure to crop my
  32. signature off of the bottom!
  33.  
  34. Michael C. Grant
  35. mcgrant@isl.stanford.edu
  36.  
  37. ;;; Timezone package for GNU Emacs
  38. ;; Copyright(C) 1990 Masanobu UMEDA (umerin@mse.kyutech.ac.jp)
  39. ;; $Header: timezone.el,v 1.1 90/12/11 11:50:10 umerin Locked $
  40.  
  41. ;; This file is part of GNU Emacs.
  42.  
  43. ;; GNU Emacs is distributed in the hope that it will be useful,
  44. ;; but WITHOUT ANY WARRANTY.  No author or distributor
  45. ;; accepts responsibility to anyone for the consequences of using it
  46. ;; or for whether it serves any particular purpose or works at all,
  47. ;; unless he says so in writing.  Refer to the GNU Emacs General Public
  48. ;; License for full details.
  49.  
  50. ;; Everyone is granted permission to copy, modify and redistribute
  51. ;; GNU Emacs, but only under the conditions described in the
  52. ;; GNU Emacs General Public License.   A copy of this license is
  53. ;; supposed to have been given to you along with GNU Emacs so you
  54. ;; can know your rights and responsibilities.  It should be in a
  55. ;; file named COPYING.  Among other things, the copyright notice
  56. ;; and this notice must be preserved on all copies.
  57.  
  58. (provide 'timezone)
  59.  
  60. (defvar timezone-world-timezones
  61.   '(("PST" .  -800)
  62.     ("PDT" .  -700)
  63.     ("MST" .  -700)
  64.     ("MDT" .  -600)
  65.     ("CST" .  -600)
  66.     ("CDT" .  -500)
  67.     ("EST" .  -500)
  68.     ("EDT" .  -400)
  69.     ("GMT" .  +000)
  70.     ("BST" .  +100)
  71.     ("MET" .  +100)
  72.     ("EET" .  +200)
  73.     ("JST" .  +900)
  74.     ("GMT+1"  .  +100) ("GMT+2"  .  +200) ("GMT+3"  .  +300)
  75.     ("GMT+4"  .  +400) ("GMT+5"  .  +500) ("GMT+6"  .  +600)
  76.     ("GMT+7"  .  +700) ("GMT+8"  .  +800) ("GMT+9"  .  +900)
  77.     ("GMT+10" . +1000) ("GMT+11" . +1100) ("GMT+12" . +1200) ("GMT+13" . +1300)
  78.     ("GMT-1"  .  -100) ("GMT-2"  .  -200) ("GMT-3"  .  -300)
  79.     ("GMT-4"  .  -400) ("GMT-5"  .  -500) ("GMT-6"  .  -600)
  80.     ("GMT-7"  .  -700) ("GMT-8"  .  -800) ("GMT-9"  .  -900)
  81.     ("GMT-10" . -1000) ("GMT-11" . -1100) ("GMT-12" . -1200))
  82.   "*Time differentials of timezone from GMT in hour.")
  83.  
  84. (defvar timezone-months-assoc
  85.   '(("JAN" .  1)("FEB" .  2)("MAR" .  3)
  86.     ("APR" .  4)("MAY" .  5)("JUN" .  6)
  87.     ("JUL" .  7)("AUG" .  8)("SEP" .  9)
  88.     ("OCT" . 10)("NOV" . 11)("DEC" . 12))
  89.   "Alist of first three letters of a month and its numerical representation.")
  90.  
  91. (defun timezone-make-date-arpa-standard (date &optional local timezone)
  92.   "Convert DATE to an arpanet standard date.
  93. Optional 1st argumetn LOCAL specifies the default local timezone of the DATE.
  94. Optional 2nd argument TIMEZONE specifies a timezone to be represented in."
  95.   (let* ((date   (timezone-parse-date date))
  96.      (year   (string-to-int (aref date 0)))
  97.      (month  (string-to-int (aref date 1)))
  98.      (day    (string-to-int (aref date 2)))
  99.      (time   (timezone-parse-time (aref date 3)))
  100.      (hour   (string-to-int (aref time 0)))
  101.      (minute (string-to-int (aref time 1)))
  102.      (second (string-to-int (aref time 2)))
  103.      (local  (or (aref date 4) local)) ;Use original if defined
  104.      (timezone (or timezone local))
  105.      (diff   (- (timezone-zone-to-hour timezone)
  106.             (timezone-zone-to-hour local)))
  107.      (new    (timezone-fix-time year month day
  108.                     (+ hour diff) minute second)))
  109.     (timezone-make-arpa-date (aref new 0) (aref new 1) (aref new 2)
  110.                  (timezone-make-time-string
  111.                   (aref new 3) (aref new 4) (aref new 5))
  112.                  timezone)
  113.     ))
  114.  
  115. (defun timezone-make-date-sortable (date &optional local timezone)
  116.   "Convert DATE to a sortable date string.
  117. Optional 1st argumetn LOCAL specifies the default local timezone of the DATE.
  118. Optional 2nd argument TIMEZONE specifies a timezone to be represented in."
  119.   (let* ((date   (timezone-parse-date date))
  120.      (year   (string-to-int (aref date 0)))
  121.      (month  (string-to-int (aref date 1)))
  122.      (day    (string-to-int (aref date 2)))
  123.      (time   (timezone-parse-time (aref date 3)))
  124.      (hour   (string-to-int (aref time 0)))
  125.      (minute (string-to-int (aref time 1)))
  126.      (second (string-to-int (aref time 2)))
  127.      (local  (or (aref date 4) local)) ;Use original if defined
  128.      (timezone (or timezone local))
  129.      (diff   (- (timezone-zone-to-hour timezone)
  130.             (timezone-zone-to-hour local)))
  131.      (new    (timezone-fix-time year month day
  132.                     (+ hour diff) minute second)))
  133.     (timezone-make-sortable-date (aref new 0) (aref new 1) (aref new 2)
  134.                  (timezone-make-time-string
  135.                   (aref new 3) (aref new 4) (aref new 5)))
  136.     ))
  137.  
  138.  
  139. ;;
  140. ;; Parsers and Constructors of Date and Time
  141. ;;
  142.  
  143. (defun timezone-make-arpa-date (year month day time &optional timezone)
  144.   "Make arpanet standard date string from YEAR, MONTH, DAY, and TIME.
  145. Optional argument TIMEZONE specifies a time zone."
  146.   (format "%02d %s %02d %s%s"
  147.       day
  148.       (capitalize (car (rassq month timezone-months-assoc)))
  149.       (- year (* (/ year 100) 100))    ;1990 -> 90
  150.       time
  151.       (if timezone (concat " " timezone) "")
  152.       ))
  153.  
  154. (defun timezone-make-sortable-date (year month day time)
  155.   "Make sortable date string from YEAR, MONTH, DAY, and TIME."
  156.   (format "%02d%02d%02d%s"
  157.       (- year (* (/ year 100) 100))    ;1990 -> 90
  158.       month day time))
  159.  
  160. (defun timezone-make-time-string (hour minute second)
  161.   "Make time string from HOUR, MINUTE, and SECOND."
  162.   (format "%02d:%02d:%02d" hour minute second))
  163.  
  164. (defun timezone-parse-date (date)
  165.   "Parse DATE and return a vector [year month day time timezone].
  166. 19 is prepended to year if necessary. Timezone may be NIL if nothing.
  167. Understand the following styles:
  168.  (1) 14 Apr 89 03:20[:12] [GMT]
  169.  (2) Fri, 17 Mar 89 4:01[:33] [GMT]
  170.  (3) Mon Jan 16 16:12[:37] [GMT] 1989"
  171.   (let ((date (or date ""))
  172.     (year nil)
  173.     (month nil)
  174.     (day nil)
  175.     (time nil)
  176.     (zone nil))            ;This may be nil.
  177.     (cond ((string-match
  178. "\\([0-9]+\\) \\([^ ,]+\\) \\([0-9]+\\) \\([0-9]+:[0-9:]+\\)[ ]*\\'" date)
  179.        ;; Styles: (1) and (2) without timezone
  180.        (setq year 3 month 2 day 1 time 4 zone nil))
  181.       ((string-match
  182. "\\([0-9]+\\) \\([^ ,]+\\) \\([0-9]+\\) \\([0-9]+:[0-9:]+\\)[ ]*\\([-+a-zA-Z0-9]+\\)" date)
  183.        ;; Styles: (1) and (2) with timezone and buggy timezone
  184.        (setq year 3 month 2 day 1 time 4 zone 5))
  185.       ((string-match
  186. "\\([^ ,]+\\) +\\([0-9]+\\) \\([0-9]+:[0-9:]+\\) \\([0-9]+\\)" date)
  187.        ;; Styles: (3) without timezone
  188.        (setq year 4 month 1 day 2 time 3 zone nil))
  189.       ((string-match
  190. "\\([^ ,]+\\) +\\([0-9]+\\) \\([0-9]+:[0-9:]+\\) \\([-+a-zA-Z0-9]+\\) \\([0-9]+\\)" date)
  191.        ;; Styles: (3) with timezoen
  192.        (setq year 5 month 1 day 2 time 3 zone 4)))
  193.     (if year
  194.     (progn
  195.       (setq year
  196.         (substring date (match-beginning year) (match-end year)))
  197.       ;; I don't care about 2000 year.  There must come out a
  198.       ;; better program by then.
  199.       (if (> (length year) 2)
  200.           (setq year (substring year -2 nil))) ;Use last two letters
  201.       (setq month
  202.         (int-to-string
  203.          (cdr
  204.           (assoc
  205.            (upcase
  206.                     (substring 
  207.                      (substring date
  208.                                 (match-beginning month) (match-end month))
  209.                      0 3)) 
  210.            timezone-months-assoc))))
  211.       (setq day
  212.         (substring date (match-beginning day) (match-end day)))
  213.       (setq time
  214.         (substring date (match-beginning time) (match-end time)))))
  215.     (if zone
  216.     (setq zone
  217.           (substring date (match-beginning zone) (match-end zone))))
  218.     ;; Return a vector.
  219.     (if year
  220.     (vector year month day time zone)
  221.       (vector "0" "0" "0" "0" nil))
  222.     ))
  223.  
  224. (defun timezone-parse-time (time)
  225.   "Parse TIME (HH:MM:SS) and return a vector [hour minute second]."
  226.   (let ((time (or time ""))
  227.     (hour nil)
  228.     (minute nil)
  229.     (second nil))
  230.     (cond ((string-match "\\`\\([0-9]+\\):\\([0-9]+\\):\\([0-9]+\\)\\'" time)
  231.        ;; HH:MM:SS
  232.        (setq hour 1 minute 2 second 3))
  233.       ((string-match "\\`\\([0-9]+\\):\\([0-9]+\\)\\'" time)
  234.        ;; HH:MM
  235.        (setq hour 1 minute 2 second nil)))
  236.     ;; Return [hour minute second]
  237.     (vector
  238.      (if hour
  239.      (substring time (match-beginning hour) (match-end hour)) "0")
  240.      (if minute
  241.      (substring time (match-beginning minute) (match-end minute)) "0")
  242.      (if second
  243.      (substring time (match-beginning second) (match-end second)) "0"))
  244.     ))
  245.  
  246.  
  247. ;; Miscellaneous
  248.  
  249. (defun timezone-zone-to-hour (timezone)
  250.   "Translate TIMEZONE (in zone name or integer) to integer hour."
  251.   (if timezone
  252.       (progn
  253.     (setq timezone
  254.           (or (cdr (assoc (upcase timezone) timezone-world-timezones))
  255.           ;; +900
  256.           timezone))
  257.     (if (stringp timezone)
  258.         (setq timezone (string-to-int timezone)))
  259.     (/ timezone 100))
  260.     0))
  261.  
  262. (defun timezone-fix-time (year month day hour minute second)
  263.   "Fix date and time."
  264.   (cond ((<= 24 hour)            ;24 -> 00
  265.      (setq hour (- hour 24))
  266.      (setq day  (1+ day))
  267.      (if (< (timezone-last-day-of-month month year) day)
  268.          (progn
  269.            (setq month (1+ month))
  270.            (setq day 1)
  271.            (if (< 12 month)
  272.            (progn
  273.              (setq month 1)
  274.              (setq year (1+ year))
  275.              ))
  276.            )))
  277.     ((> 0 hour)
  278.      (setq hour (+ hour 24))
  279.      (setq day  (1- day))
  280.      (if (> 1 day)
  281.          (progn
  282.            (setq month (1- month))
  283.            (if (> 1 month)
  284.            (progn
  285.              (setq month 12)
  286.              (setq year (1- year))
  287.              ))
  288.            (setq day (timezone-last-day-of-month month year))
  289.            )))
  290.     )
  291.   (vector year month day hour minute second))
  292.  
  293. ;; Partly copied from Calendar program by Edward M. Reingold.
  294. ;; Thanks a lot.
  295.  
  296. (defun timezone-last-day-of-month (month year)
  297.   "The last day in MONTH during YEAR."
  298.   (if (and (= month 2) (timezone-leap-year-p year))
  299.       29
  300.     (aref [31 28 31 30 31 30 31 31 30 31 30 31] (1- month))))
  301.  
  302. (defun timezone-leap-year-p (year)
  303.   "Returns t if YEAR is a Gregorian leap year."
  304.   (or (and (zerop  (% year 4))
  305.        (not (zerop (% year 100))))
  306.       (zerop (% year 400))))
  307.  
  308. --
  309. "Long hair, short hair--what's the difference once the head's blowed off?" (?)
  310.