Emacs and Git show wrong time on Windows

Emacs is two hours from system time. I tried to solve the problem, but no luck. What do I need to configure to fix this? I suspect this is a difference from GMT to where I live (I am in GMT + 2 zone, that is, if I subtract from system time 2, I will find time in Emacs). So ... maybe some locale settings?

I just messed up the git repository because of this: I made use of Emacs through magit and put them in front of commits made by someone else :(

enter image description here

Here I added a screenshot showing the difference. The result from date is the correct time, but the time on the model fringe is incorrect.

EDIT0:

It seems that Stefan is right, and the time in git is not related to the time in Emacs (screenshot below from the Cygwin terminal).

This question has to do with git as Emacs - somehow they use some kind of system API that drops out of sync on my PC - and this is what I need to configure them on it. The question is, what are they both using?

enter image description here

EDIT1:

Here is the code that Emacs uses to extract time, afaik:

 /* Emulate gettimeofday (Ulrich Leodolter, 1/11/95). */ int gettimeofday (struct timeval *__restrict tv, struct timezone *__restrict tz) { struct _timeb tb; _ftime (&tb); tv->tv_sec = tb.time; tv->tv_usec = tb.millitm * 1000L; /* Implementation note: _ftime sometimes doesn't update the dstflag according to the new timezone when the system timezone is changed. We could fix that by using GetSystemTime and GetTimeZoneInformation, but that doesn't seem necessary, since Emacs always calls gettimeofday with the 2nd argument NULL (see current_emacs_time). */ if (tz) { tz->tz_minuteswest = tb.timezone; /* minutes west of Greenwich */ tz->tz_dsttime = tb.dstflag; /* type of dst correction */ } return 0; } 

And it looks like he is wrong tz . I don’t know what _ftime , but it does not seem to be defined in Emacs sources, this should come from other sources ...

Some more research:

SBCL installed from MSI gives the following:

 (defconstant *day-names* '("Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday" "Sunday")) (multiple-value-bind (second minute hour date month year day-of-week dst-p tz) (get-decoded-time) (format t "It is now ~2,'0d:~2,'0d:~2,'0d of ~a, ~d/~2,'0d/~d ( GMT~@d )" hour minute second (nth day-of-week *day-names*) month date year (- tz))) 

Exit: (actual time 12:56)

 It is now 10:56:55 of Tuesday, 6/04/2013 (GMT+0) 

Perl from ActivePerl (installed from Cygwin):

 $now = localtime; print $now; 

Output: (actual time 12:52)

 Tue Jun 4 12:52:17 2013 

CPython installed from MSI.

 import datetime str(datetime.datetime.now()) 

Output: (actual time 13:03)

 2013-06-04 11:03:49.248000 

JavaScript, Node.js installed from MSI:

 Date(); 

Exit: (Current time is 12:09)

 Tue Jun 04 2013 10:09:05 GMT+0000 (IST) 

Bash (Cygwin):

 $ date 

Output: (actual time 1:10 p.m.)

 04 Jun, 2013 13:10:37 

WITH#:

 using System; namespace TestTime { class Program { static void Main(string[] args) { DateTime d = DateTime.Now; Console.WriteLine("Today: {0}", d); Console.ReadLine(); } } } 

Output: (actual time 13:13)

 Today: 04-Jun-13 13:13:37 

EDIT2:

Today, our system administrator gave me a virtual machine to move my things. I wonder what happened that this time I got git through Cygwin, and now git is showing the correct times. However, Emacs still shows the wrong time. Python (and not the one associated with Cygwin) shows the correct time if it is running with Cygwin and erroneous time if it is running with Emacs! SBCL shows the wrong time no matter how it starts.

Is this possible in some network settings? Perhaps something has to do with how Windows synchronizes system time?

+4
source share
1 answer

Windows programs get time zone information from the system where you install it through the control panel. The time itself can also be set manually, but it is usually customary to synchronize Windows with time servers via the "Windows Time Service" (NTP-based; for use, see WinXP support article ). AFAIK The Windows Time Service has nothing to do with the time zone and is the only network-related thing related to the problem.

Cygwin programs should theoretically behave just like any other * NIX. They get timezone information from the /etc/localtime file or TZ environment variable . In my case (Debian) /etc/localtime is a copy of /usr/share/zoneinfo/Europe/Prague , but it could be a symbolic link pointing to this location. TZ can contain a path relative to /usr/share/zoneinfo and takes precedence over /etc/localtime .

Practice is a completely different story. According to the thread on the Cygwin mailing list , the Microsoft C runtime (mscrt * .dll) has extremely outdated timezone processing and is used for non-Cygwin programs. This is consistent with the results you get. Related technical information has been in the stream since August 2005 and related since May 2010 .

There is work for Python already hosted on SO and exactly the same for C ++ , which contains a more concise description of the MSCRT problem than previously associated threads.

Emacs may have something special about this issue. Posted February 2009 on the GNU Emacs Developer Mailing List . Emacs 22.3 displays the correct time, but Emacs 23 does not. Following the advice from the answer, the author publishes the report on the Cygwin mailing list - but does not receive the answer. December 2012, the problem is solved by documenting it and bypassing it (see /usr/share/doc/Cygwin/emacs.README ). I do not have Cygwin and I can not find this file in CVS, so please edit my answer with the information from there.

Personally, I believe that setting (and exporting) the TZ environment variable to your ~/.profile would be a good idea. Obviously, Cygwin violated the processing of the time zone, so redefining all related should be the safest thing, since it leaves only a small room for black magic. Maybe tzset will work, maybe this will not happen, and you will need to set the time zone to a constant value.

Try the search query for the β€œtime zone” on Cygwin.com for more resources.

+1
source

Source: https://habr.com/ru/post/1484043/


All Articles