From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/39376 Path: main.gmane.org!not-for-mail From: Frank Schmitt Newsgroups: gmane.emacs.gnus.general Subject: Update of gnus-user-date (was: [patch] age depending date-format) Date: Wed, 17 Oct 2001 22:35:29 +0200 Organization: Hamme net, kren mer och nimmi Sender: owner-ding@hpc.uh.edu Message-ID: References: <2n1yk3tiil.fsf@zsh.cs.rochester.edu> Reply-To: NNTP-Posting-Host: coloc-standby.netfonds.no Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: main.gmane.org 1035175090 27537 80.91.224.250 (21 Oct 2002 04:38:10 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Mon, 21 Oct 2002 04:38:10 +0000 (UTC) Return-Path: Original-Received: (qmail 28416 invoked from network); 17 Oct 2001 20:37:41 -0000 Original-Received: from malifon.math.uh.edu (mail@129.7.128.13) by mastaler.com with SMTP; 17 Oct 2001 20:37:41 -0000 Original-Received: from sina.hpc.uh.edu ([129.7.128.10] ident=lists) by malifon.math.uh.edu with esmtp (Exim 3.20 #1) id 15txPf-0003hX-00; Wed, 17 Oct 2001 15:35:39 -0500 Original-Received: by sina.hpc.uh.edu (TLB v0.09a (1.20 tibbs 1996/10/09 22:03:07)); Wed, 17 Oct 2001 15:35:17 -0500 (CDT) Original-Received: from sclp3.sclp.com (qmailr@sclp3.sclp.com [209.196.61.66]) by sina.hpc.uh.edu (8.9.3/8.9.3) with SMTP id PAA01986 for ; Wed, 17 Oct 2001 15:34:56 -0500 (CDT) Original-Received: (qmail 28365 invoked by alias); 17 Oct 2001 20:35:12 -0000 Original-Received: (qmail 28360 invoked from network); 17 Oct 2001 20:35:12 -0000 Original-Received: from quimby.gnus.org (195.204.10.139) by gnus.org with SMTP; 17 Oct 2001 20:35:12 -0000 Original-Received: (from news@localhost) by quimby.gnus.org (8.9.3/8.9.3) id WAA18350 for ding@gnus.org; Wed, 17 Oct 2001 22:35:05 +0200 (CEST) Original-To: ding@gnus.org Original-Path: not-for-mail Original-Newsgroups: gnus.ding Original-Lines: 103 Original-NNTP-Posting-Host: pppin88.max-hochsimmer.rz-online.net Original-X-Trace: quimby.gnus.org 1003350904 18466 212.7.169.88 (17 Oct 2001 20:35:04 GMT) Original-X-Complaints-To: usenet@quimby.gnus.org Original-NNTP-Posting-Date: 17 Oct 2001 20:35:04 GMT User-Agent: Gnus/5.090004 (Oort Gnus v0.04) XEmacs/21.4 (Academic Rigor) Hamster/1.3.23.0 X-Face: "?Hv7MyYveeGDm66,O\f[l6!L*,`Q)c&3'8{9UGIM`EO8<3ASfX`8}W+u;F},&V%/y+cz(z&spQ(`CkKzCJY/@0R]aM#[W7*$(,QA-oO0f}Z2S0Y0~b5}|XDhQds[9}=t$Hf%G2c;zR%;$"~eI+dw3Gy!xKw=oduK(-, Precedence: list X-Majordomo: 1.94.jlt7 Xref: main.gmane.org gmane.emacs.gnus.general:39376 X-Report-Spam: http://spam.gmane.org/gmane.emacs.gnus.general:39376 --=-=-= ShengHuo ZHU writes: >A suggestion. Is it better to use a variable like >gnus-user-data-format-alist instead of gnus-user-date-format-day and >it friends? g-u-d-f-a is a list of cons of elapsed time (or symbol) >and format. Here we go. I really like it. Now I feel like a real Gnus-programmer: I made something which is more customizable than you'll ever need and so difficult that no one will ever understand it. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=gnus-util.diff Content-Description: Patch against gnus-util.el --- 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 () --=-=-= -- One Ring to rule them all, One Ring to find them, One Ring to bring them all and in the darkness bind them In the Land of Mordor where the Shadows lie. 19. Dezember 2001 --=-=-=--