Package com.atlassian.jira.datetime

A small set of classes that allow clients to format and parse dates in JIRA, in a way that is time zone and locale aware.

See:
          Description

Interface Summary
DateTimeFormatter Interface for JIRA date time formatters.
DateTimeFormatterFactory This factory is used to create DateTimeFormatter instances within JIRA.
 

Class Summary
DateTimeFormatterFactoryImpl This class is responsible for providing DateTimeFormatter instances to JIRA and plugin code.
DateTimeFormatterFactoryStub Stub for DateTimeFormatterFactory, useful for unit tests.
DateTimeFormatUtils Helper methods for dealing with the configured date and date-time formats.
DateTimeVelocityUtils Aggregates the most commonly-used date/time formats in a single instance, for use within Velocity templates.
DateVelocityUtils Aggregates the most commonly-used date formats in a single instance, for use within Velocity templates.
ExampleDateFormatOutputGenerator This simple function returns an example date/time formatted with the given pattern.
JodaFormatterSupplierStub JodaFormatterSupplier for use in tests.
LocalDate Represents a "Local Date" or "Calendar Date" - that is a date (no time) without any associated timezone.
LocalDateFactory Used for creating LocalDate objects.
 

Enum Summary
DateTimeStyle The date styles that JIRA is capable of formatting to.
 

Package com.atlassian.jira.datetime Description

A small set of classes that allow clients to format and parse dates in JIRA, in a way that is time zone and locale aware.

Time zones

When working with dates and times inside JIRA, it is important to understand the following time zone concepts.

By default, formatters in this package will operate using the time zone of the user that is currently logged in. If the default user time zone has not configured, it defaults to the system time zone. Similarly, if a user has not configured a user time zone, JIRA will use the default user time zone when displaying date and times to that user.

Locales

JIRA is capable of displaying dates in the default JIRA locale, and also in the user's locale, when a user has explicitly configured a different locale. By default, formatters in this package will operate using the locale of the user that is currently logged in.

Usage

Most of the work is done by implementations of the DateTimeFormatter interface. If you intent to use date, and especially date/time values in your plugin, you should have a DateTimeFormatterFactory injected into your plugin classes, which you can use to build DateTimeFormatter instances, as in the following example.

     public class MyPluginClass
     {
         private final DateTimeFormatter dateTimeFormatter;

         public MyPluginClass(DateTimeFormatter dateTimeFormatter)
         {
             // call forLoggedInUser() to associate the formatter with the currently logged in user
             this.dateTimeFormatter = dateTimeFormatter.forLoggedInUser();
         }

         // formats dates in the user's time zone and with the user's locale
         public String currentDate()
         {
             return dateTimeFormatter.withStyle(COMPLETE).format(new Date());
         }

         // formats dates in UTC and with the user's locale
         public String currentDateInUTC()
         {
             return dateTimeFormatter.withZone(TimeZone.UTC).format(new Date());
         }

         // formats dates in the user's time zone and in Dutch
         public String currentDateInDutch()
         {
             return dateTimeFormatter.withLocale(new Locale("nl")).format(new Date());
         }
     }
 

Since:
4.4


Copyright © 2002-2014 Atlassian. All Rights Reserved.