• Post Reply Bookmark Topic Watch Topic
  • New Topic

Date shifting 1 day back on 1 of many systems :S  RSS feed

 
Gerben Feenstra
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This piece of java software I am responsible for is running throughout numerous locations in my country, there is only 1 location which has trouble with the dates being displayed incorrectly, birthdates of clients are displayed as a day earlier. It seems pretty safe to say it is a problem on their end... But still, they're asking me for an explanation as to why java would treat a date differently in this rare case.

The date (a birthdate) comes from an oracle database, it is a date without a time (trunced date). It enters the application as a member of the client-class, it is NOT being set or changed after that. It goes through several layers in the application, then ends up in a GUI class which unwraps it from the "client"-object and puts a SimpleDateFormat (new SimpleDateFormat("dd-MM-yyyy")) on it.

My first and only hunch was the timezone settings, but that seems to be OK!

Does anyone here have any clue as to what might cause this strange behaviour?

 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gerben Feenstra wrote:Does anyone here have any clue as to what might cause this strange behaviour?

I think so, and I suspect that it does have to do with the timezone. There is no such thing as a "date" in Java (at least before version 8): all Java dates - and specifically java.sql.Date - include a time.

Now I'm not exactly sure how SQL DATEs are converted to Java, but I suspect that the timezone of the database will be involved, and there will be some specification for the time part (either 00:00:00.000 or "current" time). So if the timezone where this "date" is being read is different to the db timezone you could have this problem.

I'm not absolutely sure that it's the problem, but it would be my guess.

Winston
 
Gerben Feenstra
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your analysis Winston. I have in fact tried this myself (Changing the timezone from +1:00 to 0:00), and it is the only way I can reproduce this problem on my local machine here. I figured since java dates always has a time (since java data is based on milliseconds from epoch), the trunced sql date will end up being at midnight, the first millisecond of that date sorta speak. When the timezone differs -1, it will become 23:00 (11PM) the previous day, so the date ends up displayed as the day before.

So, yes, timezone difference can cause this same problem.

However, the people I am dealing with here ensure me their timezones are set correctly :S
Not sure how credible this response is though...
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gerben Feenstra wrote:However, the people I am dealing with here ensure me their timezones are set correctly :S
Not sure how credible this response is though...

Yes, but if their timezone is different to the one the DATE (ie, the db date) was stored for, it could still cause the issue. So, they could very well be right, and you might still have the problem.

I'm afraid I simply don't know enough about the mechanics of how SQL DATEs are stored and retrieved to offer any more advice; but I can tell you that I had this exact problem a while ago - but that was with Oracle 8i, and I suspect things have moved along quite a bit since then.

Winston
 
Gerben Feenstra
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd say that chance is pretty slim, since my country is entirely in one timezone, so their timezone must be the same as mine, and the date comes from the same DB, so same timezone.
I do not think the problem is with the db (sql date) since it comes out trunced, plus many other locations report no problems on the same data.
 
Gerben Feenstra
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, I found out something. If this is the solution, I'm not expecting any feedback from our customer and I will probably forget all about this post, so here's my findings for future reference and/or for anyone with a similar problem:

Although the checkbox (under timezone settings) for "Adjust to Daylight Saving Time" does not seem to do anything in wintertime (Which is standard time), it does seem to be having effect on my problem. I am able to reproduce the problem once again depending on wether the checkbox is on or off. I gave this information to our customer, but as usual I'll probably hear little from them if this is indeed the solution...
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gerben Feenstra wrote:Although the checkbox (under timezone settings) for "Adjust to Daylight Saving Time" does not seem to do anything in wintertime (Which is standard time), it does seem to be having effect on my problem.

Hmmm. I wonder why someone thought you would need a checkbox for this? DST is a function OF the timezone, not something that you can (or should) turn "on" or "off".

If you're in the Netherlands (I'm in Belgium), then you're on WET which does use DST with strictly defined rules, so if you "turn it off", you're not on WET (or "Europe/Amsterdam") any more.

Winston
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!