--- gnus-util.el Sun Oct 7 13:49:04 2001 +++ gnus-util2.el Wed Oct 17 20:26:40 2001 @@ -299,6 +299,68 @@ (yes-or-no-p prompt) (message ""))) +;; By Frank Schmitt . Allows to have age-depending +;; date representations. (e.g. just the time if it's from today, the day +;; of the week if it's within the last 7 days and the full date if it's older) +(defun gnus-seconds-today () +"Returns the number of seconds passed today" +(setq now (decode-time (current-time))) +(+ (car now) (* (car (cdr now)) 60) (* (car (nthcdr 2 now)) 3600))) + +(defun gnus-seconds-month () +"Returns the number of seconds passed this month" +(setq now (decode-time (current-time))) +(+ (car now) (* (car (cdr now)) 60) (* (car (nthcdr 2 now)) 3600) (* (- (car (nthcdr 3 now)) 1) 3600 24))) + +(defun gnus-seconds-year () +"Returns the number of seconds passed this year" +(setq now (decode-time (current-time))) +(setq days (format-time-string "%j" (current-time))) +(+ (car now) (* (car (cdr now)) 60) (* (car (nthcdr 2 now)) 3600) (* (- (string-to-number days) 1) 3600 24))) + +(defvar gnus-user-date-format-alist + '(((gnus-seconds-today) . "%k:%M") + (604800 . "%a %k:%M") ;;that's one week + ((gnus-seconds-month) . "%a %d") + ((gnus-seconds-year) . "%b %d") + (t . "%b %m '%y")) ;;this one is used when no other does match + "Alist of time in seconds and format specification used to display dates not older. +The first element must be a number or a function returning a number. The second element +is a format-specification as described in the documentation for format-time-string. +The list must be ordered smallest number up. When there is an element, which is not a +number, the corresponding format-specification will be used, disregarding any following +elements. +You can use the functions gnus-seconds-today, gnus-seconds-month, gnus-seconds-year +which will return the number of seconds which passed today/this month/this year.") + +(defun gnus-user-date (messy-date) + "Format the messy-date acording to gnus-user-date-format-alist. +Returns \" ? \" if there's bad input or if an other error occurs. +Input should look like this: \"Sun, 14 Oct 2001 13:34:39 +0200\"." + (condition-case () + (progn + (setq messy-date (safe-date-to-time messy-date)) + (setq now (current-time)) + (setq my-format "%b %m '%y") ;;If we don't find something suitable we'll use this one + (setq high (lsh (- (car now) (car messy-date)) 16)) + (if (and (> high -1) (= (logand high 65535) 0)) ;;overflow and bad input + (progn + (setq difference (+ high (- (car (cdr now)) (car (cdr messy-date))))) + (setq templist gnus-user-data-format-alist) + (setq top (eval (caar templist))) + (while (and (numberp top) (< top difference)) + (progn + (setq templist (cdr templist)) + (setq top (eval (caar templist))) + ) + ) + (if (stringp (cdr (car templist))) + (setq my-format (cdr (car templist))) + ))) + (format-time-string (eval my-format) messy-date)) + (error " ? "))) +;;end of Frank's code + (defun gnus-dd-mmm (messy-date) "Return a string like DD-MMM from a big messy string." (condition-case ()