Subject: bug#19874: 25.0.50; encode-time not working as expected

From: [email-masked] (Ashish SHUKLA)
Date: Thu, 26 Feb 2015 21:28:55 +0530

On Thu, 26 Feb 2015 00:39:57 -0800, Paul Eggert <[email-masked]> said:
| Ashish SHUKLA wrote:
|| I did this in X11 window (note the absence
|| of '-batch' option)
|| 
|| --8<---------------cut here---------------start------------->8---
|| emacs-25.0.50.20150206.5c9ad35f/src % ../src/emacs -Q -eval '(progn (setenv "TZ" "Asia/Kolkata") (print (encode-time 44 42 6 15 2 2015 0 nil 0)))'
|| oldtz=(null) tz=XXX-0:00:00 oldTZ=(null) TZ=(null) 2015-02-15 06:42:44 -1 -> 2015-02-15 06:42:44 0 = 1423962764

| This makes it look like immediately after set_time_zone_rule
| ("XXX-0:00:00") was called, getenv ("TZ") returned NULL.  That
| shouldn't happen: set_time_zone_rule is supposed to arrange for TZ to
| have the specified value.

| Could you please try similar tests with the attached patch instead?
| It should tell us whether set_time_zone_rule is properly affecting the
| TZ environment variable.

| diff --git a/src/editfns.c b/src/editfns.c
| index dbcb316..4c542bd 100644
| --- a/src/editfns.c
| +++ b/src/editfns.c
| @@ -2359,6 +2359,11 @@ set_time_zone_rule (const char *tzstring)
|        xputenv (tzval);
|      }
 
| +  char const *TZ = getenv ("TZ");
| +  fprintf (stderr, ("set_time_zone_rule (\"%s\"); "
| +		    "tzval = \"%s\"; getenv (\"TZ\") -> %s\n"),
| +	   tzstring ? tzstring : "(null)", tzval, TZ ? TZ : "(null)");
| +
|  #ifdef HAVE_TZSET
|    tzset ();
|  #endif

There you go:

--8<---------------cut here---------------start------------->8---
emacs-25.0.50.20150206.5c9ad35f/src % ../src/emacs -Q -eval '(progn (setenv "TZ" "Asia/Kolkata") (print (encode-time 44 42 6 15 2 2015 0 nil 0)))'
set_time_zone_rule ("(null)"); tzval = "tZ="; getenv ("TZ") -> (null)
set_time_zone_rule ("Asia/Kolkata"); tzval = "TZ=Asia/Kolkata"; getenv ("TZ") -> (null)
set_time_zone_rule ("XXX-0:00:00"); tzval = "TZ=XXX-0:00:00"; getenv ("TZ") -> (null)
oldtz=(null) tz=XXX-0:00:00 oldTZ=(null) TZ=(null) 2015-02-15 06:42:44 -1 -> set_time_zone_rule ("(null)"); tzval = "tZ="; getenv ("TZ") -> (null)
2015-02-15 06:42:44 0 = 1423962764^C
--8<---------------cut here---------------end--------------->8---

In minibuffer, "(21727 62092)" is displayed. And with "-batch":

--8<---------------cut here---------------start------------->8---
emacs-25.0.50.20150206.5c9ad35f/src % ../src/emacs -batch -Q -eval '(progn (setenv "TZ" "Asia/Kolkata") (print (encode-time 44 42 6 15 2 2015 0 nil 0)))'
set_time_zone_rule ("(null)"); tzval = "tZ="; getenv ("TZ") -> (null)
set_time_zone_rule ("Asia/Kolkata"); tzval = "TZ=Asia/Kolkata"; getenv ("TZ") -> Asia/Kolkata
set_time_zone_rule ("XXX-0:00:00"); tzval = "TZ=XXX-0:00:00"; getenv ("TZ") -> XXX-0:00:00
oldtz=Asia/Kolkata tz=XXX-0:00:00 oldTZ=Asia/Kolkata TZ=XXX-0:00:00 2015-02-15 06:42:44 -1 -> set_time_zone_rule ("Asia/Kolkata"); tzval = "TZ=Asia/Kolkata"; getenv ("TZ") -> Asia/Kolkata
2015-02-15 06:42:44 0 = 1423982564
(21728 16356)
--8<---------------cut here---------------end--------------->8---

Decided to explicitly set "TZ=Asia/Kolkata" in environment before invoking
Emacs, and it seems like now getenv("TZ") is returning "Asia/Kolkata"
everytime:

--8<---------------cut here---------------start------------->8---
emacs-25.0.50.20150206.5c9ad35f/src % TZ=Asia/Kolkata ../src/emacs -Q -eval '(progn (setenv "TZ" "Asia/Kolkata") (print (encode-time 44 42 6 15 2 2015 0 nil 0)))'
set_time_zone_rule ("Asia/Kolkata"); tzval = "TZ=Asia/Kolkata"; getenv ("TZ") -> Asia/Kolkata
set_time_zone_rule ("Asia/Kolkata"); tzval = "TZ=Asia/Kolkata"; getenv ("TZ") -> Asia/Kolkata
set_time_zone_rule ("XXX-0:00:00"); tzval = "TZ=XXX-0:00:00"; getenv ("TZ") -> Asia/Kolkata
oldtz=Asia/Kolkata tz=XXX-0:00:00 oldTZ=Asia/Kolkata TZ=Asia/Kolkata 2015-02-15 06:42:44 -1 -> set_time_zone_rule ("Asia/Kolkata"); tzval = "TZ=Asia/Kolkata"; getenv ("TZ") -> Asia/Kolkata
2015-02-15 06:42:44 0 = 1423962764
--8<---------------cut here---------------end--------------->8---

In minibuffer, "(21727 62092)" is displayed. And with "-batch":

--8<---------------cut here---------------start------------->8---
emacs-25.0.50.20150206.5c9ad35f/src % TZ=Asia/Kolkata ../src/emacs -batch -Q -eval '(progn (setenv "TZ" "Asia/Kolkata") (print (encode-time 44 42 6 15 2 2015 0 nil 0)))'
set_time_zone_rule ("Asia/Kolkata"); tzval = "TZ=Asia/Kolkata"; getenv ("TZ") -> Asia/Kolkata
set_time_zone_rule ("Asia/Kolkata"); tzval = "TZ=Asia/Kolkata"; getenv ("TZ") -> Asia/Kolkata
set_time_zone_rule ("XXX-0:00:00"); tzval = "TZ=XXX-0:00:00"; getenv ("TZ") -> XXX-0:00:00
oldtz=Asia/Kolkata tz=XXX-0:00:00 oldTZ=Asia/Kolkata TZ=XXX-0:00:00 2015-02-15 06:42:44 -1 -> set_time_zone_rule ("Asia/Kolkata"); tzval = "TZ=Asia/Kolkata"; getenv ("TZ") -> Asia/Kolkata
2015-02-15 06:42:44 0 = 1423982564
--8<---------------cut here---------------end--------------->8---

Thanks!
-- 
Ashish SHUKLA

“The mirror sees the man as beautiful, the mirror loves the man; another mirror
sees the man as frightful and hates him; and it is always the same being who
produces the impressions.” (Marquis D. A. F. de Sade)

Sent from my Emacs