bug-gnulib
[Top][All Lists]
Advanced

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

Re: tzset: add native Windows workaround


From: Bruno Haible
Subject: Re: tzset: add native Windows workaround
Date: Tue, 09 May 2017 21:35:05 +0200
User-agent: KMail/5.1.3 (Linux/4.4.0-75-generic; KDE/5.18.0; x86_64; ; )

Hi Paul,

> > Only for Cygwin, an empty or absent TZ environment variable means GMT.
> 
> That's weird; I don't know of any other system that does that.

Misunderstanding: I meant only among the platforms on Windows. I.e. for mingw 
and
MSVC, an empty or absent TZ environment variable means the system's notion of
time zone.

> > How about this revised comment?
> 
> > +     There are two possible kinds of such values:
> > +       - Traditional US time zone names, e.g. "PST8PDT",
> > +       - tzdata time zone names, based on geography.  They contain one
> > +         or more slashes.
> 
> As a point of terminology, "PST8PDT" is as much of a tzdata time zone name as 
> "America/Los_Angeles" is. They are both implemented by consulting a file by 
> that 
> name. And some of the slashless tzdata names are based on geography, e.g., 
> "Singapore", "GB-Eire" (these are mostly present for backward compatibility, 
> but 
> some people still use them). Perhaps it would be better to summarize things 
> by 
> wording the comment something like this:
> 
> 
> TZ values are of two kinds:
> 
> - Values supported by the Microsoft CRT, e.g., "PST+8PDT". See 
> <https://msdn.microsoft.com/en-us/library/90s5c885.aspx>. The documented 
> values 
> of this form are matched by the POSIX extended regular expression 
> "^[A-Za-z]{3}[-+]?[01]?[0-9](:[0-5][0-9](:[0-5][0-9])?)?([A-Za-z]{3})?$".
> 
> - Values supported by Cygwin, e.g., "America/Los_Angeles". Typically, each of 
> these values corresponds to the name of a file installed somewhere on the 
> system. However, some of these values are analyzed programmatically based on 
> rules specified by POSIX, e.g., "PST8PDT,M3.2.0,M11.1.0"; see 
> <http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html#tag_08_03>.
> 
> The two kinds of TZ values overlap, e.g., "PST8PDT" is valid in both 
> implementations.  However, most TZ values supported by Cygwin do not work 
> with 
> the Microsoft CRT, which silently uses UTC when given such values. In 
> practice 
> most of these troublesome TZ values contain '/', and no TZ value supported by 
> the Microsoft CRT contains '/', so as a heuristic neutralize any TZ value 
> containing '/'. For the Microsoft CRT, an absent or empty TZ means the time 
> zone 
> that the user has set in the Windows Control Panel.

Thanks for the explanations. However, your wording is quite confusing to me,
because it talks about the possible syntaxes and their different interpretations
at the same time, and because of the overlap. For clarity, I prefer to talk
about disjoint cases. Here's what I have come up with:


2017-05-09 Bruno Haible  <address@hidden>

        tzset: Expand comment about TZ problem on native Windows.
        * lib/tzset.c (tzset): Elaborate comment, based on explanations by
        Paul Eggert.
        * lib/ctime.c (rpl_ctime): Likewise.
        * lib/localtime.c (rpl_localtime): Likewise.
        * lib/mktime.c (mktime): Likewise.
        * lib/strftime-fixes.c (rpl_strftime): Likewise.
        * lib/wcsftime.c (rpl_wcsftime): Likewise.

diff --git a/lib/tzset.c b/lib/tzset.c
index ce854b9..bec4dfe 100644
--- a/lib/tzset.c
+++ b/lib/tzset.c
@@ -41,9 +41,28 @@ tzset (void)
 #endif
 
 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
-  /* If the environment variable TZ has been set by Cygwin, neutralize it.
-     The Microsoft CRT interprets TZ differently than Cygwin and produces
-     incorrect results if TZ has the syntax used by Cygwin.  */
+  /* Rectify the value of the environment variable TZ.
+     There are four possible kinds of such values:
+       - Traditional US time zone names, e.g. "PST8PDT".  Syntax: see
+         <https://msdn.microsoft.com/en-us/library/90s5c885.aspx>
+       - Time zone names based on geography, that contain one or more
+         slashes, e.g. "Europe/Moscow".
+       - Time zone names based on geography, without slashes, e.g.
+         "Singapore".
+       - Time zone names that contain explicit DST rules.  Syntax: see
+         
<http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html#tag_08_03>
+     The Microsoft CRT understands only the first kind.  It produces incorrect
+     results if the value of TZ is of the other kinds.
+     But in a Cygwin environment, /etc/profile.d/tzset.sh sets TZ to a value
+     of the second kind for most geographies, or of the first kind in a few
+     other geographies.  If it is of the second kind, neutralize it.  For the
+     Microsoft CRT, an absent or empty TZ means the time zone that the user
+     has set in the Windows Control Panel.
+     If the value of TZ is of the third or fourth kind -- Cygwin programs
+     understand these syntaxes as well --, it does not matter whether we
+     neutralize it or not, since these values occur only when a Cygwin user
+     has set TZ explicitly; this case is 1. rare and 2. under the user's
+     responsibility.  */
   const char *tz = getenv ("TZ");
   if (tz != NULL && strchr (tz, '/') != NULL)
     _putenv ("TZ=");




reply via email to

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