Re: Finding the offset of a specific time zone

Eddie Lascu <[email protected]> Wed, 25 Mar 2009 15:32:27 -0400
Newsgroups gmane.comp.windows.devel.dotnet.advanced
Organization IBI Group
Message-ID <[email protected]>
 
Your point is a valid one. However, the devices I am talking about are speed
detectors deployed all over California's highways. I am pretty sure they
will not move on a different time zone. If and when California decides to
move the entire state to a different time zone, all I have to do is to
indicate that new time zone in my configuration file.

Again, I agree with your point that ideally would be to have the client send
in all those time stamps as UTC. The problem is that they may not be willing
to do the effort and change it. From my experience so far, they tend not to
be too responsive, every time we are asking for something.

Regards,
Eddie



-----Original Message-----
From: Discussion of advanced .NET topics.
[mailto:[email protected]] On Behalf Of Peter Ritchie
Sent: Wednesday, March 25, 2009 2:19 PM
To: [email protected]
Subject: Re: [ADVANCED-DOTNET] Finding the offset of a specific time zone

You're going to have a mismatch from the server to the clients.  You're
making an assumption as to the location of each client.  The recommended
solution is that each of the clients send the date/time in UTC format.  If
one of those clients moves to a different timezone and the server doesn't
know about it in time; you've got corrupted data.  This, of course, assumes
the server is tracking where the clients are--it sounds like you've simply
made the assumption that their all in PST.  If you're trying to design
something on the server that can accomodate the server moving from timezone
to timezone; it stands to reason you want the same for clients moving from
timzezone to timezone.  Tracking that at the server doesn't smell right.  I
don't think it's the responsiblity of the server to know that information
(i.e. the client *must* know, so let it deal with it); especially in terms
of a web service.

If you do the conversion from local to UTC before the data is sent to the
web service, you never have to deal with the TimeZoneInfo class, it's a
single call to ToUniversalTime before sending the data.

Personally, I think doing it right is a better than taking care of business.

-- Peter

On Wed, 25 Mar 2009 13:31:23 -0400, Eddie Lascu <[email protected]> wrote:

>The Web Service that sends me those time stamps could do it, but I am 
>not sure the client is willing to go through that exercise. Rather than 
>wait for them to decide and come up with a cost estimate, a risk factor 
>and the general impact on the overall project, I better take care of 
>business myself.
>
>Eddie
>
>
>
>-----Original Message-----
>From: Discussion of advanced .NET topics.
>[mailto:[email protected]] On Behalf Of Michael Levy
>Sent: Wednesday, March 25, 2009 1:28 PM
>To: [email protected]
>Subject: Re: [ADVANCED-DOTNET] Finding the offset of a specific time 
>zone
>
>Can the devices be reconfigured to use UTC instead of the local time?
>
>-Mike
>
>On Wed, Mar 25, 2009 at 12:59 PM, Eddie Lascu <[email protected]> wrote:
>
>>
>> Peter,
>>
>> Everything you said, I already figured it out and it's not helping me.
>>
>> Again, a time stamp coming from the field device belongs to a 
>> different time zone, so using "ToUniversalTime" will give me the 
>> wrong result because "ToUniversalTime" assumes the time is local 
>> which is not the case. I explained that the field devices and the 
>> server that runs my application are in different time zones.
>>
>> On the other hand, I found a class that mimics what TimeZoneInfo does 
>> in .NET 3.5. Incidentally, it is also called TimeZoneInfo. You can 
>> get it
>> here:
>>
>> http://www.codeproject.com/KB/vb/TimeZoneInfo.aspx
>>
>> With that, I can instantiate an object of type TimeZoneInfo for 
>> Pacific Time (this would be the only parameter that I need to keep in 
>> my configuration
>> file: the name of the time zone where the field devices are located).
>> Having
>> that object (which is built based on available time zone information 
>> from the subkeys of the registry's 
>> HKEY_LOCAL_MACHINE\Software\Microsoft\Windows
>> NT\CurrentVersion\Time Zones key), I can ask what is the Current Time 
>> Offset and that is the offset I need to add to the values that come 
>> from the field devices in order to obtain the correct UTC.
>>
>> Thank you everyone for pitching in with your ideas.
>>
>> Regards,
>> Eddie
>>
>>
>>
>> -----Original Message-----
>> From: Discussion of advanced .NET topics.
>> [mailto:[email protected]] On Behalf Of Peter 
>> Ritchie
>> Sent: Wednesday, March 25, 2009 12:44 PM
>> To: [email protected]
>>  Subject: Re: [ADVANCED-DOTNET] Finding the offset of a specific time 
>> zone
>>
>> You can use DateTime.UtcNow to get the current time in UTC.  e.g.:
>> DateTime utcDate = DateTime.UtcNow;
>>
>> You can use DateTime.ToUniversalTime() to convert a local time to UTC.
>> e.g.:
>> DateTime date = new DateTime(1968, 11, 05, 12,0,0); DateTime utcDate 
>> = date.ToUniversalTime();
>>
>> You can change the type of a date from local to UTC with the 
>> SpecifyKind method (i.e. you get a DateTime object from a database; 
>> but it's default kind is local and its value is actually UTC) e.g:
>> DateTime dateTime = GetRecordDateFromDatabase(id); dateTime = 
>> dateTime.SpecifyKind(DateTimeKind.Utc);
>>
>> You can convert a UTC time to local time with DateTime.ToLocalTime.
E.g.:
>> DateTime utcDate = GetUtcDateFromSomewhere(); DateTime localDate = 
>> utcDate .ToLocalTime();
>>
>> -- Peter
>>
>> ===================================
>> View archives and manage your subscription(s) at 
>> http://peach.ease.lsoft.com/archives
>>
>> ===================================
>> View archives and manage your subscription(s) at 
>> http://peach.ease.lsoft.com/archives
>>
>
>
>
>--
>Michael Levy MCPD, MCDBA
>[email protected]
>
>===================================
>View archives and manage your subscription(s) at 
>http://peach.ease.lsoft.com/archives
>
>===================================
>View archives and manage your subscription(s) at 
>http://peach.ease.lsoft.com/archives

===================================
View archives and manage your subscription(s) at
http://peach.ease.lsoft.com/archives

===================================
View archives and manage your subscription(s) at http://peach.ease.lsoft.com/archives