473,545 Members | 2,094 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XML dateTime conversion to DateTime.MinVal ue 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.000 0000+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 .CurrentTimezon e.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.MinVal ue we need 0001-01-01T00:00:00.000 0000 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 .CurrentTimeZon e.GetUtcOffset( Now)

If System.TimeZone .CurrentTimeZon e.IsDaylightSav ingTime(Now) Then
tz =
tz.Subtract(Sys tem.TimeZone.Cu rrentTimeZone.G etDaylightChang es(Now.Year).De l
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.000 0000 and you SHOULD be off and
running...
I got the following results:

Paris
CurrentTimezone default offset = +1 hour

Paris Standard time:
System.Timezone .CurrentTimezon e.IsDaylightSav ingTime(Now) = False
System.Timezone .CurrentTimezon e.GetUTCOffset( Now) = 1 hour
System.Timezone .CuttentTimezon e.GetDayLightCh anges(Now.Year) .GetDelta.Hours
= 1

TestValue = "0001-01-01T00:00:00.000 0000+1:00"
CDate(TestValue ) = #12:00:00 AM# (which equals DateTime.MinVal ue)

Paris Daylight time:
System.Timezone .CurrentTimezon e.IsDaylightSav ingTime(Now) = True
System.Timezone .CurrentTimezon e.GetUTCOffset( Now) = 2 hours
System.Timezone .CuttentTimezon e.GetDayLightCh anges(Now.Year) .GetDelta.Hours
= 1

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

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

Sydney:
CurrentTimezone default offset = + 10 hours

Sydney Standard time:
System.Timezone .CurrentTimezon e.IsDaylightSav ingTime(Now) = False
System.Timezone .CurrentTimezon e.GetUTCOffset( Now) = 10 hours
System.Timezone .CuttentTimezon e.GetDayLightCh anges(Now.Year) .GetDelta.Hours
= 1

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

Sydney Daylight time:
System.Timezone .CurrentTimezon e.IsDaylightSav ingTime(Now) = True
System.Timezone .CurrentTimezon e.GetUTCOffset( Now) = 11 hours
System.Timezone .CuttentTimezon e.GetDayLightCh anges(Now.Year) .GetDelta.Hours
= 1

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

TestValue = "0001-01-01T00:00:00.000 0000+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 5107

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

Similar topics

8
19228
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 is null or nor before processing it, but I am not able to figure out the syntax.
4
15229
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 another (winform for example) then the timezone conversion takes place. This is a pain if you are doing date based calculations on the client using...
2
15864
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 in/select the activity or followup date. If, for this exercise, the followupdate textfield is empty, then when the insert method of the class calls...
8
4324
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 procedure and must save either a null or a real date. However, passing a hardcoded "null" to call this function causes a compilation error : ...
5
2049
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 logic has to take care of the conversion?? e.g when inserting DateTime.minvalue into db, (especially when using store precedure, it seems that pass...
2
3284
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 the string. Is there a simple way? -- Thanks George Jin
0
375
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 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...
5
2850
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
3467
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 do a SELECT I loose original "string" and the datetime get converted in a local datetime.
0
7656
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7419
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7756
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5971
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5326
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4944
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3450
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3442
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
703
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.