Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Midnight date with timezone sent to timezone-ignorant system

Quick summary of my issue first, then details further below.

I have a Calendar date with 00:00:00 as the time as it's not important to the business. This value is sent to a webservice which generates a XML in which the value ends up in the following format : 2014-09-12T07:55:07.000Z. I have noticed that this is the original value converted to a +0 timezone (UTC) (ours is CET, +1, but currently CEST, +2, because of DST).

I currently have no idea whether the system reading the XML takes timezones into account or would extract 2014-09-12 and assume it's in the +2 timezone.

What I've noticed is that sending "2014-09-12 00:00:00" local time (tz +2) ends up as 2014-09-11T22:00:00.000Z in the XML. No big surprise, it converted it... but if it's interpreted as is by the other system, it will think the date is a day earlier than it should be.

What can be done to ensure this gets interpreted as intended?

I was thinking of using noon instead of midnight to make sure timezone shifts wouldn't impact interpretation, but it feels like a dirty trick. Or maybe I should cheat and have the Calendar timezone be +0 so it's not time-shifted when put in the XML?


Q&A

Why do you "send a Calendar to a webservice"?

The application is in Coldfusion 7. To communicate with SOAP webservices, the server generates a set of Java classes that fit the definition of the argument expected by the webservice. The argument is apparently a single big object with a lot of attributes and sub-attributes. So one instantiates the main Java class and uses setters and further instanciations of other classes to "fill out" all the attributes.

Do you have to use Calendar?

Yes, the Java object definition cannot be changed. It expects Calendar for all dates.

What's this 2014-09-11T22:00:00.000Z format?

I have no idea. This seems to be what the end system expects for dates.

You should use JODA

Unless JODA classes extend Calendar and are compatible with Java 1.3 (current Java version on the Coldfusion server -- yes it's old), I doubt it will work.

How much can you do on the other system?

The other system is the responsibility of a different team and is apparently very hard to change. I expect the solution will have to be found on the side of our application.

like image 497
leokhorn Avatar asked Sep 12 '14 10:09

leokhorn


1 Answers

Although the time value in your Calendar object is not important to your business, it is important to the webservice that you use and have no control over. The calendar object specifies an instant in time, so you must make sure that instant is in the day that is important to you. I recommend you use midday, as you suggested already. I also recommend that you create your Calendar object in the UTC timezone:

Calendar myCalendar=Calendar.getInstance(TimeZone.getTimeZone("UTC"));
like image 142
Breandán Dalton Avatar answered Oct 01 '22 16:10

Breandán Dalton