Windows 7夏令时错误?

tjw*_*992 8 perl time dst windows-7 windows-7-x64

我正在尝试确定何时使用Perl localtime函数在Perl脚本中进行夏令时转换并使用打印时区strftime.

奇怪的是,这似乎适用于今年和其他近年来,但如果我尝试回到2000年,例如,Perl似乎认为过渡发生在错误的一天!

根据谷歌的说法,夏令时于2000年4月2日开始:

在此输入图像描述

...但由于某种原因,下面的Perl代码似乎不同意:

use POSIX qw(strftime);
use Time::Local;

# 03/12/2000 01:59:59
($year, $month, $day, $hour, $minute, $second) = (2000, 3, 12, 1, 59, 59);
$epoch = timelocal($second, $minute, $hour, $day, $month - 1, $year);

# Print the time
print strftime "%m/%d/%Y %H:%M:%S - %Z\n", localtime($epoch);

# 03/12/2000 02:00:00
($year, $month, $day, $hour, $minute, $second) = (2000, 3, 12, 2, 0, 0);
$epoch = timelocal($second, $minute, $hour, $day, $month - 1, $year);

# Print the time
print strftime "%m/%d/%Y %H:%M:%S - %Z\n", localtime($epoch);
Run Code Online (Sandbox Code Playgroud)

输出:

03/12/2000 01:59:59 - Eastern Standard Time
03/12/2000 03:00:00 - Eastern Daylight Time
Run Code Online (Sandbox Code Playgroud)

为什么Perl认为2000年的夏令时开始于3月12日,显然这是不正确的?


编辑:

阅读下面的评论后,看起来这可能是操作系统的问题,而不是Perl.看起来这可能是Windows 7中的一个错误.

Mat*_*int 3

我不知道 Perl 内部的细节(我也不想仔细研究源代码),但是在 Windows 上使用FileTimeToLocalFileTimeLocalFileTimeToFileTimeWin32 函数时通常会发生这样的错误。这些函数不考虑时区的历史,只考虑当前规则。该文档解释了该怎么做:

要在将文件时间转换为本地时间时考虑夏令时,请使用以下函数序列代替使用FileTimeToLocalFileTime

  1. 文件时间到系统时间
  2. 系统时间到Tz特定本地时间
  3. 系统时间到文件时间

TzSpecificLocalTimeToSystemTime对于中间步骤,应该对反函数执行类似的序列。

您运行的 Perl 版本可能会调用这些函数作为localtimetimelocal函数的 Win32 实现的一部分。根据问题中某些无法重现您的结果的评论,我猜测较新版本的 Perl 可能已按上述方式进行了修补。如果不是,他们应该是。(我相信更熟悉 Perl 内部结构的人可以指出具体的代码和错误报告。)