473,421 Members | 1,562 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,421 software developers and data experts.

DateTime Serialization Framework 1.1

Our application is windows desktop application. We are using VS.Net 2003, C#,
Framework 1.1, SQL 2000. We use webservices to add/update/select objects. We
are using XML Serialization. Following is a sample object at CLIENT

[System.Xml.Serialization.XmlAttributeAttribute()]
public System.DateTime ContactDateTime
{
get { return _ContactDateTime; }
set { _ContactDateTime = value; }
}

Following is the object at SERVER

[XmlAttribute]
public DateTime ContactDateTime
{
get {return _contactDateTime;}
set {_contactDateTime = value;}
}

The problem is that when the client/server is in a timezone where
dayLightSavings are ON. The DateTime field contains a value adjusted to one
hour during Daylight saving period, which results in incorrect data. For ex:
if the value in the database is "12/03/2005 23:00:00" when it is serialized
and received at DLS client the date becomes "13/03/2005 00:00:00" same is the
case when dates are serialized from client to server.

How this problem can be resolved?
Nov 23 '05 #1
5 5887
"=?Utf-8?B?bnMyMQ==?=" <ns**@discussions.microsoft.com> wrote in
news:14**********************************@microsof t.com:
The problem is that when the client/server is in a timezone where
dayLightSavings are ON. The DateTime field contains a value adjusted to
one hour during Daylight saving period, which results in incorrect data.
For ex: if the value in the database is "12/03/2005 23:00:00" when it is
serialized and received at DLS client the date becomes "13/03/2005
00:00:00" same is the case when dates are serialized from client to
server.


Its built into DateTime. You need to make your own value type, or what most
users do is just use strings.
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Blog: http://blogs.atozed.com/kudzu
Nov 23 '05 #2
http://blogs.msdn.com/bclteam/archiv...21/136918.aspx

--
William Stacey [MVP]

"ns21" <ns**@discussions.microsoft.com> wrote in message
news:14**********************************@microsof t.com...
Our application is windows desktop application. We are using VS.Net 2003,
C#,
Framework 1.1, SQL 2000. We use webservices to add/update/select objects.
We
are using XML Serialization. Following is a sample object at CLIENT

....
Nov 23 '05 #3
Thanks Chad & William.
I am aware of the fact that changing the datetime to string is the concrete
solution However I actually want to avoid changing the datetime types to
strings because These would be the huge changes in the application. I was
looking for the other ways to handle it.

Is this problem resolved in framework 2.0 / whidbey.

"Chad Z. Hower aka Kudzu" wrote:
"=?Utf-8?B?bnMyMQ==?=" <ns**@discussions.microsoft.com> wrote in
news:14**********************************@microsof t.com:
The problem is that when the client/server is in a timezone where
dayLightSavings are ON. The DateTime field contains a value adjusted to
one hour during Daylight saving period, which results in incorrect data.
For ex: if the value in the database is "12/03/2005 23:00:00" when it is
serialized and received at DLS client the date becomes "13/03/2005
00:00:00" same is the case when dates are serialized from client to
server.


Its built into DateTime. You need to make your own value type, or what most
users do is just use strings.
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Blog: http://blogs.atozed.com/kudzu

Nov 23 '05 #4
"=?Utf-8?B?bnMyMQ==?=" <ns**@microsoft.com> wrote in
news:8B**********************************@microsof t.com:
Is this problem resolved in framework 2.0 / whidbey.


Its actually a feature. It can be a big PITA, but it can be very useful too.
Its more problematic when you are storing dates, or a computer has the wrong
time zone set.
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Blog: http://blogs.atozed.com/kudzu
Nov 23 '05 #5
All your DateTime(s) on the server should be stored and returned as UTC.
This has a few benifits. First, you have a stack in the ground as to what
format the dates are in (all UTC.) Second, they will serilize fine now as
they will be Zulu (hence the Z at the end). All your clients can then
convert to local time if needed or leave in UTC for datetime calcs. After
class is deserilized, you decide if you need to convert any/all DateTime
fields to LocalTime or leave in UTC.

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Xml.Serialization;

namespace NetNodes.DB
{
public class ClassWithDate
{
public ClassWithDate() { }
public DateTime Date;
public string Name;
public string ToXmlString()
{
string data = null;
XmlSerializer ser = new XmlSerializer(typeof(ClassWithDate));
using (StringWriter sw = new StringWriter())
{
ser.Serialize(sw, this);
sw.Flush();
data = sw.ToString();
return data;
}
}
public static ClassWithDate FromXml(string xmlString)
{
if (xmlString == null)
throw new ArgumentNullException("xmlString");

ClassWithDate cwd = null;
XmlSerializer ser = new XmlSerializer(typeof(ClassWithDate));
using (StringReader sr = new StringReader(xmlString))
{
cwd = (ClassWithDate)ser.Deserialize(sr);
}
return cwd;
}
}
}

