public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* setting TZ is harmful
@ 2017-05-09 14:10 Bruno Haible
  2017-05-09 14:41 ` Gluszczak, Glenn
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Bruno Haible @ 2017-05-09 14:10 UTC (permalink / raw)
  To: cygwin

Hi,

Currently, all commands in a Cygwin command window are run with the TZ
environment variable set.

It is set by /etc/profile.d/tzset.sh (or its csh equivalent,
/etc/profile.d/tzset.csh).

Setting TZ is harmful in two ways:

  1) When the user changes the time zone (through the Windows Control Panel) -
     for example when traveling - the programs run in the Cygwin command
     window will display a stale notion of local time. Only after the user
     closes and re-opens a new Cygwin command window, will the programs
     display local time according to the new time zone.

  2) It causes native Windows programs (built through mingw, MSVC) to assume
     a time zone that is different from the intended one and different from
     the one that the user has set in the Windows Control Panel (see APPENDIX 1
     below). This is because in most geographies, the values of TZ (produced
     by winsup/utils/tzset.c and winsup/utils/tzmap.h) contains a slash, and
     the tzset() function in the Microsoft CRT does not understand this syntax
     - it understands only a different syntax
     https://msdn.microsoft.com/en-us/library/90s5c885.aspx .

When TZ is not set, both Cygwin and native Windows programs take their time
zone information from the Windows Control Panel settings. See APPENDIX 2
below and https://lists.gnu.org/archive/html/bug-gnulib/2017-05/msg00035.html .

What are the benefits of setting the TZ environment variable? I don't
see any!

===> Please remove /etc/profile.d/tzset.{sh,csh} ! <===

Side note: An empty TZ value is equivalent to an unset TZ variable for mingw
and MSVC compiled programs, but not for Cygwin programs (which interpret it as
GMT). See APPENDIX 2 below.

Bruno


======= APPENDIX 1: Effects of Cygwin-set TZ on programs =========

$ ./showtime-cygwin.exe
now = 17286 17 157
  as GMT: 2017-04-30 17:02:37 dst=0
  as GMT: Sun Apr 30 17:02:37 2017
  as localtime: 2017-04-30 19:02:37 dst=1
  as localtime: Sun Apr 30 19:02:37 2017
tzname[0] = CET, tzname[1] = CEST

$ ./showtime-mingw.exe
now = 17286 17 175
  as GMT: 2017-04-30 17:02:55 dst=0
  as GMT: Sun Apr 30 17:02:55 2017
  as localtime: 2017-04-30 18:02:55 dst=1
  as localtime: Sun Apr 30 18:02:55 2017
tzname[0] = Eur, tzname[1] = ope

$ ./showtime-msvc.exe
now = 17286 17 234
  as GMT: 2017-04-30 17:03:54 dst=0
  as GMT: Sun Apr 30 17:03:54 2017
  as localtime: 2017-04-30 18:03:54 dst=1
  as localtime: Sun Apr 30 18:03:54 2017
tzname[0] = Eur, tzname[1] = ope


======= APPENDIX 2: Effects of unset TZ or empty TZ on programs =======

Cygwin: makes a difference

$ (unset TZ; ./showtime-cygwin.exe )
now = 17292 20 3383
  as GMT: 2017-05-06 20:56:23 dst=0
  as GMT: Sat May  6 20:56:23 2017
  as localtime: 2017-05-06 22:56:23 dst=1
  as localtime: Sat May  6 22:56:23 2017
tzname[0] = WEST, tzname[1] = WEST

$ TZ= ./showtime-cygwin.exe
now = 17292 20 3420
  as GMT: 2017-05-06 20:57:00 dst=0
  as GMT: Sat May  6 20:57:00 2017
  as localtime: 2017-05-06 20:57:00 dst=0
  as localtime: Sat May  6 20:57:00 2017
tzname[0] = GMT, tzname[1] =

mingw: no difference

$ (unset TZ; ./showtime-mingw.exe )
now = 17292 20 3395
  as GMT: 2017-05-06 20:56:35 dst=0
  as GMT: Sat May 06 20:56:35 2017
  as localtime: 2017-05-06 22:56:35 dst=1
  as localtime: Sat May 06 22:56:35 2017
tzname[0] = W. Europe Standard Time, tzname[1] = W. Europe Summer Time

$ TZ= ./showtime-mingw.exe
now = 17292 20 3426
  as GMT: 2017-05-06 20:57:06 dst=0
  as GMT: Sat May 06 20:57:06 2017
  as localtime: 2017-05-06 22:57:06 dst=1
  as localtime: Sat May 06 22:57:06 2017
tzname[0] = W. Europe Standard Time, tzname[1] = W. Europe Summer Time

msvc: no difference

$ (unset TZ; ./showtime-msvc.exe )
now = 17292 20 3401
  as GMT: 2017-05-06 20:56:41 dst=0
  as GMT: Sat May  6 20:56:41 2017
  as localtime: 2017-05-06 22:56:41 dst=1
  as localtime: Sat May  6 22:56:41 2017
tzname[0] = W. Europe Standard Time, tzname[1] = W. Europe Summer Time

$ TZ= ./showtime-msvc.exe
now = 17292 20 3431
  as GMT: 2017-05-06 20:57:11 dst=0
  as GMT: Sat May  6 20:57:11 2017
  as localtime: 2017-05-06 22:57:11 dst=1
  as localtime: Sat May  6 22:57:11 2017
tzname[0] = W. Europe Standard Time, tzname[1] = W. Europe Summer Time



--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: setting TZ is harmful
  2017-05-09 14:10 setting TZ is harmful Bruno Haible
@ 2017-05-09 14:41 ` Gluszczak, Glenn
  2017-05-09 16:39   ` Brian Inglis
  2017-06-06 15:05 ` Corinna Vinschen
  2017-06-06 16:51 ` Brian Inglis
  2 siblings, 1 reply; 5+ messages in thread
From: Gluszczak, Glenn @ 2017-05-09 14:41 UTC (permalink / raw)
  To: cygwin

Ran into issues with TZ in the past too.  ActiveState Perl is picky.

I use the PST8PDT format for TZ, but could be other Window programs that
won't accept that.


$ TZ="" date
Tue, May  9, 2017  2:02:50 PM

$ TZ="America/Los_Angeles" date
Tue, May  9, 2017  7:01:39 AM

$ TZ="PST8PEDT" date
Tue, May  9, 2017  7:01:49 AM


Cygwin Perl
=========
$ TZ="" perl -e "print scalar localtime(time);"
Tue May  9 13:59:57 2017

$ TZ="America/Los_Angeles" perl -e "print scalar localtime(time);"
Tue May  9 07:00:28 2017

$ TZ="PST8PDT" perl -e "print scalar localtime(time);"
Tue May  9 07:00:45 2017

ActiveState Perl
============
$ TZ="" ./perl -e "print scalar localtime(time);"
Tue May  9 07:06:06 2017

$ TZ="America/Los_Angeles" ./perl -e "print scalar localtime(time);"
Tue May  9 15:06:29 2017

$  TZ="PST8PDT" ./perl -e "print scalar localtime(time);"
Tue May  9 07:06:47 2017


Glenn


====================================================================
Hi,

Currently, all commands in a Cygwin command window are run with the TZ environment variable set.

It is set by /etc/profile.d/tzset.sh (or its csh equivalent, /etc/profile.d/tzset.csh).

Setting TZ is harmful in two ways:

  1) When the user changes the time zone (through the Windows Control Panel) -
     for example when traveling - the programs run in the Cygwin command
     window will display a stale notion of local time. Only after the user
     closes and re-opens a new Cygwin command window, will the programs
     display local time according to the new time zone.

  2) It causes native Windows programs (built through mingw, MSVC) to assume
     a time zone that is different from the intended one and different from
     the one that the user has set in the Windows Control Panel (see APPENDIX 1
     below). This is because in most geographies, the values of TZ (produced
     by winsup/utils/tzset.c and winsup/utils/tzmap.h) contains a slash, and
     the tzset() function in the Microsoft CRT does not understand this syntax
     - it understands only a different syntax
     https://msdn.microsoft.com/en-us/library/90s5c885.aspx .

When TZ is not set, both Cygwin and native Windows programs take their time zone information from the Windows Control Panel settings. See APPENDIX 2 below and https://lists.gnu.org/archive/html/bug-gnulib/2017-05/msg00035.html .

What are the benefits of setting the TZ environment variable? I don't see any!

===> Please remove /etc/profile.d/tzset.{sh,csh} ! <===

Side note: An empty TZ value is equivalent to an unset TZ variable for mingw and MSVC compiled programs, but not for Cygwin programs (which interpret it as GMT). See APPENDIX 2 below.

Bruno


======= APPENDIX 1: Effects of Cygwin-set TZ on programs =========

$ ./showtime-cygwin.exe
now = 17286 17 157
  as GMT: 2017-04-30 17:02:37 dst=0
  as GMT: Sun Apr 30 17:02:37 2017
  as localtime: 2017-04-30 19:02:37 dst=1
  as localtime: Sun Apr 30 19:02:37 2017 tzname[0] = CET, tzname[1] = CEST

$ ./showtime-mingw.exe
now = 17286 17 175
  as GMT: 2017-04-30 17:02:55 dst=0
  as GMT: Sun Apr 30 17:02:55 2017
  as localtime: 2017-04-30 18:02:55 dst=1
  as localtime: Sun Apr 30 18:02:55 2017 tzname[0] = Eur, tzname[1] = ope

$ ./showtime-msvc.exe
now = 17286 17 234
  as GMT: 2017-04-30 17:03:54 dst=0
  as GMT: Sun Apr 30 17:03:54 2017
  as localtime: 2017-04-30 18:03:54 dst=1
  as localtime: Sun Apr 30 18:03:54 2017 tzname[0] = Eur, tzname[1] = ope


======= APPENDIX 2: Effects of unset TZ or empty TZ on programs =======

Cygwin: makes a difference

$ (unset TZ; ./showtime-cygwin.exe )
now = 17292 20 3383
  as GMT: 2017-05-06 20:56:23 dst=0
  as GMT: Sat May  6 20:56:23 2017
  as localtime: 2017-05-06 22:56:23 dst=1
  as localtime: Sat May  6 22:56:23 2017 tzname[0] = WEST, tzname[1] = WEST

$ TZ= ./showtime-cygwin.exe
now = 17292 20 3420
  as GMT: 2017-05-06 20:57:00 dst=0
  as GMT: Sat May  6 20:57:00 2017
  as localtime: 2017-05-06 20:57:00 dst=0
  as localtime: Sat May  6 20:57:00 2017 tzname[0] = GMT, tzname[1] =

mingw: no difference

$ (unset TZ; ./showtime-mingw.exe )
now = 17292 20 3395
  as GMT: 2017-05-06 20:56:35 dst=0
  as GMT: Sat May 06 20:56:35 2017
  as localtime: 2017-05-06 22:56:35 dst=1
  as localtime: Sat May 06 22:56:35 2017 tzname[0] = W. Europe Standard Time, tzname[1] = W. Europe Summer Time

$ TZ= ./showtime-mingw.exe
now = 17292 20 3426
  as GMT: 2017-05-06 20:57:06 dst=0
  as GMT: Sat May 06 20:57:06 2017
  as localtime: 2017-05-06 22:57:06 dst=1
  as localtime: Sat May 06 22:57:06 2017 tzname[0] = W. Europe Standard Time, tzname[1] = W. Europe Summer Time

msvc: no difference

$ (unset TZ; ./showtime-msvc.exe )
now = 17292 20 3401
  as GMT: 2017-05-06 20:56:41 dst=0
  as GMT: Sat May  6 20:56:41 2017
  as localtime: 2017-05-06 22:56:41 dst=1
  as localtime: Sat May  6 22:56:41 2017 tzname[0] = W. Europe Standard Time, tzname[1] = W. Europe Summer Time

$ TZ= ./showtime-msvc.exe
now = 17292 20 3431
  as GMT: 2017-05-06 20:57:11 dst=0
  as GMT: Sat May  6 20:57:11 2017
  as localtime: 2017-05-06 22:57:11 dst=1
  as localtime: Sat May  6 22:57:11 2017 tzname[0] = W. Europe Standard Time, tzname[1] = W. Europe Summer Time



--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: setting TZ is harmful
  2017-05-09 14:41 ` Gluszczak, Glenn
