emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

`format-time-string', TZ and environement variables


From: Lars Magne Ingebrigtsen
Subject: `format-time-string', TZ and environement variables
Date: Fri, 24 Feb 2012 20:24:38 -0800
User-agent: Gnus/5.130004 (Ma Gnus v0.4) Emacs/24.0.93 (gnu/linux)

I needed to format a time string in the time zone it was originally
written in (after making it more valid).

(setq time (parse-time-string "16 Oct 92 13:48:29 PST"))
=> (29 48 13 16 10 1992 nil (-28800) -28800)

(Hm.  That's slightly buggy.  The DST should field is documented to be
either t or nil, so that `(-28800)' thing looks weird...)

Anyway, the original date string is kinda invalid because of the Y2K
problem, so I thought I'd just parse it and then recreate the string,
which turned out to be difficult and undocumented.  

(apply 'encode-time time)
=> (10975 14509)

(format-time-string "%a, %d %b %Y %T %z" (apply 'encode-time time))
=> "Fri, 16 Oct 1992 22:48:29 +0100"

Er, nope.

(setenv "TZ" (format "GMT%d" (- (/ (or (car (last time)) 0)
                                       60 60))))
=> "GMT8"

(format-time-string "%a, %d %b %Y %T %z" (apply 'encode-time time))
=> "Fri, 16 Oct 1992 13:48:29 -0800"

I think.  Or something.

`format-time-string' allows either formatting in the local time zone, or
using UT.  I think either it should be extended to allow formatting in
any time zone, or the "TZ" trick should be documented.  If the latter,
we should probably have a nice macro for the environment variables, too:

(with-environment-variable ("TZ" "GMT8")
  (format-time-string "%a, %d %b %Y %T %z" (apply 'encode-time time)))

Because using `setenv' directly is kinda yucky.

This is not for Emacs 24.1, obviously...

-- 
(domestic pets only, the antidote for overdose, milk.)
  bloggy blog http://lars.ingebrigtsen.no/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]