staleb
asked on
DateTime UTC marker
Hi
I have an old soap web service that I took charge over and trying to figure out.
One of the fieds in the enity is datetime and before daylightsavingstime (25th of october) we revived the
date and time as this: <ObsEnd>2015-10-23T02:18:5 8+01:00</O bsEnd> and the webservice converted it into local time when storing it into the DB which will be T03:18:58.
But after daylightsavingstime we started to revice the filed as: <ObsEnd>2015-12-01T13:48:5 3Z</ObsEnd > With z as the marker.
and now it stores it directly into the databse without converting to local time.
As fare as I can see there are now special handling of the date Field other then :
obs.DateTimeWritten = obsData.ObsEnd;
Whats the difference in the handling of z and +01:00
I have an old soap web service that I took charge over and trying to figure out.
One of the fieds in the enity is datetime and before daylightsavingstime (25th of october) we revived the
date and time as this: <ObsEnd>2015-10-23T02:18:5
But after daylightsavingstime we started to revice the filed as: <ObsEnd>2015-12-01T13:48:5
and now it stores it directly into the databse without converting to local time.
As fare as I can see there are now special handling of the date Field other then :
obs.DateTimeWritten = obsData.ObsEnd;
Whats the difference in the handling of z and +01:00
Because you are storing the date and time in UTC, all incoming dates would need to be "converted" to UTC time. For +01:00, this means adding on hour. For Z (Zulu Time) there is no time offset, so the time received is the time saved.
ASKER
Hi probaly didnt explain it correct
In the database it' stored in local time. I'm in oslo so right now I'm +01:00.
But when <ObsEnd>2015-10-23T02:18:5 8+01:00</O bsEnd> (irish) came as a value
I was +02:00 and the time in db was stored as 03:18 wich is correct local time in Oslo
And when <ObsEnd>2015-12-01T13:48:5 3Z</ObsEnd > came Oslo is +01:00
but hen tim in db is stored same as the value 13:48.
Since there is an hour time differnce I presumed it also would store this value as local time wich would be 14:48
In the database it' stored in local time. I'm in oslo so right now I'm +01:00.
But when <ObsEnd>2015-10-23T02:18:5
I was +02:00 and the time in db was stored as 03:18 wich is correct local time in Oslo
And when <ObsEnd>2015-12-01T13:48:5
but hen tim in db is stored same as the value 13:48.
Since there is an hour time differnce I presumed it also would store this value as local time wich would be 14:48
Z assumes it is in the same time zone. I.e. no conversion is needed.
I.e. you were at +1 hour, then you 'fell back' for the time zone, and it went to +0.
+0 gets converted to Z as well. Since it is a standard for servers to run UTC time, this is typically not an issue.
When you don't run your time zone as UTC, you run into that difference, where Z meaning don't change it, and Z meaning UTC time can hurt.
Please keep in mind that just changing your servers timezone is not necessarily safe. I.e. depending on how things are recorded, all your database dates may then be off. Logs may appear confusing, and communications with other servers may have issues. It's always best to start a server in UTC time, but as it sounds like not, you need to be careful in fixing it.
Here is a good article about UTC time. - http://yellerapp.com/posts /2015-01-1 2-the-wors t-server-s etup-you-c an-make.ht ml
I.e. you were at +1 hour, then you 'fell back' for the time zone, and it went to +0.
+0 gets converted to Z as well. Since it is a standard for servers to run UTC time, this is typically not an issue.
When you don't run your time zone as UTC, you run into that difference, where Z meaning don't change it, and Z meaning UTC time can hurt.
Please keep in mind that just changing your servers timezone is not necessarily safe. I.e. depending on how things are recorded, all your database dates may then be off. Logs may appear confusing, and communications with other servers may have issues. It's always best to start a server in UTC time, but as it sounds like not, you need to be careful in fixing it.
Here is a good article about UTC time. - http://yellerapp.com/posts
ASKER
Hi
OK, sorry probaly som confusion here
I haven't changed the timezone on the server, the time has adjusted itself accordingly to daylightsavingstime.
I (the server in Oslo) is +2 before 25october and + 1 after 25october (this changes again in march)
This Data that I recive is from Ireland and they are +1 pre 25th and z (+0) post 25th october
Pre 25th the service stored the data as local time, adding one hour to the data recived correctly
post 25th the service did not add 1 hour, and just stored the time as it recived it
No timezone's altered just daylightsavings adjusted.
OK, sorry probaly som confusion here
I haven't changed the timezone on the server, the time has adjusted itself accordingly to daylightsavingstime.
I (the server in Oslo) is +2 before 25october and + 1 after 25october (this changes again in march)
This Data that I recive is from Ireland and they are +1 pre 25th and z (+0) post 25th october
Pre 25th the service stored the data as local time, adding one hour to the data recived correctly
post 25th the service did not add 1 hour, and just stored the time as it recived it
No timezone's altered just daylightsavings adjusted.
It would appear that the time you are receiving from the web service is UTC/GMT time with timezone offset. So the time is being converted to the local time of the sender (Ireland), not the recipient (Norway).
Does your data records have audit fields with which you can confirm when you received the data in Oslo time?
Does your data records have audit fields with which you can confirm when you received the data in Oslo time?
ASKER
yes, I record the time we revice the transaction/data in
Data recived time (oslo time) is + 1hour from the time in the Object Field <ObsEnd>
So it seems that the service converts the irish time right when it comes as
<ObsEnd>2015-10-23T02:18:5 8+01:00</O bsEnd>
And not when it comes as:
<ObsEnd>2015-12-01T13:48:5 3Z</ObsEnd >
Data recived time (oslo time) is + 1hour from the time in the Object Field <ObsEnd>
So it seems that the service converts the irish time right when it comes as
<ObsEnd>2015-10-23T02:18:5
And not when it comes as:
<ObsEnd>2015-12-01T13:48:5
ASKER
I just wondered if .net framework 3.5 wich the service is created does not handle "z" correct.
Or if the error is pre this since the service recives data in xml, and deserialize it
Or if the error is pre this since the service recives data in xml, and deserialize it
ASKER
Hi
Since the service recives an xml string and its Deserialized into an enity before I handle it, the error seems to be there.
I have done following testing (sorry for all the code)
I use deserilaze from this site
http://www.techillumination.in/2013/07/convert-object-to-xml-and-vice-versa.html
I am now in timezone +1 (oslo)
With z
XmlDocument doc = new XmlDocument();
XmlElement el = (XmlElement)doc.AppendChil d(doc.Crea teElement( "pEnt"));
el.AppendChild(doc.CreateE lement("da to")).Inne rText = "2015-10-29T17:47:37+z";
XmlDocument doc2 = new XmlDocument();
XmlElement el2 = (XmlElement)doc2.AppendChi ld(doc2.Cr eateElemen t("pEnt")) ;
el2.AppendChild(doc2.Creat eElement(" dato")).In nerText = "2015-10-29T17:47:37+01:00 ";
XmlDocument doc3 = new XmlDocument();
XmlElement el3 = (XmlElement)doc3.AppendChi ld(doc3.Cr eateElemen t("pEnt")) ;
el3.AppendChild(doc3.Creat eElement(" dato")).In nerText = "2015-10-29T17:47:37+02:00 ";
pEnt sak = new pEnt();
sak = (pEnt)ObjectToXML(doc.Oute rXml, sak.GetType());
pEnt sak2 = (pEnt)ObjectToXML(doc2.Out erXml, sak.GetType());
pEnt sak3 = (pEnt)ObjectToXML(doc3.Out erXml, sak.GetType());
DateTime local1 = DateTime.Parse("2015-10-29 T17:47:37+ z");
DateTime local2 = DateTime.Parse("2015-10-29 T17:47:37+ 01:00");
DateTime local3 = DateTime.Parse("2015-10-29 T17:47:37+ 02:00");
Gives:
DateTimeParse on string
29.10.2015 18:47:37 z
29.10.2015 17:47:37 +01
29.10.2015 16:47:37 +02
Deserialize
29.10.2015 17:47:37 z
29.10.2015 17:47:37 +01
29.10.2015 16:47:37 +
but if I change z With +00:00
I get the desired result:
DateTimeParse on string
29.10.2015 18:47:37
29.10.2015 17:47:37
29.10.2015 16:47:37
Deserialize
29.10.2015 18:47:37
29.10.2015 17:47:37
29.10.2015 16:47:37
So my conlusion is that I need to change the Field in the entity from datetime to string and the DateTime.Parse it or have the customer send in +00:00 instead
Since the service recives an xml string and its Deserialized into an enity before I handle it, the error seems to be there.
I have done following testing (sorry for all the code)
I use deserilaze from this site
http://www.techillumination.in/2013/07/convert-object-to-xml-and-vice-versa.html
I am now in timezone +1 (oslo)
With z
XmlDocument doc = new XmlDocument();
XmlElement el = (XmlElement)doc.AppendChil
el.AppendChild(doc.CreateE
XmlDocument doc2 = new XmlDocument();
XmlElement el2 = (XmlElement)doc2.AppendChi
el2.AppendChild(doc2.Creat
XmlDocument doc3 = new XmlDocument();
XmlElement el3 = (XmlElement)doc3.AppendChi
el3.AppendChild(doc3.Creat
pEnt sak = new pEnt();
sak = (pEnt)ObjectToXML(doc.Oute
pEnt sak2 = (pEnt)ObjectToXML(doc2.Out
pEnt sak3 = (pEnt)ObjectToXML(doc3.Out
DateTime local1 = DateTime.Parse("2015-10-29
DateTime local2 = DateTime.Parse("2015-10-29
DateTime local3 = DateTime.Parse("2015-10-29
Gives:
DateTimeParse on string
29.10.2015 18:47:37 z
29.10.2015 17:47:37 +01
29.10.2015 16:47:37 +02
Deserialize
29.10.2015 17:47:37 z
29.10.2015 17:47:37 +01
29.10.2015 16:47:37 +
but if I change z With +00:00
I get the desired result:
DateTimeParse on string
29.10.2015 18:47:37
29.10.2015 17:47:37
29.10.2015 16:47:37
Deserialize
29.10.2015 18:47:37
29.10.2015 17:47:37
29.10.2015 16:47:37
So my conlusion is that I need to change the Field in the entity from datetime to string and the DateTime.Parse it or have the customer send in +00:00 instead
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I will test this in my service, I have gotten the customer to send in +00:00 to start with