public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Re: Python for Windows reports wrong local time when run under Cygwin on Europe/Moscow TZ
@ 2021-06-08 17:37 Keith Thompson
  2021-06-09  3:43 ` Brian Inglis
  2021-06-09 22:31 ` Keith Thompson
  0 siblings, 2 replies; 29+ messages in thread
From: Keith Thompson @ 2021-06-08 17:37 UTC (permalink / raw)
  To: cygwin; +Cc: Keith Thompson

There is a known problem with the $TZ environment variable.

Here's a discussion from 2017:
https://cygwin.com/pipermail/cygwin/2017-May/232675.html

The problem is that both Cygwin and Windows use the $TZ environment
variable, but they interpret it differently.

The Windows handling of $TZ (or %TZ%) is documented here:
https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/tzset?view=msvc-160

For example, Pacific Time is represented as TZ=PST8PDT.

In Cygwin, my $TZ is set by default to "America/Los_Angeles".
Any Windows applications that I invoke from Cygwin, if they attempt
to determine the time zone, will behave inconsistently because they
don't see "America/Los_Angeles" as a valid time zone string.

I've worked around this by unsetting TZ in my .bash_profile .
Cygwin applications are still able to determine the correct time zone.

I suggest that Cygwin should *not* set the TZ environment variable.

^ permalink raw reply	[flat|nested] 29+ messages in thread
* Python for Windows reports wrong local time when run under Cygwin on Europe/Moscow TZ
@ 2021-06-07  6:59 Mike Kaganski
  2021-06-08  4:34 ` Russell VT
  2021-06-08 11:37 ` L A Walsh
  0 siblings, 2 replies; 29+ messages in thread
From: Mike Kaganski @ 2021-06-07  6:59 UTC (permalink / raw)
  To: cygwin

Hello,

Running Cygwin 3.1.7-1 on Windows 10 Version 21H1 (OS Build 19043.985), 
I have this issue:

when I start Cygwin's Python, I have correct time reported:

> mikek@DESKTOP-8SHAE9Q ~
> $ python
> Python 3.8.9 (default, Apr 21 2021, 23:14:29)
> [GCC 10.2.0] on cygwin
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import datetime
> >>> datetime.datetime.now()
> datetime.datetime(2021, 6, 7, 9, 40, 15, 318391)

But running Python for Windows (it doesn't matter which, specifically 
for the test I used the one from MS Store [1]), I have incorrect local time:

> mikek@DESKTOP-8SHAE9Q ~
> $ "C:/Program 
> Files/WindowsApps/PythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0/python3.8.exe"
> Python 3.8.10 (tags/v3.8.10:3d8993a, May  3 2021, 11:48:03) [MSC 
> v.1928 64 bit (AMD64)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import datetime
> >>> datetime.datetime.now()
> datetime.datetime(2021, 6, 7, 7, 40, 55, 503775)

Note how the latter output reports 2021-06-07 07:40, while the former 
reports 2021-06-07 09:40. The difference is 2 hours.

Starting the same Python for Windows from cmd.exe has it correct:

> C:\Users\mikek>python
> Python 3.8.10 (tags/v3.8.10:3d8993a, May  3 2021, 11:48:03) [MSC 
> v.1928 64 bit (AMD64)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import datetime
> >>> datetime.datetime.now()
> datetime.datetime(2021, 6, 7, 9, 41, 21, 925240)

Cygwin reports correct timezone:

> $ echo $TZ
> Europe/Moscow

Starting Python for Windows using a different timezone (specifically, '$ 
TZ=UTC "C:/Program 
Files/WindowsApps/PythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0/python3.8.exe"') 
gives correct time for *that* time zone.

This is a problem, because in our project (LibreOffice), we use Cygwin 
as environment for unit testing, where LibreOffice's own Python (also 
built natively for Windows) is used, and at some times (from 00:00 till 
02:00) it reports wrong dates, which makes tests fail locally on 
affected systems(see [2]).

Thank you!


[1] https://www.microsoft.com/en-us/p/python-38/9mssztt1n39l

[2] 
https://gerrit.libreoffice.org/c/core/+/92217/2#message-f55091795e7cde9d75adc00ddb69451121b644f6


-- 

Best regards,

Mike Kaganski


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

end of thread, other threads:[~2021-06-12 22:44 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-08 17:37 Python for Windows reports wrong local time when run under Cygwin on Europe/Moscow TZ Keith Thompson
2021-06-09  3:43 ` Brian Inglis
2021-06-09 22:31 ` Keith Thompson
2021-06-10  2:36   ` Brian Inglis
2021-06-10 14:57     ` Ken Brown
2021-06-10 15:25       ` KAVALAGIOS Panagiotis (EEAS-EXT)
2021-06-10 18:31       ` Brian Inglis
2021-06-10 19:50         ` Ken Brown
2021-06-11  5:38           ` ASSI
2021-06-11 13:38             ` Ken Brown
2021-06-11 17:33           ` Brian Inglis
2021-06-11 18:05             ` Ken Brown
2021-06-12 16:34               ` Brian Inglis
2021-06-12 22:44                 ` Ken Brown
2021-06-11 10:51     ` Andrey Repin
  -- strict thread matches above, loose matches on Subject: below --
2021-06-07  6:59 Mike Kaganski
2021-06-08  4:34 ` Russell VT
2021-06-08  7:51   ` Mike Kaganski
2021-06-08 11:37 ` L A Walsh
2021-06-08 12:28   ` Mike Kaganski
2021-06-08 13:04     ` L A Walsh
2021-06-08 13:30       ` Mike Kaganski
2021-06-08 13:57         ` L A Walsh
2021-06-08 14:10           ` Mike Kaganski
2021-06-08 14:15             ` L A Walsh
2021-06-08 13:36       ` Mike Kaganski
2021-06-08 20:03       ` Mike Kaganski
2021-06-09  5:50         ` Brian Inglis
2021-06-11  6:01   ` Mike Kaganski

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