SeamFramework.orgCommunity Documentation

Chapter 38. Timezones

38.1. Joda Time
38.2. Application TimeZone
38.3. User TimeZone
38.4. Available TimeZones

To support a more developer friendly way of handling TimeZones, in addition to supporting JDK TimeZone, we have added support for using Joda-Time through their DateTimeZone class. Don't worry, it provides convenience methods for converting to JDK TimeZone.

To activate Joda-Time for i18n within your project you will need to add the following Maven dependency:


<dependency>
      <groupId>joda-time</groupId>
      <artifactId>joda-time</artifactId>
      <version>1.6</version>
   </dependency>

We have an Application time zone that is available with Joda-Time (DateTimeZone) or the JDK (TimeZone) that can be retrieved with

@Inject

private DateTimeZone applicationDateTimeZone;
@Inject
private TimeZone applicationTimeZone

It can also be accessed through EL by the name "defaultDateTimeZone" for Joda-Time or "defaultTimeZone" for JDK!

By default the TimeZone will be set to the JVM default, unless you produce a String annotated with @DefaultTimeZone. This can be achieved through either the Seam Config module or any bean that @Produces a method or field that matches the type and qualifier.

This will set the application time zone to be Tijuana:

@Produces

@DefaultTimeZone
private String defaultTimeZoneId = "America/Tijuana";

In addition to the Application time zone, there is also a time zone assigned to each User Session.

@Inject

@Client
private DateTimeZone userDateTimeZone;
@Inject
@Client
private TimeZone userTimeZone;

It can also be accessed through EL using "userDateTimeZone" for Joda-Time and "userTimeZone" for JDK.

By default the DateTimeZone and TimeZone for a User Session is initialized to the same as the Application. However, changing the User's DateTimeZone and TimeZone is a simple matter of firing an event to update it. An example would be

@Inject

@Client
@Alter
private Event<DateTimeZone> dtzEvent;
@Inject
@Client
@Alter
private Event<TimeZone> tzEvent;
public void setUserDateTimeZone() {
    DateTimeZone dtzTijuana = DateTimeZone.forID("America/Tijuana");
    dtzEvent.fire(dtzTijuana);
    TimeZone tzTijuana = TimeZone.getTimeZone("America/Tijuana");
    tzEvent.fire(tzTijuana);
}

We've also provided a list of available TimeZones that can be accessed via

@Inject

private List<ForwardingDateTimeZone> dateTimeZones;
@Inject
private List<ForwardingTimeZone> timeZones;