Re: Rotor Bug: TimeZone ToLocalTime

From: Justin Rogers (Justin_at_games4dotnet.com)
Date: 11/03/04


Date: Wed, 3 Nov 2004 02:20:43 -0800

Did you do a round trip test?

using System;

public class RoundTripDateTime {
    private static void Main(string[] args) {
        DateTime realNow = DateTime.Now;
        DateTime utc = realNow.ToUniversalTime();
        DateTime now = utc.ToLocalTime();

        Console.WriteLine(realNow);
        Console.WriteLine(utc);
        Console.WriteLine(now);
    }
}

Or are you just basing this on a code examination? Having looked at the
code myself, GetUtcOffset doesn't depend on the time at all. It instead gets
all of the information from the time zone about how to offset the times.

So apparently, the real bug would be that turning an already local time
into a local time fails, but not converting a utc date into a local date. In
effect
the reverse is the actual reverse.

Note that in Whidbey, there are immense changes that make this *work*.
Each date stores a kind, and the calculations are based on this kind. In
this manner any time should be able to be converted into a real local time
or a real UTC time no matter what time zone you are in.

-- 
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers
"Todd Bandrowsky" <tbandrow@mightyware.com> wrote in message 
news:d43b6e1.0411021100.159c16d6@posting.google.com...
> The following snippet is from CurrentTimeZone in Rotor.
>
> //
>        // Converts the specified datatime to the Universal time base
> on the current timezone
>        //
>        /// <include file='doc\TimeZone.uex'
> path='docs/doc[@for="TimeZone.ToUniversalTime"]/*' />
>        public virtual DateTime ToUniversalTime(DateTime time) {
>            return (time - GetUtcOffset(time));
>        }
>
>        //
>        // Convert the specified datetime value from UTC to the local
> time based on the time zone.
>        //
>        /// <include file='doc\TimeZone.uex'
> path='docs/doc[@for="TimeZone.ToLocalTime"]/*' />
>        public virtual DateTime ToLocalTime(DateTime time) {
>            return (time + GetUtcOffset(time));
>        }
>
> ToLocalTime is incorrect, because the call for GetUtcOffset specifies
> a date already in local time, not UTC.  As a result, the calls to
> ToLocalTime and ToUniversalTime are not inverse operations.
>
> Todd Bandrowsky
> tbandrow@mightyware.com 


Relevant Pages

  • Re: Network Time Protocol (NTP) client support question
    ... compensating adjustment to the time zone offset. ... The whole point of using UTC time stamps is to avoid issues ... fudging the local time offset fails to satisfy it. ...
    (bit.listserv.ibm-main)
  • Re: convert time string in UTC to time in local time
    ... I have a time stamp that looks like this (corresponding to UTC time): ... I want to convert it to my local time. ... time zone magic to treat the supplied time as a local time, ... UTC time - this seems to be an artifact of the way mktime is defined ...
    (comp.lang.python)
  • Re: How to compare DateTime Objects?
    ... If the server records in GMT ... It does not matter what time zone the ... server is actually in as long as it records in UTC. ... display based on their local time. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Problems with the Timezone
    ... it UTC - 4 hours) then you must set the TZ environment variable to GMT4 ... the abbreviation of the time zone name since it implies that the displayed ... associated to what you call your local time zone. ...
    (comp.protocols.time.ntp)
  • Re: WMI LastBootUpTime wrong value
    ... To convert to local time you need to adjust using ... the time zone bias stored in the local registry. ... ' Obtain local Time Zone bias from machine registry. ...
    (microsoft.public.scripting.vbscript)