0

I have following scenario:

  • A JSF application that can be used by a user to create tickets.
  • These tickets have a validity (from-to)
  • I have a application configuration which states in which TimeZone/ZoneID the context of the application runs.
  • I need to persist the validity of the ticket and be aware that the application configuration for TimeZone/ZoneID may change and therefore also previously created tickets should be visualized with the correct converted datetime

I'd like to know what the way to go would be? Having some custom converter to store the, adding the TimeZone information as additional field in the database or some other approach? Is this topic database vendor specific or is there some sort of generic solution? I'm a little puzzled, maybe I'm intending to do something that one shouldn't do, cause I didn't find too much information about this topic in general.

hecko84
  • 1,224
  • 1
  • 16
  • 29

1 Answers1

0

Finally I found a different solution, based on the fact that it is not necessary to keep the original timezone the ticket was created for. I now simply use java.util.Date in the backing bean for the date picker component and convert it to an java.time.Instant as soon as I push it to the backend. For visualization purposes on the JSF frontend I just format the java.util.Date with a SimpleDateFormatter where I set the timezone to the one configured in the backend

String timeZoneOffset = "GMT+0100";
TimeZone timeZone = TimeZone.getTimeZone(timeZoneOffset);
DateFormat dateTimeFormat = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss.SSSZ");
dateTimeFormat.setTimeZone(this.timeZone);

To display the formatted java.util.Date objects in JSF I use a formatter like that

<p:outputLabel id="tripEndDate" value="#{registerBean.trip.tripEndDate}">
    <f:convertDateTime pattern="yyyy-MM-dd HH:mm Z" timeZone="#{registerBean.timeZone.getID()}" />
</p:outputLabel>

Maybe as further input that might be interesting here is that I had some issues with storing the Timestamps to DB with Hibernate as Hibernate uses the systems default timezone, so if your server doesn't run in UTC you will observe this timezone conversions

hecko84
  • 1,224
  • 1
  • 16
  • 29