Emacs和Git在Windows上显示错误的时间 [英] Emacs and Git show wrong time on Windows

查看:195
本文介绍了Emacs和Git在Windows上显示错误的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Emacs从系统时间开始是两个小时。我试图google的问题,但没有运气。需要配置哪些来纠正这个问题?我怀疑这是与格林尼治标准时间(GMT)的差异(我在格林尼治标准时间+2区,也就是说,如果从系统时间2减去,我将在Emacs中获得时间)。所以...也许这是一些区域设置?



我只是搞砸了一个git仓库,因为:通过 magit 使用Emacs时间,并将它们放在别人提交之前:(





这里,我添加了一个屏幕截图,显示了差异,日期是正确的时间,但是模型边缘的时间是错误的。



EDIT0: p>

似乎Stefan是对的,Git中的时间在Emacs中没有连接到时间(下面的截图来自Cygwin终端)。



这个问题与Emacs的Git有关,不知何故,他们正在使用一些在我的PC上不同步的系统API,这就是我需要设置的对齐方式。问题是他们使用的是什么设置?



$

EDIT1:



这是Emacs用来检索时间的代码,afaik:

  / *模拟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;
/ *实现注意:当系统时区为
更改时,_ftime有时根据新的时区更新dstflag
。我们可以通过使用GetSystemTime和
GetTimeZoneInformation来解决这个问题,但这似乎不是必需的,因为
Emacs总是使用第二个参数NULL调用gettimeofday(参见
current_emacs_time)。 * /
if(tz)
{
tz-> tz_minuteswest = tb.timezone; / *格林威治以西* /
tz-> tz_dsttime = tb.dstflag; / * dst校正类型* /
}
返回0;
}

它看起来像 tz 错了。我不知道什么 _ftime 是 - 但它似乎没有在Emacs的来源定义,这必须来自其他地方...



更多研究:



从MSI安装的SBCL给出了这一点:

 (defconstant * day-names * 
'(星期一星期二星期三
星期四星期五星期六星期日))
(multiple-value-bind
(第二分钟小时日期月份日周日dst-p tz)
-decoded-time)
(格式t现在〜2,'0d:〜2,'0d:〜2,'0d的〜a,〜d /〜2,'0d /〜d 〜@ d)
小时分钟秒(nth星期*天名*)
月日期年( - tz)))

输出:(实际时间为12:56)

 现在是星期二,6/04/2013(GMT + 0)的$ 10:56:55 

来自ActivePerl的Perl(从Cygwin安装):

  $ now = localtime; 
打印$现在;

输出:(实际时间为12:52)

  Tue Jun 4 12:52:17 2013 

从MSI安装的CPython。

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

输出:(实际时间为13 :03)

  2013-06-04 11:03:49.248000 

从MSI安装的JavaScript,Node.js:

 日期(); 

输出:(实际时间为12:09)

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

Bash(Cygwin):

  $ date 

输出:(实际时间为13:10) p>

  2013年6月4日13:10:37 

C#:

  using System; 

命名空间TestTime
{
类程序
{
static void Main(string [] args)
{
DateTime d = DateTime.Now;
Console.WriteLine(今日:{0},d);
Console.ReadLine();
}
}
}

输出:实际时间是13:13)

 今天:04-Jun-13 13:13:37 

EDIT2:



今天我们的系统管理员给了我一个虚拟机来移动我的东西。有趣的是,发生了什么事情,这次我通过Cygwin得到Git,现在Git显示正确的时间。然而,Emacs仍然显示错误的时间。 Python(而不是与Cygwin捆绑在一起)显示正确的时间,如果从Cygwin启动,如果从Emacs启动,错误的时间! SBCL显示错误的时间,无论如何启动。



这可能是一些网络设置?可能与Windows如何同步系统时间有关?

解决方案

Windows程序从您通过控件设置的系统获取时区信息面板。时间本身也可以手动设置,但通常情况下,让Windows与时间服务器通过 Windows时间服务(基于NTP);有关使用情况,请参阅 WinXP支持文章)。 AFAIK Windows时间服务与时区无关,是与问题有关的唯一与网络相关的事情。



Cygwin程序在理论上应与任何方式相同其他* NIX。他们从 / etc / localtime 文件 TZ 环境中获取时区信息变量即可。在我的情况下(Debian), / etc / localtime / usr / share / zoneinfo / Europe / Prague ,但它可能是一个指向该位置的符号链接。 TZ 可以包含相对于 / usr / share / zoneinfo 的路径,优先于 / etc / localtime



实践是一个不同的故事。根据 Cygwin邮件列表中的一个线程,Microsoft C runtime(mscrt * .dll)具有非常过时的时区处理功能,用于非Cygwin程序。这与您获得的结果一致。相关技术信息位于从2005年8月的线程与2010年5月相关的一个



