2 Replies Latest reply: Aug 2, 2007 8:37 AM by 807605 RSS

    DST issue: Date discrepancy in displaying the retrieved Date from database

    807605
      Hope you know the general DST Transition funda.

      The DST date time wont be having time 2007 Mar 10 2:00:00 AM. Instead it has 3:00:00 AM. Here the transition takes place from 1:59:99 AM to 3:00:00 AM.

      Let me describe my issue in detail.

      We have data for 2:00:00AM am and 3:00:00AM separately in the database. The project uses JDK 1.5 version and it has the DST fix. So the Date object of this JDK1.5 won�t be having 2:00:00 AM.

      Actual problem goes here:
      I am trying to retrieve a record with the Date 2:00:00 AM and assigning to the Date variable. The Date object variable is then sent to the reports and displays. Instead of 2:00:00 AM it report has 3:00:00 AM which is a wrong data. We know that Java Date object automatically converts the time to 3:00:00 which is correct as per the DST fix.

      In my case, I should show the user the data that is exactly in the database. Is there any generic/global solution for this issue?

      Hope I you understand the problem clearly.
        • 1. Re: DST issue: Date discrepancy in displaying the retrieved Date from datab
          Herko_ter_Horst
          Please note that "DST", "Timezone" and stuff like that are display issues only. java.util.Date doesn't know about any of it.

          A java.util.Date object represents a 'moment in time', represented as the number of milliseconds since the moment in time we western humans call January 1st, 1970, 0:00:00,000.

          As 2:00 AM and 3:00 AM on a DST-switch date represent the exact same moment in time, there is no way for a java.util.Date to know about the distinction.

          So if you want to display the distinction for the benefit of the user (I wonder why, but that's your problem), you will have to look outside java.util.Date for a solution. Depending on how your database stores its values, you might be able to retrieve the String representation of the date and work with that.

          TBH, I would look at fixing the inconsistencies in the database instead of creating work-arounds for them in your code. But then I don't know your problem domain, perhaps you have a very good reason for having two different representations of the same moment in time.
          • 2. Re: DST issue: Date discrepancy in displaying the retrieved Date from datab
            807605
            You are right.

            Thats the business requirement of our scenario. We have tried some, to fix this issue are;

            1. Geting the date from the database as a String. (This requires major changes in the existing code. i.e. change all the beans that use the date object)

            2. Disabling the DST for that particular moment to retrieve the date and enabling it back.

            3. Store the date as UTC in the database. [This can't be done since we are refering some historical data].

            Just explaining you about our status. We are looking forward to fix this issue by generating a wrapper class which can be implemented in all the places where we are refering to the date with the Date object.

            Keep posted if you found any solution for this.

            Message was edited by:
            Mani_cs