bug-gnulib
[Top][All Lists]
Advanced

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

Re: what shall we do with the drunken time_t ?


From: Bruno Haible
Subject: Re: what shall we do with the drunken time_t ?
Date: Sat, 29 Apr 2017 22:36:18 +0200
User-agent: KMail/5.1.3 (Linux/4.4.0-75-generic; KDE/5.18.0; x86_64; ; )

I had written:
> ================================ Results ===========================
> (I am in CEST, i.e. GMT+1 with DST since end of March.)
> 
> A file last touched on 2016-11-27 18:32 GMT:
> $ ls -l t.tar
> -rw-r--r-- 1 bruno None 10240 Nov 27 19:32 t.tar
> 
> Cygwin:
> mtime = 17132 18 1920
> as GMT: Sun Nov 27 18:32:00 2016         (correct)
> as localtime: Sun Nov 27 19:32:00 2016   (correct)
> 
> msvc:
> mtime = 17132 19 1920
> as GMT: Sun Nov 27 19:32:00 2016         (off by 1 h)
> as localtime: Sun Nov 27 19:32:00 2016   (correct)
> 
> mingw:
> mtime = 17132 20 1920
> as GMT: Sun Nov 27 20:32:00 2016         (off by 2 h)
> as localtime: Sun Nov 27 20:32:00 2016   (off by 1 h)
> 
> A file last touched on 2017-04-05 01:49 GMT:
> $ ls -l n.txt
> -rw-r--r-- 1 bruno None 93 Apr  5 03:49 n.txt
> 
> Cygwin:
> mtime = 17261 1 2961
> as GMT: Wed Apr  5 01:49:21 2017         (correct)
> as localtime: Wed Apr  5 03:49:21 2017   (correct)
> 
> msvc:
> mtime = 17261 2 2961
> as GMT: Wed Apr  5 02:49:21 2017         (off by 1 h)
> as localtime: Wed Apr  5 03:49:21 2017   (correct)
> 
> mingw:
> mtime = 17261 2 2961
> as GMT: Wed Apr 05 02:49:21 2017         (off by 1 h)
> as localtime: Wed Apr 05 03:49:21 2017   (correct)

Part of the confusion came from the facts that
  - I'm using Cygwin as development environment,
  - Cygwin defines the environment variable TZ, with value "Europe/Berlin"
    in my case [1],
  - the Microsoft CRT interprets TZ, but with a different expected syntax 
[2][3],
    which led to tzname[0] = "Eur", tzname[1] = "ope".

The problem is that an absent or empty TZ value means "GMT" for Cygwin,
whereas it means the timezone from the Windows Control Panel in native Windows.
There have been proposals that Cygwin should unset TZ when it invokes a native
Windows program [4][5], but it has not been implemented so far.

Here are updated results (the msvc and mingw programs run with empty TZ):
===============================================================================

With DST:
$ ls -l n.txt
-rw-r--r-- 1 bruno None 93 Apr  5 03:49 n.txt

Cygwin:
File n.txt mtime = 17261 1 2961           (correct)
  as GMT: Wed Apr  5 01:49:21 2017        (correct)
  as localtime: Wed Apr  5 03:49:21 2017  (correct)

msvc with empty TZ:
File n.txt mtime = 17261 1 2961           (correct)
  as GMT: Wed Apr  5 01:49:21 2017        (correct)
  as localtime: Wed Apr  5 03:49:21 2017  (correct)
msvc with Cygwin's TZ:
File n.txt mtime = 17261 2 2961           (off by 1 h)
  as GMT: Wed Apr  5 02:49:21 2017        (off by 1 h)
  as localtime: Wed Apr  5 03:49:21 2017  (correct)

mingw with empty TZ:
File n.txt mtime = 17261 1 2961           (correct)
  as GMT: Wed Apr 05 01:49:21 2017        (correct)
  as localtime: Wed Apr 05 03:49:21 2017  (correct)
mingw with Cygwin's TZ:
File n.txt mtime = 17261 2 2961           (off by 1 h)
  as GMT: Wed Apr 05 02:49:21 2017        (off by 1 h)
  as localtime: Wed Apr 05 03:49:21 2017  (correct)

Without DST:
$ ls -l t.tar
-rw-r--r-- 1 bruno None 10240 Nov 27 19:32 t.tar

Cygwin:
File t.tar mtime = 17132 18 1920          (correct)
  as GMT: Sun Nov 27 18:32:00 2016        (correct)
  as localtime: Sun Nov 27 19:32:00 2016  (correct)

msvc with empty TZ:
File t.tar mtime = 17132 18 1920          (correct)
  as GMT: Sun Nov 27 18:32:00 2016        (correct)
  as localtime: Sun Nov 27 19:32:00 2016  (correct)
msvc with Cygwin's TZ:
File t.tar mtime = 17132 19 1920          (off by 1 h)
  as GMT: Sun Nov 27 19:32:00 2016        (off by 1 h)
  as localtime: Sun Nov 27 19:32:00 2016  (correct)

mingw with empty TZ:
File t.tar mtime = 17132 19 1920          (off by 1 h)
  as GMT: Sun Nov 27 19:32:00 2016        (off by 1 h)
  as localtime: Sun Nov 27 20:32:00 2016  (off by 1 h)
mingw with Cygwin's TZ:
File t.tar mtime = 17132 20 1920          (off by 2 h)
  as GMT: Sun Nov 27 20:32:00 2016        (off by 2 h)
  as localtime: Sun Nov 27 20:32:00 2016  (off by 1 h)

===============================================================================

I'm still going to override stat() and fstat(), because
  - There are the unlucky Cygwin users like me.
  - Doing time zone sensitive computations for time_t is madness, and leads
    to the Notepad++ notifications when the user changes the time zone.
  - These rewrites of stat() and fstat() are the basis for future enhancements
    (struct timeval instead of time_t -> higher timestamp precisions,
    dev_t and ino_t, and symbolic links).

Bruno

[1] 
https://stackoverflow.com/questions/40350812/cygwin-shows-utc-time-instead-of-local-time
[2] https://msdn.microsoft.com/en-us/library/aa273389.aspx
[3] https://msdn.microsoft.com/en-us/library/90s5c885.aspx
[4] https://cygwin.com/ml/cygwin/2012-03/msg00048.html
[5] https://cygwin.com/ml/cygwin-patches/2012-q2/msg00007.html




reply via email to

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