Date creates many confusion & bugs in our applications, some of which are only found when Day Light Savings time changes. 🙂

There is fundamental issue with how we talk about Date. For example, my date is in Central Time or for this Location my Date is in Eastern Time. As we all know, Date is milliseconds representing GMT time & String value we see in Debugger or Logs is just String representation of Date with respect to some TimeZone.

Here is what i recommend for Date usage with ADF, some of which can very well apply to other frameworks as well.

1. Don’t offset date value for Persistence

JDBC driver will transform value of Date is Server’s Default TimeZone for storing in Table Column. At times, we try to offset value of Date, so that when JDBC Driver creates String representation using Server’s Default TimeZone, it looks like GMT for example. This is clever, but not a good idea.

This approach can cause issues with Queries. It will also not represent values correctly on screen components. You can workaround these issues, but that’s extra work that can be avoided, by accepting the fact that Date will be stored in Server’s Default TimeZone.

2. Do not specify Date Format on Control Hints for Entity or View Object attributes

ADF does a good job of providing Control Hints that can be set on Business Components, but in this case I would recommend not setting any Format for Date on Entity and View Object. I have seen issues with Control Hints related to Date Format and more importantly it makes sense to control this based on User’s Preferences / Locale.

3. Create Session Scope variables for TimeZone & Date Format

Using Phase Listener, create Session Scope values for TimeZone and various Date & Time formats. You can read this values from User’s Preference or derive it using any other data store.

These can be used in UI pages with af:convertDateTime as shown below.

 

4. Specify TimeZone in trinidad-config.xml

 

If you set value of time-zone in trinidad-config.xml, it will apply to all Date components for display and input processing.

5. Specify Pattern on af:date Specify different TimeZone if necessary on af:date

If you want to display particular Date value in a different TimeZone, you can indicate that on af:convertDateTime. For example, Delivery Date would make sense to be displayed in TimeZone of Delivery Location.

Share this:
Chandresh Patel

I have been working with Java EE technologies since 2000. After implementing IBM WebSphere and custom framework solutions, my past 10 years have been focused on Oracle Fusion Middleware such as WebLogic, ADF, WebCenter and Coherence. I have been part of many automation projects in the past and have a passion for automation capabilities to help our customers deliver software faster and with higher quality. In my current role as a Principal Architect at Flexagon, I am driving the FlexDeploy product strategy and development to build DevOps/CI/CD features that help our customers.

More posts by Chandresh Patel
    

4 Comments

  • Naren says:

    Can I have sample application

    Regards
    Naren

  • mridu says:

    Hi

    My view criteria has date fields . Even the view criteria date field also we need to set the dynamic date format
    Please suggest me how i can set this

    Thanks

    • Chandresh Patel says:

      You can set format on the Attribute in view object, which will create entry in ResourceBundle. You can then create different Locale based bundle and that format would apply according to Locale setting on user’s browser.

Leave a Reply

Your email address will not be published. Required fields are marked *