private void button3_Click(object sender, EventArgs e)
{
// Serialize/Deserialize using UTC.
// Server side.
DateTime localDateTime = DateTime.Now;
Console.WriteLine("Server local Time: {0}",
localDateTime.ToString());
DateTime utcDateTime = localDateTime.ToUniversalTime();
Console.WriteLine("Server UTC Time: {0}\n",
utcDateTime.ToString());
ClassWithDate dc = new ClassWithDate();
dc.Name = "ABC";
dc.Date = DateTime.UtcNow;
string xml = dc.ToXmlString();
Console.WriteLine("Class on the wire per XmlSerializer (date as
UTC):");
Console.WriteLine(xml);

// Client side.
Console.WriteLine("\nClient Side:");
ClassWithDate ncwd = ClassWithDate.FromXml(xml);
Console.WriteLine("Server's UTC: {0}", ncwd.Date.ToString());
ncwd.Date = ncwd.Date.ToLocalTime();
Console.WriteLine("Server's UTC as my LocalTime: {0}",
ncwd.Date.ToString());
}

Example Output:
================================================== ====
Server local Time: 5/17/2005 5:26:21 PM
Server UTC Time: 5/17/2005 9:26:21 PM

Class on the wire per XmlSerializer (date as UTC):
<?xml version="1.0" encoding="utf-16"?>
<ClassWithDate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Date>2005-05-17T21:26:21.96875Z</Date>
<Name>ABC</Name>
</ClassWithDate>

Client Side:
Server's UTC: 5/17/2005 9:26:21 PM
Server's UTC as my LocalTime: 5/17/2005 5:26:21 PM

--
William Stacey [MVP]

"ns21" <ns**@microsoft.com> wrote in message
news:8B**********************************@microsof t.com...
Thanks Chad & William.
I am aware of the fact that changing the datetime to string is the
concrete
solution However I actually want to avoid changing the datetime types to
strings because These would be the huge changes in the application. I was
looking for the other ways to handle it.

Is this problem resolved in framework 2.0 / whidbey.

"Chad Z. Hower aka Kudzu" wrote:
"=?Utf-8?B?bnMyMQ==?=" <ns**@discussions.microsoft.com> wrote in
news:14**********************************@microsof t.com:
> The problem is that when the client/server is in a timezone where
> dayLightSavings are ON. The DateTime field contains a value adjusted to
> one hour during Daylight saving period, which results in incorrect
> data.
> For ex: if the value in the database is "12/03/2005 23:00:00" when it
> is
> serialized and received at DLS client the date becomes "13/03/2005
> 00:00:00" same is the case when dates are serialized from client to
> server.


Its built into DateTime. You need to make your own value type, or what
most
users do is just use strings.
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Blog: http://blogs.atozed.com/kudzu

Nov 23 '05 #6

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

Similar topics

2
by: andrew lowe | last post by:
Hi, Please bear with me on this problem, first I'll give you some background: I have an object that contains a DateTime field which i pass to a webservice public class Foo { public DateTime...
2
by: BjörnHolmberg | last post by:
Hi everyone! In the following code we get a UTC offset in xml. Since I want my WAP users in UTC+02:00 to see data on a server in some US time zone, a lot of confusion will be created from this...
0
by: HakonB | last post by:
Hi all I get an exception when trying to deserialize a simple configuration file using XML Serialization. The very long stacktrace can be seen at the bottom of this message. I've see other...
3
by: Alexander | last post by:
When i store rule on PC with .NET.SP1 i cant restore them from PC without SP1. An i get this Error: System.Runtime.Serialization.SerializationException: Possible Version mismatch. Type...
5
by: Naveen Mukkelli | last post by:
Hi, I'm writing a server applicaiton using C# and .NET Framework. This server sends out time to all the clients. The clients are expected to be written in various platforms for example, Delphi,...
9
by: Phil B | last post by:
I am having a problem with a datetime from a web services provider The provider is sending the following SOAP response <?xml version="1.0" encoding="utf-8"?> <soap:Envelope...
1
by: Chris Ashley | last post by:
Hi, I have an XML web service which accepts a few datetime values. We have some clients using it who are using different systems (java etc) and they need to know what the standard format for a...
3
by: Zachary Turner | last post by:
Hello, I have a situation where I would like to perform custom serialization and deserialization of an existing .NET framework object (specifically, System.DateTime). Is there a common paradigm...
1
by: Karch | last post by:
I am doing some experimenting with serialization (for use with Service Broker) and I am having a problem converting from a .NET DateTime (in the client application) to a SqlDbType.VarBinary (as...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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,...
0
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...

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.