From: Frank Schmitt <usereplyto@Frank-Schmitt.net>
Subject: Update of gnus-user-date (was: [patch] age depending date-format)
Date: Wed, 17 Oct 2001 22:35:29 +0200 [thread overview]
Message-ID: <lmia80oe.fsf_-_@hschmi22.userfqdn.rz-online.de> (raw)
In-Reply-To: <2n1yk3tiil.fsf@zsh.cs.rochester.edu>
[-- Attachment #1: Type: text/plain, Size: 440 bytes --]
ShengHuo ZHU <zsh@cs.rochester.edu> 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.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Patch against gnus-util.el --]
[-- Type: text/x-patch, Size: 3245 bytes --]
--- 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 <ich@Frank-Schmitt.net>. 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 ()
[-- Attachment #3: Type: text/plain, Size: 0 bytes --]
next prev parent reply other threads:[~2001-10-17 20:35 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-10-16 19:42 [patch] age depending date-format Frank Schmitt
2001-10-16 20:52 ` ShengHuo ZHU
2001-10-17 7:16 ` Frank Schmitt
2001-10-17 16:09 ` ShengHuo ZHU
2001-10-17 16:34 ` Frank Schmitt
2001-10-17 11:50 ` Kai Großjohann
2001-10-17 13:59 ` ShengHuo ZHU
2001-10-17 14:08 ` Didier Verna
2001-10-17 14:11 ` Colin Marquardt
2001-10-17 14:36 ` Didier Verna
2001-10-17 15:05 ` Kai Großjohann
2001-10-17 15:33 ` Didier Verna
2001-10-17 15:30 ` Paul Jarc
2001-10-17 15:41 ` Didier Verna
2001-10-17 16:14 ` Per Abrahamsen
2001-10-17 16:19 ` Paul Jarc
2001-10-17 16:37 ` Simon Josefsson
2001-10-17 16:52 ` Kai Großjohann
2001-10-17 17:03 ` Paul Jarc
2001-10-17 18:11 ` Per Abrahamsen
2001-10-17 18:08 ` Per Abrahamsen
2001-10-17 16:20 ` Amos Gouaux
2001-10-17 16:51 ` Kai Großjohann
2001-10-18 6:44 ` Yair Friedman (Jerusalem)
2001-10-17 15:09 ` Per Abrahamsen
2001-10-17 15:15 ` Per Abrahamsen
2001-10-17 15:19 ` Kai Großjohann
2001-10-17 16:04 ` ShengHuo ZHU
2001-10-17 20:35 ` Frank Schmitt [this message]
2001-10-17 21:34 ` Update of gnus-user-date (was: [patch] age depending date-format) ShengHuo ZHU
2001-10-18 7:53 ` Update of gnus-user-date Frank Schmitt
2001-10-18 10:08 ` Kai Großjohann
2001-10-19 17:11 ` Update of gnus-user-date (was: [patch] age depending date-format) Wes Hardaker
2001-10-17 10:51 ` [patch] age depending date-format Frank Schmitt
2001-10-17 15:05 ` Yair Friedman (Jerusalem)
2001-10-17 16:09 ` Frank Schmitt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=lmia80oe.fsf_-_@hschmi22.userfqdn.rz-online.de \
--to=usereplyto@frank-schmitt.net \
--cc=usenet@Frank-Schmitt.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).