[Mono-list] Re: System.TimeZone

Duncan Mak duncan@ximian.com
16 Feb 2002 13:31:55 -0500


On Sat, 2002-02-16 at 08:49, Dwivedi , Ajay Kumar wrote:
> hi Duncan,
> 	I took a look at the TimeZone.cs in the 15th Feb snapshot.
> Here are a few suggestions regarding the same.

Thanks for the patch you sent to the list earlier! I was going to merge
it in last night, but got too tired. ;-)

> 1. CurentTimeZone needs to return the TimeZone implementation
> (CurrentTimeZone class I sent in the earlier mail).

I've already merged in the skeleton of your CurrentTimeZone class to the
copy on my local machine and will commit after I've tested it. Only the
skeleton of the class could be merged, because some of those methods are
just stubbed out, sample implementations. I'll look into writing
internal calls sometimes next week and hopefully get those done then.
Internal calls need to be hooked up for proper implementation of:

    string DaylightName { get; }
    string NormalName { get; }
    
    DaylightTime GetDaylightChanges (int year);
    TimeSpan GetUtcOffset (DateTime time);

> 2. IsDaylightSavingTime (DateTime time) should call DaylightTime(DateTime
> time, DaylightTime daylightTimes) for return value.

Agreed. That patch is already merged in.

> 3. IsDaylightSavingTime needs to check the hemisphere in which the current
> timezone lies. The current implementation only assumes northern hemisphere.
> (Note that when it is summer in north, its winter in south)

I've been reading this portion of your patch for the past few days
trying to understand it. There must something that I'm not understanding
-- why does which hemisphere matter here? If timezone X in the north
starts DST from November to March, and April to August in the south,
then wouldn't the DaylightTime TimeSpan be different? Why do these
following checks here:

    if (daylightTimes.Start.Ticks < time.Ticks && 
        daylightTimes.End.Ticks > time.Ticks)
    
    if (daylightTimes.Start.Ticks > daylightTimes.End.Ticks)

I would think this is the responsibility of the internal CurrentTimeZone
class to return "correct" TimeSpans? (actually, this might be quite
difficult...)

There's also a check for:

    if (time.Year == daylightTimes.Start.Year && 
        time.Year == daylightTimes.End.Year)
    
At first, I thought this should be a good check, but then it seems like
the only way to get a DaylightTime object is to call GetDaylightChanges
(int year). So there shouldn't be a case where daylightTimes and time
mismatches, right? Hmm, and I just thought of this, couldn't the
TimeSpan of DST span across a year -- it starts November 2001 and ends
March 2002, for example.

I'm feeling really confused on this portion of the code, and I'd love to
understand what's going on before I commit it. I hope you would mind
explaining to me before committing it.

Thanks,

Duncan.