Announcements and discussions for Gnus, the GNU Emacs Usenet newsreader
 help / color / mirror / Atom feed
* Re: Date/Time display
       [not found] <4qzt73yz.fsf@maxqnz.com>
@ 2003-09-05  6:18 ` Norbert Koch
       [not found] ` <873cfddrtt.fsf@cox.net>
  1 sibling, 0 replies; 2+ messages in thread
From: Norbert Koch @ 2003-09-05  6:18 UTC (permalink / raw)


Max Quordlepleen <maxq@nonags.com> writes:

> I like the easy keystrokes to change the display to my local timezone,
> but to make it permanent, do I just add (gnus-article-date-local) to
> my .gnus? What is the syntax I need? Thanks.

On a first glance I would have thought

(add-hook 'gnus-article-display-hook 'gnus-article-date-local)

should do the trick, but the outcome is not as I had expected, ie the
date haeader stays unchanged.  Hmm, is the date treated differently?

norbert.


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Date/Time display
       [not found]   ` <hluo21xn4v.ln2@elaleph.borges.cgitftp.uiggm.nsc.ru>
@ 2003-09-07  1:11     ` Nelson Ferreira
  0 siblings, 0 replies; 2+ messages in thread
From: Nelson Ferreira @ 2003-09-07  1:11 UTC (permalink / raw)


