X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=lisp%2Ftime-date.el;h=db7a35e652117766f92ba4ec29468ec99a070fb8;hb=49e6091148fad026ec5a2324eaff06c145506235;hp=cd6f9e9d3abb4937bf4b2181bcb4a99b76d3581d;hpb=216dd310a007e96604475319ea3087bf9e9970c7;p=elisp%2Fgnus.git- diff --git a/lisp/time-date.el b/lisp/time-date.el index cd6f9e9..db7a35e 100644 --- a/lisp/time-date.el +++ b/lisp/time-date.el @@ -24,42 +24,25 @@ ;;; 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))) + (cadr time) + (/ (or (caddr time) 0) 1000000.0))) -(defun float-to-time (float) - "Convert FLOAT (a floating point number) to an Emacs time structure." - (list (floor float 65536) - (floor (mod float 65536)))) +(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." @@ -95,7 +78,7 @@ (defun date-to-day (date) "Return the number of days between year 1 and DATE." - (time-to-day (date-to-time date))) + (time-to-days (date-to-time date))) (defun days-between (date1 date2) "Return the number of days between DATE1 and DATE2." @@ -120,7 +103,7 @@ (setq day-of-year (1+ day-of-year)))) day-of-year)) -(defun time-to-day (time) +(defun time-to-days (time) "The number of days between the Gregorian date 0001-12-31bce and TIME. The Gregorian date Sunday, December 31, 1bce is imaginary." (let* ((tim (decode-time time)) @@ -133,6 +116,13 @@ The Gregorian date Sunday, December 31, 1bce is imaginary." (- (/ (1- year) 100)) ; - century years (/ (1- year) 400)))) ; + Gregorian leap years +(defun safe-date-to-time (date) + "Parse DATE and return a time structure. +If DATE is malformed, a zero time will be returned." + (condition-case () + (date-to-time date) + (error '(0 0)))) + (provide 'time-date) ;;; time-date.el ends here