Importing pgnus-0.18.
[elisp/gnus.git-] / lisp / time-date.el
index cd6f9e9..4f07bbc 100644 (file)
 
 ;;; Code:
 
-(eval-and-compile
-  (eval
-   '(if (not (string-match "XEmacs" emacs-version))
-       (require 'parse-time)
-
-      (require 'timezone)
-      (defun parse-time-string (date)
-       "Convert DATE into time."
-       (decode-time
-        (condition-case ()
-            (let* ((d1 (timezone-parse-date date))
-                   (t1 (timezone-parse-time (aref d1 3))))
-              (apply 'encode-time
-                     (mapcar (lambda (el)
-                               (and el (string-to-number el)))
-                             (list
-                              (aref t1 2) (aref t1 1) (aref t1 0)
-                              (aref d1 2) (aref d1 1) (aref d1 0)
-                              (number-to-string
-                               (* 60 (timezone-zone-to-minute (aref d1 4))))))))
-          ;; If we get an error, then we just return a 0 time.
-          (error (list 0 0))))))))
+(require 'parse-time)
 
 (defun date-to-time (date)
   "Convert DATE into time."
-  (apply 'encode-time (parse-time-string date)))
+  (condition-case ()
+      (apply 'encode-time (parse-time-string date))
+    (error (error "Invalid date: %s" date))))
 
-(defun time-to-float (time)
+(defun time-to-seconds (time)
   "Convert TIME to a floating point number."
   (+ (* (car time) 65536.0)
-     (cadr time)))
-
-(defun float-to-time (float)
-  "Convert FLOAT (a floating point number) to an Emacs time structure."
-  (list (floor float 65536)
-       (floor (mod float 65536))))
+     (cadr time)
+     (/ (or (caddr time) 0) 1000000.0)))
+
+(defun seconds-to-time (seconds)
+  "Convert SECONDS (a floating point number) to an Emacs time structure."
+  (list (floor seconds 65536)
+       (floor (mod seconds 65536))
+       (floor (* (- seconds (ffloor seconds)) 1000000))))
 
 (defun time-less-p (t1 t2)
   "Say whether time T1 is less than time T2."