* `format-time-string', TZ and environement variables
@ 2012-02-25 4:24 Lars Magne Ingebrigtsen
2012-02-25 10:02 ` Andreas Schwab
2012-02-27 14:02 ` Ted Zlatanov
0 siblings, 2 replies; 3+ messages in thread
From: Lars Magne Ingebrigtsen @ 2012-02-25 4:24 UTC (permalink / raw)
To: emacs-devel
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/
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: `format-time-string', TZ and environement variables
2012-02-25 4:24 `format-time-string', TZ and environement variables Lars Magne Ingebrigtsen
@ 2012-02-25 10:02 ` Andreas Schwab
2012-02-27 14:02 ` Ted Zlatanov
1 sibling, 0 replies; 3+ messages in thread
From: Andreas Schwab @ 2012-02-25 10:02 UTC (permalink / raw)
To: emacs-devel
Lars Magne Ingebrigtsen <larsi@gnus.org> writes:
> (Hm. That's slightly buggy. The DST should field is documented to be
> either t or nil, so that `(-28800)' thing looks weird...)
Fixed.
Andreas.
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: `format-time-string', TZ and environement variables
2012-02-25 4:24 `format-time-string', TZ and environement variables Lars Magne Ingebrigtsen
2012-02-25 10:02 ` Andreas Schwab
@ 2012-02-27 14:02 ` Ted Zlatanov
1 sibling, 0 replies; 3+ messages in thread
From: Ted Zlatanov @ 2012-02-27 14:02 UTC (permalink / raw)
To: emacs-devel
On Fri, 24 Feb 2012 20:24:38 -0800 Lars Magne Ingebrigtsen <larsi@gnus.org> wrote:
LMI> we should probably have a nice macro for the environment variables, too:
LMI> (with-environment-variable ("TZ" "GMT8")
LMI> (format-time-string "%a, %d %b %Y %T %z" (apply 'encode-time time)))
LMI> Because using `setenv' directly is kinda yucky.
I agree it's generally useful to have that macro, except it should take
a list:
(with-environment-variables (("TZ" . "GMT8")) ...)
Ted
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-02-27 14:02 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-25 4:24 `format-time-string', TZ and environement variables Lars Magne Ingebrigtsen
2012-02-25 10:02 ` Andreas Schwab
2012-02-27 14:02 ` Ted Zlatanov
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).