再次关于“俄罗斯时区的时区信息不正确” [.Net bug,ID:693286]

同事们,下午好,我赶紧分享Java和.Net服务集成过程中出现的问题。为了清楚起见,我举一个例子:.Net服务从数据库中读取Date类型的数据,将其转换为long类型,然后将其传输到Java使用者端,在Java用户端从long中创建一个完整的java.util.Date实例。一切都会好起来,直到我们开始读取历史数据,也就是著名的取消向冬季或已有时间过渡之前的数据。.Net服务(在俄罗斯时区中)为“ 01/01/2010 13:00:00”传输日期(或更准确地说是长整数),并且在Java端,将java.util.Date实例创建为“ 01/01 / 2010 12:00:00。“ 一个小时内这个难以理解的区别从何而来?我们开始探索。

因此,Java代码:
public class Main {

    public static void main(String[] args) throws ParseException {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
        TimeZone tzMoscow = TimeZone.getTimeZone("Europe/Moscow");
        TimeZone tzLondon = TimeZone.getTimeZone("Europe/London");

        System.out.println("Before Medvedev tricks: " + calcTimeZoneShift(tzLondon, tzMoscow, "2010-01-01T13:00:00", format));
        System.out.println("After Medvedev tricks: " + calcTimeZoneShift(tzLondon, tzMoscow, "2013-01-01T13:00:00", format));
    }

    static private long calcTimeZoneShift(TimeZone tz1, TimeZone tz2, String time, SimpleDateFormat format)
            throws ParseException{

        format.setTimeZone(tz1);
        Date date1 = format.parse(time);

        format.setTimeZone(tz2);
        Date date2 = format.parse(time);
        return (date1.getTime() - date2.getTime())/3600000;

    };

}

Output:
Before Medvedev tricks: 3
After Medvedev tricks: 4


似乎一切都是事实:在梅德韦杰夫之前,伦敦与伦敦的冬季和夏季的差值为3点钟,但在梅德韦杰夫之后,冬季的差值为4小时。

什么使我们感到惊讶?

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            
            TimeZoneInfo tzMoscow = TimeZoneInfo.FindSystemTimeZoneById("Russian Standard Time");
            TimeZoneInfo tzLondon = TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time");
            
            System.Diagnostics.Debug.WriteLine("Before Medvedev tricks: " + calcTimeZoneShift(tzLondon, tzMoscow, "01/01/2010 13:00:00"));
            System.Diagnostics.Debug.WriteLine("After Medvedev tricks: " + calcTimeZoneShift(tzLondon, tzMoscow, "01/01/2013 13:00:00"));

        }

        private static long calcTimeZoneShift(TimeZoneInfo tz1, TimeZoneInfo tz2, String time)
        {
            DateTime date = DateTime.Parse(time);
            DateTime newTime = TimeZoneInfo.ConvertTime(date, tz1, tz2);
            return (newTime.ToFileTimeUtc() - date.ToFileTimeUtc()) / 36000000000;
        }

    }
}

Output:
Before Medevedev tricks: 4
After Medevedev tricks: 4


Mliiin,哇?!即,时区偏移结果与“之前”和“之后”相同。继续用谷歌搜索并找到

Incorrect time zone information for Russian time zones by

Type: Bug
ID: 693286
Opened: 10/5/2011 8:18:45 PM
Access Restriction: Public
Moderator Decision: Sent to Engineering Team for consideration

Time zone information for Russian time zones is incorrect. I think this occurs after Russian government disable summer time. Issue occurs then I converting date in the past from UST time zone to one of Russian time zones using routine TimeZoneInfo.ConvertTimeFromUtc
Actual results
UTC 13.06.2010 00:00:00 = Moscow 13.06.2010 5:00:00
UTC 13.12.2010 00:00:00 = Moscow 13.12.2010 4:00:00

Expected results
UTC 13.06.2010 00:00:00 = Moscow 13.06.2010 4:00:00
UTC 13.12.2010 00:00:00 = Moscow 13.12.2010 3:00:00


我们阅读了答案:

简而言之,该问题不是由.NET框架问题引起的。相反,它是由操作系统更新引起的,该更新影响了描述某些俄罗斯时区的注册表数据。背景是俄罗斯在同一年更改了时区及其基准时差和夏令时规则。


我拥有Windows 7的感觉如何,我拥有所有最新的Service Pack和最新版本的.Net,仍然无法解决2011年检测到的错误?好的,仅此而已(我在谈论how叫,并且一切在Java中都按“应有的方式”工作)...仅在读取历史数据时考虑到此错误。

All Articles