From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Lars Magne Ingebrigtsen Newsgroups: gmane.emacs.devel Subject: `format-time-string', TZ and environement variables Date: Fri, 24 Feb 2012 20:24:38 -0800 Organization: Programmerer Ingebrigtsen Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1330143907 14068 80.91.229.3 (25 Feb 2012 04:25:07 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 25 Feb 2012 04:25:07 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Feb 25 05:25:06 2012 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1S19Bx-0000q5-Ci for ged-emacs-devel@m.gmane.org; Sat, 25 Feb 2012 05:25:06 +0100 Original-Received: from localhost ([::1]:55900 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S19Bw-0002e9-Kp for ged-emacs-devel@m.gmane.org; Fri, 24 Feb 2012 23:25:04 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:36797) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S19Bo-0002cw-FT for emacs-devel@gnu.org; Fri, 24 Feb 2012 23:25:02 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S19Bh-0007FD-Vf for emacs-devel@gnu.org; Fri, 24 Feb 2012 23:24:56 -0500 Original-Received: from plane.gmane.org ([80.91.229.3]:57091) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S19Bh-0007F7-Ot for emacs-devel@gnu.org; Fri, 24 Feb 2012 23:24:49 -0500 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1S19Be-0000gE-BF for emacs-devel@gnu.org; Sat, 25 Feb 2012 05:24:46 +0100 Original-Received: from cm-84.215.51.58.getinternet.no ([84.215.51.58]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 25 Feb 2012 05:24:46 +0100 Original-Received: from larsi by cm-84.215.51.58.getinternet.no with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 25 Feb 2012 05:24:46 +0100 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: emacs-devel@gnu.org Original-Lines: 45 Original-X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: cm-84.215.51.58.getinternet.no Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAElBMVEUAAABXJh8/Hht3Riwb DxABAQIos7B+AAACUElEQVQ4jW2Uy5bbIAyG6YV9hD37SJb3xczsJyre+6Tm/V+lv8DTzjktSXwc Pn7dEIQj+IixHTHgi9Gf/mv/GbGF77fy79i+vANQmmYTLpkUT8pWlu3b7oCkWlpKyf6ZCkHx9egK qhWyTJNDVxpAvBMlU05MVLIAZlgOUDhgiBhOiTvYxMFtSmnJZMWnOJWSiBOyANgIoiUnETJ4zmzi 4E0wj+UkWtUQdUGQnvu7YnGPpVbrnnizbko5y1Q2ZFNZlp64oFbxpjIh+pJTxRKkUjwqmLoLXQXS 2l/z4zKVuM9TAnBL22PuwBW9EPBRH66geZhSL0VKYhcoee4J3nUW2EHwVeuwujmIPxTRkwCIjHnU YOSBpYLHAwXwzSjuI7qp6tZrB1dxOrjBiA3AmeGsJLWuWNuQGAmLl1g6QBF3V1g1xpwP6yAEberr UXImRKw6XWBt54mdQEEYDQSAZgjNwdlOK7P7IEnQ8l9Fc1DdvhpKtj8/AFbPnj4nmJO6/1FUUfhO qaKPkInKAGd7Qi/oyETeGco9j7buzWivvhabSjQhjqE4otBa3QbaAJ36el7hHtGWlxNL0exqRG9t gDvSWOYT5dAeVX5pT5wo+AihGo4OBidlmlt7uiKu7Tg930zoqvlnXj+D/TRPgRZ5QDBAW3Gimyla asqy295Bz6PhmPxK3tmFxmn2qBoADpwxFDxN73GA0IGf+MeUJi6vLxeIH6A9zx25rfsnU9r/+AM7 cfmIRzgbqnON/PEydwUcXHeO30Txuo6uqyiMCymMccQWfwNKyrX31TrdrQAAAABJRU5ErkJggg== Mail-Copies-To: never X-Now-Playing: Coil's _Moon's Milk (In Four Phases) (2)_: "Magnetic North" User-Agent: Gnus/5.130004 (Ma Gnus v0.4) Emacs/24.0.93 (gnu/linux) Cancel-Lock: sha1:hDbd9z9sSpjKSodqwRCC7gSD3jo= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:148770 Archived-At: 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/