Web lists-archives.com

RE: setting TZ is harmful




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