date.lisp string->dttm failures

"Michael A. Koerber" <[email protected]>
Newsgroups gmane.lisp.clocc.devel
Message-ID <[email protected]>
In working on a project for home, I needed to parse a long list of
DATE fields from old e-mail files.  There were a few pathologic
entries that caused string->dttm to fail.  These input strings and my
hack are provided below.  I couldn't even begin to guess if such a
changes should be made to date.lisp...it could be that the (unknown)
mailer programs that generated these strings should be outlawed :-).

...
mike
********************
Dr Michael A. Koerber
MIT/Lincoln Laboratory
[email protected]

(defun string->dttm (xx)
  "Parse the string into a date/time integer."
  (declare (simple-string xx))
  (or (string-w3-dttm xx)
      (multiple-value-bind (v0 v1 v2 v3 v4 v5 v6 v7)
          (values-list
           (delete-if (lambda (st)
                        (and (symbolp st)
                             (find (subseq (to-string st) 0 3) +week-days+
                                   :test #'string-equal)))
                      (string-tokens
                       (purge-string (if (< (count #\- xx) 2) xx
                                         ;; kill #\- in yyyy-mm-dd
                                         (substitute #\Space #\- xx :count 2))
                                     ":,/()")
                       :max 9)))

        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	;; Begin MAK Hack
	;; Fix Y2K problem with some dates
	(cond
	 ((and (>= v2 50)
	       (< v2 99)) (incf v2 1900))
	 ((and (>= v2 0)
	       (< v2 50)) (incf v2 2000)))

	;; And some pathological formats give the TIME ZONE as, e.g.,
	;; Wed, 31 Oct 2001 17:59:31 -0800 (PST)
	;;                           ^^^^^ ^^^^ which puts (PST) in v7
	;; and v7 is assumed to be minutes in INFER-TIMEZONE
	(if (not (numberp v7)) (setf v7 nil))
	;; End MAK Hack
        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	
	
        (if (numberp v0)
            (encode-universal-time (round (or v5 0)) (or v4 0) (or v3 0)
                                   (min v0 v2) (infer-month v1) (max v0 v2)
                                   (infer-timezone v6 v7))
            (encode-universal-time (round (or v4 0)) (or v3 0) (or v2 0)
                                   v1 (infer-month v0) v5
                                   (infer-timezone v6 v7))))))



_______________________________________________________________
Hundreds of nodes, one monster rendering program.
Now that's a super model! Visit http://clustering.foundries.sf.net/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.