From: Lars Magne Ingebrigtsen <larsi@gnus.org>
To: emacs-devel@gnu.org
Subject: `format-time-string', TZ and environement variables
Date: Fri, 24 Feb 2012 20:24:38 -0800 [thread overview]
Message-ID: <m3sjhzleux.fsf@stories.gnus.org> (raw)
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/
next reply other threads:[~2012-02-25 4:24 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-25 4:24 Lars Magne Ingebrigtsen [this message]
2012-02-25 10:02 ` `format-time-string', TZ and environement variables Andreas Schwab
2012-02-27 14:02 ` 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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m3sjhzleux.fsf@stories.gnus.org \
--to=larsi@gnus.org \
--cc=emacs-devel@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 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).