@ 2017-05-09 16:39   ` Brian Inglis
  0 siblings, 0 replies; 5+ messages in thread
From: Brian Inglis @ 2017-05-09 16:39 UTC (permalink / raw)
  To: cygwin

On 2017-05-09 08:09, Gluszczak, Glenn wrote:
> Ran into issues with TZ in the past too. ActiveState Perl is picky.
> I use the PST8PDT format for TZ, but could be other Window programs
> that won't accept that.

Default rules used for that format in tzcode are those for pre-2007 
North America, until changes coming in the next tzcode release are 
incorporated into downstream libraries, when rules will default to 
post-2007 North America. 
Many libraries, including Cygwin, use their own implementations of 
some tzcode functions, so may use different rules, or not pick up 
code updates until years later. 
Better to set up an /etc/localtime symlink to zoneinfo/.../... for 
Cygwin and let Windows programs do their own thing, which may be 
neither currently nor historically correct.

-- 
Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: setting TZ is harmful
  2017-05-09 14:10 setting TZ is harmful Bruno Haible
  2017-05-09 14:41 ` Gluszczak, Glenn
@ 2017-06-06 15:05 ` Corinna Vinschen
  2017-06-06 16:51 ` Brian Inglis
  2 siblings, 0 replies; 5+ messages in thread