"Ivan" == Ivan Boldyrev <boldyrev+nospam@cgitftp.uiggm.nsc.ru> writes:

    Ivan> On 8491 day of my life Kevin Fleming wrote:
    >> Max Quordlepleen <maxq@nonags.com> writes:
    >>
    >>> I found this in the manual: 'WTl Display the date in the local
    >>> timezone (gnus-article-date-local).
    >>>
    >>> I like the easy keystrokes to change the display to my local
    >>> timezone, but to make it permanent, do I just add
    >>> (gnus-article-date-local) to my .gnus? What is the syntax I
    >>> need? Thanks.
    >>
    >> I think (setq gnus-treat-date-local 'head) works (for the
    >> record, I got this from section 4.3 of the Gnus manual,
    >> "Customizing Articles).

    Ivan> Does anyone know how can I see both original and (say)
    Ivan> elapsed date *at same time*?  It seems impossible -- some
    Ivan> variables take precedence over other ones...


[...]

I use the following below, which is pieced from several bits posted
by several people here and on the gnus mailing list. 
I'd love to have a more elegant solution...


(defun njsf-replace-header (header text) 
  ""
  (let* ((header-regexp (concat "^" header "[ \t]*:[ \t]"))
	 (inhibit-point-motion-hooks t)	 
	 pos bface eface)
    (save-excursion
      (save-restriction
	(article-narrow-to-head)
	(when (re-search-forward header-regexp nil t)
	  (setq bface (get-text-property (gnus-point-at-bol) 'face)
		eface (get-text-property (1- (gnus-point-at-eol)) 'face))
	  (forward-line 1))
	(goto-char (point-min))
	(let ((buffer-read-only nil))
	  ;; Delete any old headers.
	  (while (re-search-forward header-regexp nil t)
	    (setq pos (beginning-of-line))
	    (delete-region (progn (beginning-of-line) (point))
			   (progn (forward-line 1) (point)))
	    (when (re-search-forward "^\t" nil t)
	      (delete-region (progn (beginning-of-line) (point))
			     (progn (forward-line 1) (point)))))
	  (if pos (goto-char pos))
	  (insert (concat header ": " text "\n"))
	  (goto-char (point-min))
	  (when (re-search-forward header-regexp nil t)
	    (beginning-of-line)
	    (when (looking-at "^\\([^:]+\\): *\\(.*\\)$")
	      (put-text-property (match-beginning 1) (1+ (match-end 1))
				 'face bface)
	      (put-text-property (match-beginning 2) (match-end 2)
				 'face eface))
	    (when (looking-at "^\t\\(.*\\)$")
	      (put-text-property (match-beginning 1) (1+ (match-end 1))
				 'face eface))))))))
  

(defun njsf-remove-header (header) 
  ""
  (let* ((header-regexp (concat "^[ \t]?" header "[ \t]?:[ \t]?"))
	 (inhibit-point-motion-hooks t))
    (save-excursion
      (save-restriction
	(article-narrow-to-head)
	(when (re-search-forward header-regexp nil t)
	  (forward-line 1))
	(goto-char (point-min))
	(let ((buffer-read-only nil))
	  (while (re-search-forward header-regexp nil t)
	    (delete-region (progn (beginning-of-line) (point))
			   (progn (forward-line 1) (point)))
	    (when (re-search-forward "^\t" nil t)
	      (delete-region (progn (beginning-of-line) (point))
			     (progn (forward-line 1) (point))))))))))

(defun njsf-elapsed (date)
  ""
  (ignore-errors
    (let* ((time (date-to-time date))
	   (now (current-time))
	   (real-time (subtract-time now time))
	   (real-sec (and real-time
			  (+ (* (float (car real-time)) 65536)
			     (cadr real-time))))
	   (sec (and real-time (abs real-sec)))
	   num prev pos)
      (cond ((null real-time) "Unknown")
	    ((zerop sec)	   "Now")
	    (t   
	     (concat (mapconcat
		      ;; This is a bit convoluted, but basically we go
		      ;; through the time units for years, weeks, etc,
		      ;; and divide things to see whether that results
		      ;; in positive answers.
		      (lambda (unit)
			(if (zerop (setq num (ffloor (/ sec (cdr unit)))))
			    ;; The (remaining) seconds are too few to
			    ;; be divided into this time unit.
			    ""
			  ;; It's big enough, so we output it.
			  (setq sec (- sec (* num (cdr unit))))
			  (prog1
			      (concat (if prev ", " "") (int-to-string
							 (floor num))
				      " " (symbol-name (car unit))
				      (if (> num 1) "s" ""))
			    (setq prev t))))
		    article-time-units "")
		     ;; If dates are odd, then it might appear like the
		     ;; article was sent in the future.
		     (if (> real-sec 0) " ago" " in the future")))))))

(defun njsf-collapse-headers nil
  ""
  (let* ((case-fold-search t)
	 (date         (message-fetch-field "date"))
	 (sent         (njsf-elapsed date)))
    (when (and sent (not (string= sent "" )))
      (setq sent
	    (replace-in-string 
	     (replace-in-string 
	      (replace-in-string 
	       (replace-in-string 
		sent 
		"\\([0-9]+\\) *days?,? *" 
		"\\1d ")
	       "\\([0-9]+\\) *hours?,? *\\([0-9]+\\) *minutes?,? *\\([0-9]+\\) *seconds?,? *"
	       "\\1h\\2m\\3s ")
	      "\\([0-9]+\\) *hours?,? *\\([0-9]+\\) *minutes?,? *"
	      "\\1h\\2m ")
	     "\\([0-9]+\\) *minutes?,? *\\([0-9]+\\) *seconds?,? *"
	     "\\1m\\2s ")))
    (when (and date sent)
      (progn
	(njsf-remove-header "X-Sent")
	(njsf-replace-header "Date" (concat date " (" sent ")"))))
    (gnus-treat-article nil)))
(add-hook 'gnus-article-prepare-hook 'njsf-collapse-headers)


-- 
Nelson Ferreira


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2003-09-07  1:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <4qzt73yz.fsf@maxqnz.com>
2003-09-05  6:18 ` Date/Time display Norbert Koch
     [not found] ` <873cfddrtt.fsf@cox.net>
     [not found]   ` <hluo21xn4v.ln2@elaleph.borges.cgitftp.uiggm.nsc.ru>
2003-09-07  1:11     ` Nelson Ferreira

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).