[Mono-dev] Time zone problems with DateTime.Parse (patch and bug)

Kornél Pál kornelpal at hotmail.com
Wed Sep 7 14:25:45 EDT 2005


The code that works with time zones is independent of the actual DST change
dates and offsets. This date change affects only the time zone database.

Kornél

----- Original Message -----
From: "Harry Holt" <harryholt at gmail.com>
To: <Mono-devel-list at lists.ximian.com>
Sent: Wednesday, September 07, 2005 8:13 PM
Subject: Re: [Mono-dev] Time zone problems with DateTime.Parse (patch and
bug)


Hmmm... Will the changes in daylight saving time for 2007+ (
http://aa.usno.navy.mil/faq/docs/daylight_time.html) have any affect on
this?

... HH

On 9/7/05, Atsushi Eno <atsushi at ximian.com> wrote:
>
> Hi,
>
> >>>> Test case:
> >>>> http://bugzilla.ximian.com/show_bug.cgi?id=75985
> >>>>
> >>>> I think the problem here is that the internal DateTime(bool,long)
> >>>> constructor calls tz.GetUtcOffset(this) with the UTC time to get the
> >>>> timezone offset before applying it to get local time, but that
> function
> >>>> expects a local time to determine if DST is active. A bit of a
> >>>> chicken-and-egg problem, perhaps... ;)
> >>>
> >>>
> >>> Agreed. But it seems possible to avoid that problem. Can you please
> >>> try attached patch? I don't have sane Unix environment and I'm
> >>> not in such region that has summer time ;-) It would be even nicer
> >>> if you try the entire corlib Nunit tests as well.
> >>
> >> Cool, that's definitely closer! Unfortunately it's still a bit off;
> >> during the doubled hour in the DST transition it's an hour off in the
> >> wrong direction. Using output from my test proggy on that bug:
> >
> > Okk, based on your help, I found some things. The most important one
> > is that there are different basis of TimeZone: UTC and local time
> > (there might be other patterns). now I think we need our own
> > TimeZone data store, that would store timezone names as well.
> >
> > At least DateTime.ToLocalTime() will be rewritten just to invoke
> > TimeZone.CurrentTimeZone.ToLocalTime(this).
> >
> > So, I'll revisit here later. Thanks for all your help, Brion :-)
>
> After some attempt (I think) I could fix TimeZone.ToLocalTime() for
> PST/PDT (the attached patch is for bug #75985). However, I have no
> better idea than that it just fixes offsets in that timezone, as
> I mentioned my concern about the basis difference (UTC or localtime).
>
> So I will have to dig into POSIX timezone design in depth.
> And apart from the matter above, I will still have to extend our
> locale-builder to support TimeZone name.
>
> Atsushi Eno
>
>
> Index: System/TimeZone.cs
> ===================================================================
> --- System/TimeZone.cs (revision 49638)
> +++ System/TimeZone.cs (working copy)
> @@ -108,27 +108,33 @@
>
> public virtual DateTime ToLocalTime (DateTime time)
> {
> -// return time + GetUtcOffset (time);
> - TimeSpan offset = GetUtcOffset (time);
> -
> - if (offset.Ticks > 0) {
> - if (DateTime.MaxValue - offset < time)
> + DaylightTime dlt = GetDaylightChanges (time.Year);
> + TimeSpan utcOffset = GetUtcOffset (time);
> + if (utcOffset.Ticks > 0) {
> + if (DateTime.MaxValue - utcOffset < time)
> return DateTime.MaxValue;
> - } else if (offset.Ticks < 0) {
> - // MS.NET <http://MS.NET> fails to check validity here
> - // - it may throw ArgumentOutOfRangeException
> - /*
> - if (DateTime.MinValue - offset > this)
> - return DateTime.MinValue;
> - */
> + //} else if (utcOffset.Ticks < 0) {
> + // LAMESPEC: MS.NET <http://MS.NET> fails to check validity here
> + // it may throw ArgumentOutOfRangeException.
> }
> -
> - DateTime lt = new DateTime (time.Ticks + offset.Ticks);
> - TimeSpan ltoffset = GetUtcOffset (lt);
> - if (ltoffset != offset)
> - lt = lt.Add (ltoffset.Subtract (offset));
>
> - return lt;
> + DateTime local = time.Add (utcOffset);
> + if (dlt.Delta.Ticks == 0)
> + return local;
> +
> + // FIXME: check all of the combination of
> + // - basis: local-based or UTC-based
> + // - hemisphere: Northern or Southern
> + // - offset: positive or negative
> +
> + // PST should work fine here.
> + if (local < dlt.End && dlt.End.Subtract (dlt.Delta) <= local)
> + return local;
> + if (local >= dlt.Start && dlt.Start.Add (dlt.Delta) > local)
> + return local.Subtract (dlt.Delta);
> +
> + TimeSpan localOffset = GetUtcOffset (local);
> + return time.Add (localOffset);
> }
>
> public virtual DateTime ToUniversalTime (DateTime time)
>
>
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>
>
>


--
====================================================
Robbie the Nanobot says:
"Only YOU can prevent gray goo
(NEVER release nanobot assemblers without replication limiting code)"
http://lizardslounge.org



--------------------------------------------------------------------------------


> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>




More information about the Mono-devel-list mailing list