From: Corinna Vinschen @ 2017-06-06 15:05 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 2720 bytes --]

On May  9 15:37, Bruno Haible wrote:
> Hi,
> 
> Currently, all commands in a Cygwin command window are run with the TZ
> environment variable set.
> 
> It is set by /etc/profile.d/tzset.sh (or its csh equivalent,
> /etc/profile.d/tzset.csh).
> 
> Setting TZ is harmful in two ways:
> 
>   1) When the user changes the time zone (through the Windows Control Panel) -
>      for example when traveling - the programs run in the Cygwin command
>      window will display a stale notion of local time. Only after the user
>      closes and re-opens a new Cygwin command window, will the programs
>      display local time according to the new time zone.
> 
>   2) It causes native Windows programs (built through mingw, MSVC) to assume
>      a time zone that is different from the intended one and different from
>      the one that the user has set in the Windows Control Panel (see APPENDIX 1
>      below). This is because in most geographies, the values of TZ (produced
>      by winsup/utils/tzset.c and winsup/utils/tzmap.h) contains a slash, and
>      the tzset() function in the Microsoft CRT does not understand this syntax
>      - it understands only a different syntax
>      https://msdn.microsoft.com/en-us/library/90s5c885.aspx .
> 
> When TZ is not set, both Cygwin and native Windows programs take their time
> zone information from the Windows Control Panel settings. See APPENDIX 2
> below and https://lists.gnu.org/archive/html/bug-gnulib/2017-05/msg00035.html .
> 
> What are the benefits of setting the TZ environment variable? I don't
> see any!

