Re: System.TimeZone interface unusable?
- From: "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@xxxxxxxxxxxxx>
- Date: Tue, 27 Dec 2005 19:30:07 -0600
| ToLocalTime must be "A DateTime instance whose value is the local time
| that corresponds to time... Local time is the date and time on the
| computer you are using." Therefore, overriding ToLocalTime to return
| anything other than machine local time breaks the contract forI
I interpret "local time" as local to the "current" Time Zone. Currently
"current" Time Zone is TimeZone.CurrentZone. If you create a TimeZone object
then that object is the "current" Time Zone.
Although I agree with the gest of your comments. The documentation is
misleading, so the method cannot be truely implemented correctly.
| The definition of Local throughout MSDN still seems to be machine local
Ah! There's the rub! "seems to be", "local time" really needs to be defined
better in relation to what, especially when you start deriving classes...
--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
<nosiren@xxxxxxxxx> wrote in message
news:1135694003.995396.12920@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
| Hi Jay,
|
| Thanks for the reply.
|
| > Using ILDASM, it appears that TimeZone.ToLocalTime in .NET 2.0 is hard
wired
| > to a concrete implementation class. IMHO a very bad no no in OO.
|
| My thoughts exactly.
|
| > You should be able to override TimeZone.ToLocalTime itself and have the
| > behavior you expect.
|
| I would say this is true, but I have to consider the contract of the
| base class. According to the MSDN documentation, the return value of
| ToLocalTime must be "A DateTime instance whose value is the local time
| that corresponds to time... Local time is the date and time on the
| computer you are using." Therefore, overriding ToLocalTime to return
| anything other than machine local time breaks the contract for
| ToLocalTime, and will cause incorrect results for someone expecting the
| documented base class behavior.
|
| > The quirk/caveat is going to be what to do with DateTimeKind.Local on
input
| > to MyTimeZone.ToLocalTime. My sample only allows Utc or Unspecified date
| > time values, as the parameter states "a UTC time". Considering that the
time
| > parameter maybe in a different time zone then the this time zone, IMHO
the
| > exception is the "better" choice. Alternative if the input is already
Local
| > then one could simply return it "As is", as its already local...
|
| The definition of Local throughout MSDN still seems to be machine local
| time, so although there are problems as you have specified, they are
| different than you have mentioned. Most notably, any DateTime that is
| not UTC or machine local time must have a Kind of
| DateTimeKind.Unspecified. Regardless, it seems perfectly sensible for
| ToLocalTime() to assume a UTC parameter and for ToUniversalTime() to
| take a "native time" parameter (avoiding the phrase "local time" for
| obvious reasons). Personally, I suspect that the addition of
| DateTime.Kind to the framework was not for the benefit of the TimeZone
| class at all.
|
| It's my understanding that, prior to .NET 2.0, the XML Serializer made
| the fundamentally flawed assumption that all outoing dates were in
| machine local time and all incoming dates were in UTC. Since the
| serializer documentation is the only other place the Kind property is
| mentioned, I have to conclude that DateTime, a core component of the
| framework IMHO, has been hijacked to fix mistakes made in the XML
| Serializer. If that is true, then this really is a nasty little hack.
| Even the new documentation for DateTime reads like raw hackery: "Prior
| to the .NET Framework version 2.0, the DateTime structure contains a
| 64-bit field composed of an unused 2-bit field concatenated with a
| private Ticks field." You can almost hear Jon Lovitz saying, "I meant
| to do that... yeah, that's the ticket."
|
| As it stands, I've pretty much concluded that the documented interface
| for System.TimeZone is fundamentally broken, and am moving on with my
| own base class with a similar interface but a more sensible contract.
|
| Thanks,
|
| Russ
|
.
- References:
- System.TimeZone interface unusable?
- From: nosiren
- Re: System.TimeZone interface unusable?
- From: Jay B. Harlow [MVP - Outlook]
- Re: System.TimeZone interface unusable?
- From: nosiren
- System.TimeZone interface unusable?
- Prev by Date: Re: Open a port for local access only
- Next by Date: DataGridView (.NET 2.0 Control) question about formatting
- Previous by thread: Re: System.TimeZone interface unusable?
- Next by thread: .NET Remoting Bug - fixed in 1.0 SP3?
- Index(es):
Relevant Pages
|