all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Ted Zlatanov <tzz@lifelogs.com>
To: help-gnu-emacs@gnu.org
Subject: Re: efficiently viewing Unix timestamps as dates
Date: Thu, 16 Dec 2010 17:12:23 -0600	[thread overview]
Message-ID: <87fwtx5n3c.fsf@lifelogs.com> (raw)
In-Reply-To: jwvlj3pxt9q.fsf-monnier+gnu.emacs.help@gnu.org

On Thu, 16 Dec 2010 17:23:34 -0500 Stefan Monnier <monnier@iro.umontreal.ca> wrote: 

>> but the actual format string should be up to the user.  Really, my
>> question is "how do I find numbers that look like 1292527019, run a
>> function on them, and then show the results of that function overlaid on
>> top of the number without actually changing it in the buffer?"

SM> The first part is rather tricky: "2" looks an awful lot like a Unix
SM> timestamp ...wait... it *is* a Unix timestamp!
SM> But assuming you know something about those time stamps, you can try
SM> something like:

SM>   (add-hook 'foo-mode-hook
SM>             (lambda ()
SM>               (font-lock-add-keywords nil
SM>                 '(("^[0-9]+"
SM>                    (0 `(face nil display
SM>                         ,(format-time-string "%F %T"
SM>                            (seconds-to-time
SM>                             (car (read-from-string
SM>                                   (concat "1292527019" ".0"))))))))))))

SM> where "^[0-9]+" is the regexp that matches your timestamps (in this
SM> case I chose to assume they're always at the beginning of a line).

I see a small bug in the last line, but I think it's fixable :)

On Thu, 16 Dec 2010 13:34:51 -0800 PJ Weisberg <pj@irregularexpressions.net> wrote: 

PW> Argh.  I don't actually know how to do the visual-only thing, but that
PW> problem is complicated by the fact that the string "December 16, 2010"
PW> (for example) contains TWO Unix timestamps, both in the early morning
PW> hours of January 1, 1970.

It's not so bad (I only bothered for dates after 2001 or 0-padded at the
beginning):

(add-hook 'foo-mode-hook
          (lambda ()
            (font-lock-add-keywords
             nil
             '(("[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]"
                (0 `(face nil display
                          ,(format-time-string "%F %T"
                                               (seconds-to-time
                                                (car
                                                 (read-from-string
                                                  (concat
                                                   (match-string 0)
                                                   ".0"))))))))))))

I'd rather make this a minor mode than a hook, so I can easily turn it
on in a buffer.  Is that easy or hard to do?  Any specific example I can
look at?

Ted


  reply	other threads:[~2010-12-16 23:12 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-13 17:20 efficiently viewing Unix timestamps as dates Ted Zlatanov
2010-12-16  7:28 ` Kevin Rodgers
     [not found] ` <mailman.8.1292484545.7231.help-gnu-emacs@gnu.org>
2010-12-16 19:26   ` Ted Zlatanov
2010-12-16 20:48     ` Burton Samograd
2010-12-16 21:34     ` PJ Weisberg
2010-12-16 22:23     ` Stefan Monnier
2010-12-16 23:12       ` Ted Zlatanov [this message]
2010-12-17  2:35         ` Stefan Monnier
2011-04-15  0:31           ` Ted Zlatanov
2011-04-15 15:29             ` Stefan Monnier
2011-04-15 16:59               ` Ted Zlatanov
2011-04-17 14:38                 ` Stefan Monnier
2011-04-19 13:23                   ` Ted Zlatanov
2011-04-19 15:23                     ` Stefan Monnier
2011-04-19 18:09                       ` Ted Zlatanov
2011-04-21 20:20                         ` Stefan Monnier
2011-04-21 20:48                           ` Ted Zlatanov
2011-04-24  5:18                             ` Stefan Monnier
2011-04-25 19:52                               ` Ted Zlatanov
2011-04-26  2:50                                 ` Ted Zlatanov
2011-04-26 13:28                                 ` Stefan Monnier
2011-04-26 15:43                                   ` Ted Zlatanov
2011-04-27 14:18                                     ` Stefan Monnier
2011-05-04 13:35                                       ` Ted Zlatanov
2011-05-04 15:32                                         ` Stefan Monnier
2011-05-04 19:40                                           ` Ted Zlatanov
2010-12-17  8:25         ` Eli Zaretskii
     [not found]         ` <mailman.7.1292574349.666.help-gnu-emacs@gnu.org>
2010-12-17 14:07           ` Ted Zlatanov

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=87fwtx5n3c.fsf@lifelogs.com \
    --to=tzz@lifelogs.com \
    --cc=help-gnu-emacs@gnu.org \
    /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.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.