If we don't do that the tzname variable contains gibberish, because the
only information we have is the Windows timezone info, and the content
is (who would expect that) non-standard.  See also
https://cygwin.com/ml/cygwin-developers/2012-01/msg00039.html
That's why we opted for always setting TZ.

> ===> Please remove /etc/profile.d/tzset.{sh,csh} ! <===
> 
> Side note: An empty TZ value is equivalent to an unset TZ variable for mingw
> and MSVC compiled programs, but not for Cygwin programs (which interpret it as
> GMT). See APPENDIX 2 below.

We're not striving for Windows compatibility, exactly.  What you
describe as problem is working the same way in glibc on Linux, see
https://linux.die.net/man/3/tzset:

  "If the TZ variable does appear in the environment,  but  its  value  is
   empty,  or  its  value  cannot  be interpreted using any of the formats
   specified below, then Coordinated Universal Time (UTC) is used.


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: setting TZ is harmful
  2017-05-09 14:10 setting TZ is harmful Bruno Haible
  2017-05-09 14:41 ` Gluszczak, Glenn
  2017-06-06 15:05 ` Corinna Vinschen
@ 2017-06-06 16:51 ` Brian Inglis
  2 siblings, 0 replies; 5+ messages in thread
From: Brian Inglis @ 2017-06-06 16:51 UTC (permalink / raw)
  To: cygwin

On 2017-05-09 07:37, Bruno Haible wrote:
> Currently, all commands in a Cygwin command window are run with the TZ
> environment variable set.
> It is set by /etc/profile.d/tzset.sh (or its csh equivalent,
> /etc/profile.d/tzset.csh).
> Setting TZ is harmful in two ways:
>   1) When the user changes the time zone (through the Windows Control Panel) -
>      for example when traveling - the programs run in the Cygwin command
>      window will display a stale notion of local time. Only after the user
>      closes and re-opens a new Cygwin command window, will the programs
>      display local time according to the new time zone.
>   2) It causes native Windows programs (built through mingw, MSVC) to assume
>      a time zone that is different from the intended one and different from
>      the one that the user has set in the Windows Control Panel (see APPENDIX 1
>      below). This is because in most geographies, the values of TZ (produced
>      by winsup/utils/tzset.c and winsup/utils/tzmap.h) contains a slash, and
>      the tzset() function in the Microsoft CRT does not understand this syntax
>      - it understands only a different syntax
>      https://msdn.microsoft.com/en-us/library/90s5c885.aspx .
> When TZ is not set, both Cygwin and native Windows programs take their time
> zone information from the Windows Control Panel settings. See APPENDIX 2
> below and https://lists.gnu.org/archive/html/bug-gnulib/2017-05/msg00035.html .
> What are the benefits of setting the TZ environment variable? I don't
> see any!

Windows TZ is not POSIX compliant:
http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html#tag_08_03
which allows up to TZNAME_MAX bytes from the portable character set in
the current locale and quoting using <> which allows alphanumeric, plus,
and minus characters from that set, e.g. TZ=<MSK+3>-6 instead of Asia/Omsk:

$ TZ='<MSK+3>-6' date -d2017-01-01 +%Z%z
MSK+3+0600
$ TZ=Asia/Omsk   date -d2017-01-01 +%Z%z
+06+0600
$ TZ='<MSK+3>-6' date -d2017-07-01 +%Z%z
MSK+3+0600
$ TZ=Asia/Omsk   date -d2017-07-01 +%Z%z
+06+0600

Now they have quoting, maybe they will consider allowing other
characters from the current locale e.g. UTF-8 <МСК+3>, which works with
Cygwin:

$ TZ='<МСК+3>-6' date -d2017-01-01 +%Z%z
МСК+3+0600
$ TZ='<МСК+3>-6' date -d2017-01-01 +%Z%z | cat -A
M-PM-^\M-PM-!M-PM-^Z+3+0600$

-- 
Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-06-06 16:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-09 14:10 setting TZ is harmful Bruno Haible
2017-05-09 14:41 ` Gluszczak, Glenn
2017-05-09 16:39   ` Brian Inglis
2017-06-06 15:05 ` Corinna Vinschen
2017-06-06 16:51 ` Brian Inglis

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).