有一个解决Python 已经发布在SO和完全相同C ++ ,它比以前链接的线程对MSCRT问题有一个更简要的解释。



也许Emacs有一些特别的问题。 2009年2月的GNU Emacs开发者邮件列表消息报告Emacs 22.3显示正确的时间,而Emacs 23不。根据回覆的建议,作者发布了报告给Cygwin邮件列表 - 但没有回复。 2012年12月该问题已通过文档化及其解决方法解决(见 /usr/share/doc/Cygwin/emacs.README )。我没有Cygwin,在CVS中找不到这个档案,所以请用这个信息编辑我的答案。



个人我认为您的〜/ .profile 中的设置(和导出)TZ环境变量将是一个好主意。 Cygwin显然已经破坏了时区处理,所以超越所有相关的应该是最安全的事情,因为它留下了一个黑色的魔法空间。也许 tzset 将工作,也许它不会,你将不得不将您的时区设置为一个恒定的值。



尝试 Google Cygwin.com 上的时区,以获得更多资源。


Emacs is two hours off from the system time. I tried to google for the problem, but no luck. What do I need to configure to correct this? I suspect this to be the difference from GMT to where I live (I'm in GMT+2 zone, that is, if I subtract from system time 2, I'll get the time in Emacs). So... maybe it's some locale settings?

I just messed up a git repository because of that: commits made through magit used Emacs time, and placed them before the commits made by someone else :(

Here, I've added a screenshot showing the difference. The output from the date is the correct time, but the time on the modeline fringe is wrong.

EDIT0:

It appears Stefan is right, and the time in Git is not connected to time in Emacs (the screenshot below is from Cygwin terminal).

This question is as relevant to Git as it is to Emacs - somehow they are using some system API that falls out of sync on my PC - and that is something I need to set up to align them on it. The question is what is that setting they both use?

EDIT1:

Here's the code that Emacs uses to retrieve the 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 it gets tz wrong. I don't know what _ftime is - but it doesn't seem to be defined in Emacs' sources, this must come from elsewhere...

Some more research:

SBCL installed from MSI gives this:

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

Output: (actual time is 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 is 12:52)

Tue Jun  4 12:52:17 2013

CPython, installed from MSI.

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

Output: (actual time is 13:03)

2013-06-04 11:03:49.248000

JavaScript, Node.js, installed from MSI:

Date();

Output: (actual time is 12:09)

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

Bash (Cygwin):

$ date

Output: (actual time is 13:10)

04 Jun, 2013 13:10:37

C#:

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 is 13:13)

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

EDIT2:

Today our sysadmin gave me a VM to move my stuff to. Interestingly, what happened there is that this time I got Git through Cygwin, and now Git shows correct times. Emacs, however, still shows wrong time. Python, (not the one bundled with Cygwin) shows correct time if launched from Cygwin and wrong time if launched from Emacs! SBCL shows wrong time no matter how it is launched.

Is it possible this is some network setting? Perhaps something to do with how Windows synchronizes system time?

解决方案

Windows programs get timezone info from the system where you set it via control panel. Time itself can be set manually too, but it is more usual to let Windows synchronize with time servers via Windows Time Service (NTP-based; for usage see WinXP support article). AFAIK Windows Time Service has nothing to do with timezone and is the only network-related thing involved in the problem.

Cygwin programs should in theory behave the same way as on any other *NIX. They get the timezone information from /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 symlink pointing to that location as well. TZ can contain path relative to /usr/share/zoneinfo and takes precedence over /etc/localtime.

Practice is a different story. According to a thread on Cygwin mailing list, Microsoft C runtime (mscrt*.dll) has extremely outdated timezone handling and it is used for non-Cygwin programs. This is consistent with the results you are getting. Related technical info is in a thread from August 2005 and a related one from May 2010.

There is a work-around for Python already posted on SO and exactly the same for C++, which has a more brief explanation of the MSCRT problem than the previously linked threads.

Maybe Emacs has something special to do with the issue. A February 2009 message on GNU Emacs developers mailing list reports Emacs 22.3 displays correct time while Emacs 23 not. Following advice from a reply, the author posts the report to Cygwin mailing list – but gets no reply. December 2012 the issue is solved by docummenting it and its workaround (see /usr/share/doc/Cygwin/emacs.README). I don't have Cygwin and cannot find this file in its CVS, so please edit my answer with the info from there.

Personally I think that setting (and exporting) TZ environment variable in your ~/.profile would be a good idea. Cygwin obviously has broken timezone handling, so overriding everything related should be the safest thing to do as it leaves just a little room for black magic. Maybe tzset will work, maybe it won't and you'll have to set your timezone to a constant value.

Try googling for „timezone" at Cygwin.com for more resources.

这篇关于Emacs和Git在Windows上显示错误的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