X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=lisp%2Ftime-date.el;h=38f9b1ad6b6b5bb18b96a6c674781553513f6f3a;hb=e5bec5d05f433a43fa2d14cdb7bebeeefab8835f;hp=db7a35e652117766f92ba4ec29468ec99a070fb8;hpb=e7b89fdbd5b964b512e70e7d89b4a0248e2e550e;p=elisp%2Fgnus.git- diff --git a/lisp/time-date.el b/lisp/time-date.el index db7a35e..38f9b1a 100644 --- a/lisp/time-date.el +++ b/lisp/time-date.el @@ -1,8 +1,10 @@ ;;; time-date.el --- Date and time handling functions -;; Copyright (C) 1998 Free Software Foundation, Inc. +;; Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc. ;; Author: Lars Magne Ingebrigtsen ;; Masanobu Umeda +;; Keywords: mail news util + ;; This file is part of GNU Emacs. ;; GNU Emacs is free software; you can redistribute it and/or modify @@ -24,19 +26,32 @@ ;;; Code: +(eval-when-compile (require 'cl)) + (require 'parse-time) +(autoload 'timezone-make-date-arpa-standard "timezone") + +;;;###autoload (defun date-to-time (date) "Convert DATE into time." (condition-case () - (apply 'encode-time (parse-time-string date)) + (apply 'encode-time + (parse-time-string + ;; `parse-time-string' isn't sufficiently general or + ;; robust. It fails to grok some of the formats that + ;; timzeone does (e.g. dodgy post-2000 stuff from some + ;; Elms) and either fails or returns bogus values. Lars + ;; reverted this change, but that loses non-trivially + ;; often for me. -- fx + (timezone-make-date-arpa-standard date))) (error (error "Invalid date: %s" date)))) (defun time-to-seconds (time) "Convert TIME to a floating point number." (+ (* (car time) 65536.0) (cadr time) - (/ (or (caddr time) 0) 1000000.0))) + (/ (or (nth 2 time) 0) 1000000.0))) (defun seconds-to-time (seconds) "Convert SECONDS (a floating point number) to an Emacs time structure." @@ -79,7 +94,7 @@ (defun date-to-day (date) "Return the number of days between year 1 and DATE." (time-to-days (date-to-time date))) - + (defun days-between (date1 date2) "Return the number of days between DATE1 and DATE2." (- (date-to-day date1) (date-to-day date2))) @@ -116,6 +131,12 @@ The Gregorian date Sunday, December 31, 1bce is imaginary." (- (/ (1- year) 100)) ; - century years (/ (1- year) 400)))) ; + Gregorian leap years +(defun time-to-number-of-days (time) + "Return the number of days represented by TIME. +The number of days will be returned as a floating point number." + (/ (+ (* 1.0 65536 (car time)) (cadr time)) (* 60 60 24))) + +;;;###autoload (defun safe-date-to-time (date) "Parse DATE and return a time structure. If DATE is malformed, a zero time will be returned."