473,320 Members | 1,974 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

XML dateTime conversion to DateTime.MinValue accross timezones

This is a bit of a weird one that I haven't yet been able to solve - I'm
hoping someone out there can disprove my findings and tell me where I've
gone wrong!

I have designed a web service that accepts messages from .NET clients. The
web method call includes an object as one of it's parameters - this
reflected object has been given a property called "FutureDelivery" and
expects a DateTime value. The clients may be in different timezones from
the server.

Due to the nature of the application of which the web service is a part the
DateTime set in the object must remain immutable; if the consumer sets it to
10am in Paris then it must remain 10am at the receiving web service, even if
the web service resides in a different timezone from the consumer. Now by
remaining 10am I don't mean that I need them to share the same UTC - I want
10am as a fixed value that is recognized as 10am at the destination. I
realize that I could get away with this by having the property value as a
String instead, but this would leave me open to inconsistencies in submitted
values and would remove the advantages that the DateTime object provide for
the consumer.

Since I'm using a web service and all the communications between the
consumer and web service are in XML my first thought was that the web
service could modify the values in the incoming XML message and alter the
appropriate node. As a result I wrote a SOAPExtension to intercept the
incoming XML data before deserialization, locate the FutureDelivery nodes
and alter the timezone on the nodes. Since XML dateTimes are represented as
0001-01-01T00:00:00.0000000+1:00 (for example) I figured I could simply
strip the timezone component (+1:00 in this case) and replace it with
current the timezone offset for the current server location.

All well and good so far, but then I ran into a little stumbling block that
I have since been banging my head on...

I used System.Timezone.CurrentTimezone.GetUTCOffset(now) to obtain the
current timezone for the region. This value can change depending on the
current daylight savings status; for example, in Paris, France the offset is
+1:00 during standard time and +2:00 during daylight time, while in Sydney,
Australia its +10:00 during standard time and +11:00 during daylight time.

The problem I have is that these offsets to not appear to behave
consistently between regions and daylight settings.

To create an XML dateTime value that will be converted into a DateTime value
equaling DateTime.MinValue we need 0001-01-01T00:00:00.0000000 then have to
add the positive or negative UTCoffset in hours and subtract the delta if
daylight savings is in effect.

For example:

Dim tz As TimeSpan = System.TimeZone.CurrentTimeZone.GetUtcOffset(Now)

If System.TimeZone.CurrentTimeZone.IsDaylightSavingTi me(Now) Then
tz =
tz.Subtract(System.TimeZone.CurrentTimeZone.GetDay lightChanges(Now.Year).Del
ta)
End If

At the end of this tz should hold a TimeSpan equaling the correct number of
hours for the offset. Convert this to a string as (+/-)hh:mm and add it to
the end of the string 0001-01-01T00:00:00.0000000 and you SHOULD be off and
running...
I got the following results:

Paris
CurrentTimezone default offset = +1 hour

Paris Standard time:
System.Timezone.CurrentTimezone.IsDaylightSavingTi me(Now) = False
System.Timezone.CurrentTimezone.GetUTCOffset(Now) = 1 hour
System.Timezone.CuttentTimezone.GetDayLightChanges (Now.Year).GetDelta.Hours
= 1

TestValue = "0001-01-01T00:00:00.0000000+1:00"
CDate(TestValue) = #12:00:00 AM# (which equals DateTime.MinValue)

Paris Daylight time:
System.Timezone.CurrentTimezone.IsDaylightSavingTi me(Now) = True
System.Timezone.CurrentTimezone.GetUTCOffset(Now) = 2 hours
System.Timezone.CuttentTimezone.GetDayLightChanges (Now.Year).GetDelta.Hours
= 1

....since 2 - 1 = 1...

TestValue = "0001-01-01T00:00:00.0000000+1:00"
CDate(TestValue )= #12:00:00 AM# (which equals DateTime.MinValue) *****YAY!
No problems yet...

Sydney:
CurrentTimezone default offset = + 10 hours

Sydney Standard time:
System.Timezone.CurrentTimezone.IsDaylightSavingTi me(Now) = False
System.Timezone.CurrentTimezone.GetUTCOffset(Now) = 10 hours
System.Timezone.CuttentTimezone.GetDayLightChanges (Now.Year).GetDelta.Hours
= 1

TestValue = "0001-01-01T00:00:00.0000000+10:00"
CDate(TestValue)= #1:00:00 AM# ...****WHAT??? This should be midnight,
shouldn't it?

Sydney Daylight time:
System.Timezone.CurrentTimezone.IsDaylightSavingTi me(Now) = True
System.Timezone.CurrentTimezone.GetUTCOffset(Now) = 11 hours
System.Timezone.CuttentTimezone.GetDayLightChanges (Now.Year).GetDelta.Hours
= 1

....since 11 - 1 = 10....

TestValue = "0001-01-01T00:00:00.0000000+10:00"
CDate(TestValue)= #1:00:00 AM# ...****WHAT??? This should be midnight,
shouldn't it?

For some reason the conversion of an XML dateTime into a DateTime seems to
think that the offset is one hour out!

Can someone explain this to me?? From everything I think I understand about
this the above values should always return #12:00:00 AM# The result of
these calculations cause data for Australia to be 1 hour out. This means
that I can't set up multiple web service nodes in multiple countries because
the timezone offset calculations only work in some of them.

Can anyone help me here?

Cheers,

Symon.


Jul 19 '05 #1
0 5066

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Manish Jain | last post by:
Platform : ASP.Net/C# void SomeFunction(DateTime date) { string text = date.ToString(); //This crashes if date is null } I am using a construct similar to above. I want to check if the date...
4
by: GiriT | last post by:
Would appreciate some insight into how people are dealing with the implicit conversion of timezones that .NET does. If a server in one timezone delivers up a typed dataset to a component in...
2
by: Rey | last post by:
Howdy all. My problem deals w/inserting nulls into database (SQL Svr 2K) for the datetime fields activityDate and followUpDate where nulls are allowed. >From the web form, the user can type...
8
by: craigkenisston | last post by:
I have a generic function that receives a couple of datetime values to work with. They can or cannot have a value, therefore I wanted to use null. This function will call a database stored...
5
by: Kevin Yu | last post by:
hi all since the DateTime can't be assign null, the min value is set to 1901 or something, if in a application design, the date field can be null, so in between the UI and the DB, the business...
2
by: George Jin | last post by:
In the Datagrid clolumns there is one is DateTime Type. It always shows DateTime.MinValue. How can It show emptty string instead? I Know I can do conversion from DateTime to string before binding...
0
by: Symon R | last post by:
This is a bit of a weird one that I haven't yet been able to solve - I'm hoping someone out there can disprove my findings and tell me where I've gone wrong! I have designed a web service that...
5
by: shapper | last post by:
Hello, I defined a DateTime variable: Dim dt As New DateTime How can I check if it is empty? Basically I want to check if it was given to it a DateTime value or not.
2
by: BLUE | last post by:
I want to store and retrieve datetime in ISO 8601 format: '2007-06-02T16:12:08.123-04:34' or '2007-06-02T16:12:08.123Z' When I insert a datetime with SQL Server Management Studio and then I...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.