Bug 1849 - TimeZoneInfo.ConvertTime gives wrong result when converting from UTC to UTC
Summary: TimeZoneInfo.ConvertTime gives wrong result when converting from UTC to UTC
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: System (show other bugs)
Version: 2.10.x
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2011-11-03 07:01 UTC by Norbert
Modified: 2015-06-08 04:01 UTC (History)
4 users (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
.cs version of my repro (2.12 KB, text/plain)
2012-06-13 21:12 UTC, pgentoo
Details

Description Norbert 2011-11-03 07:01:59 UTC
TimeZoneInfo.ConvertTime gives one hour difference when converting from UTC to UTC.

-----------------8<-----------------
public static void Main(string[] args) {

  TimeZoneInfo tziFrom = TimeZoneInfo.FindSystemTimeZoneById("UTC");
  TimeZoneInfo tziTo = TimeZoneInfo.FindSystemTimeZoneById("UTC");
  
  DateTime dateTime = new DateTime(2011, 11, 02, 
                                   18, 05, 00, 
                                   DateTimeKind.Unspecified);

  Console.Out.WriteLine("{0}/{1} --> {2}/{3}",
    dateTime,
    tziFrom,
    TimeZoneInfo.ConvertTime(dateTime, tziFrom, tziTo),
    tziTo);
}
-----------------8<-----------------

norbert@wks-norbert $ mono Foo.exe
02.11.2011 18:05:00/UTC --> 02.11.2011 17:05:00/UTC

The result should be the same as the input.

norbert@wks-norbert $ mono --version
Mono JIT compiler version 2.10.5 (tarball Mon Oct 31 21:18:17 CET 2011)
Copyright (C) 2002-2011 Novell, Inc, Xamarin, Inc and Contributors. www.mono-project.com
        TLS:           __thread
        SIGSEGV:       altstack
        Notifications: epoll
        Architecture:  amd64
        Disabled:      none
        Misc:          debugger softdebug 
        LLVM:          supported, not enabled.
        GC:            Included Boehm (with typed GC and Parallel Mark)

norbert@wks-norbert $ uname -a
Linux wks-norbert 3.0.6-gentoo #2 SMP PREEMPT Sat Oct 8 14:27:09 CEST 2011 x86_64 AMD Athlon(tm) 64 X2 Dual Core Processor 5000+ AuthenticAMD GNU/Linux
Comment 1 pgentoo 2012-06-13 20:59:57 UTC
I have another repro of this, with some sample code.  As you'll see, the conversion works from PST to EST, but then fails to work in reverse.  The code behaves as expected on Windows (under Microsoft runtime) but misbehaves on Linux/Mono.


REPRO CODE:
--------------------------------------------------------------------
TimeZoneInfo easternTimeZone = null;
            try
            {
                //for linux
                easternTimeZone = TimeZoneInfo.FindSystemTimeZoneById("US/Eastern");
            }
            catch
            {
                //for windows
                easternTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
            }
            Console.WriteLine("Eastern Time Zone created: " + easternTimeZone.Id);
            
            
            TimeZoneInfo pacificTimeZone = null;
            try
            {
                //for linux
                pacificTimeZone = TimeZoneInfo.FindSystemTimeZoneById("US/Pacific");
            }
            catch
            {
                //for windows
                pacificTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");
            }
            Console.WriteLine("Pacific Time Zone created: " + pacificTimeZone.Id);


            DateTime lastMidnight = new DateTime(DateTime.Now.Date.Ticks, DateTimeKind.Unspecified);
            Console.WriteLine("Last midnight is: " + lastMidnight.ToString());
            Console.WriteLine("Converting last midnight from PST to EST");
            DateTime lastMidnightAsEST = TimeZoneInfo.ConvertTime(lastMidnight, pacificTimeZone, easternTimeZone);
            Console.WriteLine("Last midnight in PST as EST should be 3AM, but is: " + lastMidnightAsEST);


       
            Console.WriteLine("Converting result back from PST to EST");
            DateTime lastMidnight2 = TimeZoneInfo.ConvertTime(lastMidnightAsEST, easternTimeZone, pacificTimeZone);
            Console.WriteLine("Last midnight in PST as EST as PST should be midnight, but is: " + lastMidnight2);

--------------------------------------------------------------------
OUTPUT IN WINDOWS:

Eastern Time Zone created: Eastern Standard Time
Pacific Time Zone created: Pacific Standard Time
Last midnight is: 6/13/2012 12:00:00 AM
Converting last midnight from PST to EST
Last midnight in PST as EST should be 3AM, but is: 6/13/2012 3:00:00 AM
Converting result back from PST to EST
Last midnight in PST as EST as PST should be midnight, but is: 6/13/2012 12:00:00 AM
--------------------------------------------------------------------
OUTPUT IN LINUX:
# mono -V
Mono JIT compiler version 2.10.8 (tarball Sat Apr 28 09:02:31 PDT 2012)
Copyright (C) 2002-2011 Novell, Inc, Xamarin, Inc and Contributors. www.mono-project.com
        TLS:           __thread
        SIGSEGV:       altstack
        Notifications: epoll
        Architecture:  amd64
        Disabled:      none
        Misc:          debugger softdebug
        LLVM:          supported, not enabled.
        GC:            Included Boehm (with typed GC and Parallel Mark)

# mono timezoneinforepro.exe
Eastern Time Zone created: US/Eastern
Pacific Time Zone created: US/Pacific
Last midnight is: 06/13/2012 00:00:00
Converting last midnight from PST to EST
Last midnight in PST as EST should be 3AM, but is: 06/13/2012 03:00:00
Converting result back from PST to EST
Last midnight in PST as EST as PST should be midnight, but is: 06/13/2012 03:00:00

---------------------------------------------------------------------
 # mono -V
Mono JIT compiler version 2.10.9 (tarball Wed May 23 22:22:48 PDT 2012)
Copyright (C) 2002-2011 Novell, Inc, Xamarin, Inc and Contributors. www.mono-project.com
        TLS:           __thread
        SIGSEGV:       altstack
        Notifications: epoll
        Architecture:  amd64
        Disabled:      none
        Misc:          debugger softdebug
        LLVM:          supported, not enabled.
        GC:            Included Boehm (with typed GC and Parallel Mark)

 # mono timezoneinforepro.exe
Eastern Time Zone created: US/Eastern
Pacific Time Zone created: US/Pacific
Last midnight is: 06/13/2012 00:00:00
Converting last midnight from PST to EST
Last midnight in PST as EST should be 3AM, but is: 06/13/2012 03:00:00
Converting result back from PST to EST
Last midnight in PST as EST as PST should be midnight, but is: 06/13/2012 03:00:00
Comment 2 pgentoo 2012-06-13 21:12:52 UTC
Created attachment 2055 [details]
.cs version of my repro
Comment 3 Bojan Rajkovic [MSFT] 2012-06-13 21:15:23 UTC
Here's the output on Mono 2.11.2, hash is master/901938b:

Eastern Time Zone created: US/Eastern
Pacific Time Zone created: US/Pacific
Last midnight is: 6/13/2012 12:00:00 AM
Converting last midnight from PST to EST
Last midnight in PST as EST should be 3AM, but is: 6/13/2012 12:00:00 AM
Converting result back from PST to EST
Last midnight in PST as EST as PST should be midnight, but is: 6/12/2012 9:00:00 PM
Comment 4 Marcin Cieślak 2015-06-08 04:01:57 UTC
Output with mono 4.3.0 master (afd7d742ab4b72645e3e9c70ed917e9b3f40fffe) on
FreeBSD, I only had to use "EST5EDT" and "PST8PDT" timezone, because FreeBSD does not have "US/* zones:

Eastern Time Zone created: EST5EDT
Pacific Time Zone created: PST8PDT
Last midnight is: 2015-06-08 00:00:00 and Kind is Unspecified
Converting last midnight from PST to EST
Last midnight in PST as EST should be 3AM, but is: 2015-06-08 03:00:00 and Kind is Unspecified
Converting result back from PST to EST
Last midnight in PST as EST as PST should be midnight, but is: 2015-06-08 00:00:00 and Kind is Unspecified
Eastern Time Zone created: EST5EDT
Pacific Time Zone created: PST8PDT
Last midnight is: 2015-06-08 00:00:00 and Kind is Unspecified
Converting last midnight from PST to EST
Last midnight in PST as EST should be 3AM, but is: 2015-06-08 03:00:00 and Kind is Unspecified
Converting result back from PST to EST
Last midnight in PST as EST as PST should be midnight, but is: 2015-06-08 00:00:00 and Kind is Unspecified

Also tried with "America/New_York" and "America/Los_Angeles":

Eastern Time Zone created: America/New_York
Pacific Time Zone created: America/Los_Angeles
Last midnight is: 2015-06-08 00:00:00 and Kind is Unspecified
Converting last midnight from PST to EST
Last midnight in PST as EST should be 3AM, but is: 2015-06-08 03:00:00 and Kind is Unspecified
Converting result back from PST to EST
Last midnight in PST as EST as PST should be midnight, but is: 2015-06-08 00:00:00 and Kind is Unspecified

I think this one got fixed.

Note You need to log in before you can comment on or make changes to this bug.