com.atlassian.jira.web.util
Class OutlookDate

java.lang.Object
  extended by com.atlassian.jira.web.util.OutlookDate

public class OutlookDate
extends Object

Formats and parses dates in a variety of formats, including relative dates such as "Today" and "Last Wednesday".

Warning

As of JIRA 4.4, some of the methods in this class have been retrofitted to be time zone-aware. This means that if you call one of these methods, this class will attempt to determine the time zone of the user that is currently logged in, and will display times in that user's time zone if possible. If the user's time zone can not be determined, or if there is no logged in user, the methods will use the JIRA default user time zone. This is different to the previous behaviour, which was to use the JVM default timezone as returned by TimeZone.getDefault() when displaying dates. Please review each method's JavaDoc to determine whether you are affected by this change in behaviour.

See Also:
DateTimeFormatterFactory

Nested Class Summary
static class OutlookDate.SmartFormatterModes
          Modes used by formatSmart(java.util.Date, com.atlassian.jira.web.util.OutlookDate.SmartFormatterModes)
 
Field Summary
static long DAY
           
static long HOUR
           
static long MINUTE
           
static int OTHER
           
static long SECOND
           
static int THIS_WEEK
           
static int TODAY
           
static int YESTERDAY
           
 
Constructor Summary
OutlookDate(Locale locale)
          Deprecated. Use OutlookDate(java.util.Locale, com.atlassian.jira.config.properties.ApplicationProperties, com.atlassian.jira.util.I18nHelper.BeanFactory, com.atlassian.jira.datetime.DateTimeFormatterFactory) or better still OutlookDateManager. Since v4.3
OutlookDate(Locale locale, ApplicationProperties applicationProperties)
          Deprecated. Use OutlookDate(java.util.Locale, com.atlassian.jira.config.properties.ApplicationProperties, com.atlassian.jira.util.I18nHelper.BeanFactory, com.atlassian.jira.datetime.DateTimeFormatterFactory) or better still OutlookDateManager. Since v4.3
OutlookDate(Locale locale, ApplicationProperties applicationProperties, I18nHelper.BeanFactory i18nHelperFactory, DateTimeFormatterFactory dateTimeFormatterFactory)
           
 
Method Summary
 int daysAgo(Date date)
          Deprecated. Use Days.daysBetween(org.joda.time.ReadablePartial, org.joda.time.ReadablePartial) instead. Since v4.4.
 int daysAgo(Date theDate, Date theReferenceDate)
          Deprecated. Use Days.daysBetween(org.joda.time.ReadablePartial, org.joda.time.ReadablePartial) instead. Since v4.4.
 String format()
          Deprecated. Use DateTimeFormatter.format(java.util.Date) instead. Since v4.4.
 String format(Date date)
          Deprecated. Use DateTimeFormatter.format(java.util.Date) instead. Since v4.4.
 String formatDatePicker(Date date)
          Deprecated. Use DateTimeFormatter.format(java.util.Date) instead. Since v4.4.
 String formatDateTimePicker(Date date)
          Deprecated. Use DateTimeFormatter.format(java.util.Date) instead. Since v4.4.
 String formatDay(Date date)
          Deprecated. Use DateTimeFormatter.format(java.util.Date) instead. Since v4.4.
 String formatDMY(Date date)
          Deprecated. Use DateTimeFormatter.format(java.util.Date) instead. Since v4.4.
 String formatDMYHMS(Date date)
          Returns the given date formatted as a String in the current user's time zone if possible, in the format specified by DateTimeStyle.COMPLETE.
 String formatIso8601(Date date)
          Formats the given date into ISO8601 format.
 String formatIso8601Date(Date date)
          Formats the given date into ISO8601 format.
 String formatRss(Date date)
          Format a date for RSS feeds.
 String formatRssRfc822(Date date)
          Deprecated. Use DateTimeFormatter.format(java.util.Date) instead. Since v4.4.
 String formatSmart(Date date, OutlookDate.SmartFormatterModes mode)
          Format the date "smartly", by using the day of the week if the date falls within a week in either direction of the current date.
 String formatTime(Date date)
          Returns the given date formatted as a String in the current user's time zone if possible, in the format specified by DateTimeStyle.TIME.
 DateFormat getCompleteDateFormat()
          Deprecated. Use DateTimeFormatter.getFormatHint() instead. Since v4.4.
 String getCompleteDateTimeFormat()
          Deprecated. Use DateTimeFormatter.getFormatHint() instead. Since v4.4.
 String getDatePickerFormat()
          Deprecated. Use DateTimeFormatter.getFormatHint() instead. Since v4.4.
 String getDatePickerFormatSample(Date date)
          Deprecated. Use DateTimeFormatter.format(java.util.Date) instead. Since v4.4.
 String getDateTimePickerFormat()
          Deprecated. Use DateTimeFormatter.getFormatHint() instead. Since v4.4.
 String getDateTimePickerFormatSample(Date date)
          Deprecated. Use DateTimeFormatter.format(java.util.Date) instead. Since v4.4.
 Locale getLocale()
           
 Date getNow()
          Deprecated. Use Date.Date() instead. Since v4.4.
 boolean isDatePickerDate(String value)
           
 Date parseCompleteDateTime(String value)
          Deprecated. Use DateTimeFormatter.parse(String) instead. Since v4.4.
 Date parseDatePicker(String value)
          Deprecated. Use DateTimeFormatter.parse(String) instead. Since v4.4.
 Date parseDateTimePicker(String value)
          Deprecated. Use DateTimeFormatter.parse(String) instead. Since v4.4.
static Date parseRss(String rssDate)
          Deprecated. Use DateTimeFormatter.format(java.util.Date) instead. Since v4.4.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SECOND

public static final long SECOND
See Also:
Constant Field Values

MINUTE

public static final long MINUTE
See Also:
Constant Field Values

HOUR

public static final long HOUR
See Also:
Constant Field Values

DAY

public static final long DAY
See Also:
Constant Field Values

TODAY

public static final int TODAY
See Also:
Constant Field Values

YESTERDAY

public static final int YESTERDAY
See Also:
Constant Field Values

THIS_WEEK

public static final int THIS_WEEK
See Also:
Constant Field Values

OTHER

public static final int OTHER
See Also:
Constant Field Values
Constructor Detail

OutlookDate

public OutlookDate(Locale locale,
                   ApplicationProperties applicationProperties,
                   I18nHelper.BeanFactory i18nHelperFactory,
                   DateTimeFormatterFactory dateTimeFormatterFactory)

OutlookDate

public OutlookDate(Locale locale)
Deprecated. Use OutlookDate(java.util.Locale, com.atlassian.jira.config.properties.ApplicationProperties, com.atlassian.jira.util.I18nHelper.BeanFactory, com.atlassian.jira.datetime.DateTimeFormatterFactory) or better still OutlookDateManager. Since v4.3

An old constructor which is left here only for backward compatibility.

Parameters:
locale -

OutlookDate

public OutlookDate(Locale locale,
                   ApplicationProperties applicationProperties)
Deprecated. Use OutlookDate(java.util.Locale, com.atlassian.jira.config.properties.ApplicationProperties, com.atlassian.jira.util.I18nHelper.BeanFactory, com.atlassian.jira.datetime.DateTimeFormatterFactory) or better still OutlookDateManager. Since v4.3

An old constructor which is left here only for backward compatibility.

Parameters:
locale -
applicationProperties -
Method Detail

getLocale

public Locale getLocale()

formatIso8601

public String formatIso8601(Date date)
Formats the given date into ISO8601 format. This format contains date and time information and it is used by data marked with hCalendar microformat. If you need to use date information only use formatIso8601Date(java.util.Date) method instead.

Parameters:
date - date to format
Returns:
formatted date string

formatIso8601Date

public String formatIso8601Date(Date date)
Formats the given date into ISO8601 format. This format contains date information only and it is used by data marked with hCalendar microformat. If you need to use date and time information use formatIso8601(java.util.Date) method instead.

Parameters:
date - date to format
Returns:
formatted date string

formatDMY

@Deprecated
public String formatDMY(Date date)
Deprecated. Use DateTimeFormatter.format(java.util.Date) instead. Since v4.4.

Returns the given date formatted as a String in the current user's time zone if possible, in the format specified by DateTimeStyle.DATE.

Parameters:
date - a Date
Returns:
a String containing the formatted date

formatDMYHMS

public String formatDMYHMS(Date date)
Returns the given date formatted as a String in the current user's time zone if possible, in the format specified by DateTimeStyle.COMPLETE.

Parameters:
date - a Date
Returns:
a String containing the formatted date

formatTime

public String formatTime(Date date)
Returns the given date formatted as a String in the current user's time zone if possible, in the format specified by DateTimeStyle.TIME.

Parameters:
date - a Date
Returns:
a String containing the formatted date

formatDay

@Deprecated
public String formatDay(Date date)
Deprecated. Use DateTimeFormatter.format(java.util.Date) instead. Since v4.4.


formatDatePicker

@Deprecated
public String formatDatePicker(Date date)
Deprecated. Use DateTimeFormatter.format(java.util.Date) instead. Since v4.4.

Returns the given date formatted as a String in the current user's time zone if possible, in the format specified by DateTimeStyle.DATE_PICKER.


formatDateTimePicker

@Deprecated
public String formatDateTimePicker(Date date)
Deprecated. Use DateTimeFormatter.format(java.util.Date) instead. Since v4.4.

Returns the given date formatted as a String in the current user's time zone if possible, in the format specified by DateTimeStyle.DATE_TIME_PICKER.


formatRss

public String formatRss(Date date)
Format a date for RSS feeds. Uses MailDateFormat to format the given date. Returns an empty string if null is passed in.

Parameters:
date - date to format
Returns:
formatted date or empty string

formatRssRfc822

public String formatRssRfc822(Date date)
Deprecated. Use DateTimeFormatter.format(java.util.Date) instead. Since v4.4.

Formats a date using the correct RFC822 format as indicated in the RSS v2 specification and not using the MailDateFormat which is technically incorrect. MailDateFormat will however parse this format.

See http://cyber.law.harvard.edu/rss/rss.html

See http://asg.web.cmu.edu/rfc/rfc822.html#sec-5.1

Correct : Wed, 22 Aug 2007 10:00:10 +1000

Incorrect : Wed, 22 Aug 2007 10:00:10 +1000 (GMT+10:00)

Parameters:
date - the date to format into a string
Returns:
a date string in RFC822 format
Since:
v3.10.3
See Also:
format(java.util.Date)

parseRss

public static Date parseRss(String rssDate)
                     throws ParseException
Deprecated. Use DateTimeFormatter.format(java.util.Date) instead. Since v4.4.

Parse a date from RSS feeds. Uses MailDateFormat to parse the date.

Parameters:
rssDate - RSS date
Returns:
new Date created from the given string
Throws:
ParseException - if string parsing fails
See Also:
format(java.util.Date)

format

@Deprecated
public String format()
Deprecated. Use DateTimeFormatter.format(java.util.Date) instead. Since v4.4.

Returns the current date formatted as a String in the current user's time zone if possible, in the format specified by DateTimeStyle.RELATIVE.

See Also:
format(java.util.Date)

format

@Deprecated
public String format(Date date)
Deprecated. Use DateTimeFormatter.format(java.util.Date) instead. Since v4.4.

Returns the given date formatted as a String in the current user's time zone if possible, in the format specified by DateTimeStyle.RELATIVE.

Note: this only looks into the past. If you want to format dates in a nice way for future dates, use formatSmart(java.util.Date, com.atlassian.jira.web.util.OutlookDate.SmartFormatterModes)

Parameters:
date - the date to format
Returns:
the date printed (i18n)

formatSmart

public String formatSmart(Date date,
                          OutlookDate.SmartFormatterModes mode)
Format the date "smartly", by using the day of the week if the date falls within a week in either direction of the current date. If the date is in the past, we will use terminology such as "last Wednesday" to differentiate it from "Wednesday" (which is in the future).

Parameters:
date - the date to format
mode - whether or not to include the time in the printed date
Returns:
the date printed (i18n)

getNow

@Deprecated
public Date getNow()
Deprecated. Use Date.Date() instead. Since v4.4.

Returns new date

Returns:
new date

daysAgo

@Deprecated
public int daysAgo(Date date)
Deprecated. Use Days.daysBetween(org.joda.time.ReadablePartial, org.joda.time.ReadablePartial) instead. Since v4.4.


daysAgo

@Deprecated
public int daysAgo(Date theDate,
                              Date theReferenceDate)
Deprecated. Use Days.daysBetween(org.joda.time.ReadablePartial, org.joda.time.ReadablePartial) instead. Since v4.4.

The method determines whether the date (theDate) lies between the reference date and the previous midnight (TODAY), between the reference date and the midnight before previous (YESTERDAY), or between the reference date and 7 midnights ago (THIS_WEEK). If the passed in date does not fall in any of the mentioned ranges, the method returns OTHER.

Parameters:
theDate - the date we are asking about
theReferenceDate - the reference date (usually today's date)
Returns:
TODAY, YESTERDAY, THIS_WEEK or OTHER

parseCompleteDateTime

@Deprecated
public Date parseCompleteDateTime(String value)
                           throws ParseException
Deprecated. Use DateTimeFormatter.parse(String) instead. Since v4.4.

Parses the given text in COMPLETE format, using the current user's time zone and locale if possible. If there is no currently logged in user, or if the currently logged in user has not configured a time zone and/or locale the JIRA default time zone and/or locale is used.

Throws:
ParseException

parseDatePicker

@Deprecated
public Date parseDatePicker(String value)
                     throws ParseException
Deprecated. Use DateTimeFormatter.parse(String) instead. Since v4.4.

Parses the given text in DATE_PICKER or DATE_TIME_PICKER format, using the current user's time zone and locale if possible. If there is no currently logged in user, or if the currently logged in user has not configured a time zone and/or locale the JIRA default time zone and/or locale is used.

Throws:
ParseException

parseDateTimePicker

@Deprecated
public Date parseDateTimePicker(String value)
                         throws ParseException
Deprecated. Use DateTimeFormatter.parse(String) instead. Since v4.4.

Parses the given text in DATE_TIME_PICKER format, using the current user's time zone and locale if possible. If there is no currently logged in user, or if the currently logged in user has not configured a time zone and/or locale the JIRA default time zone and/or locale is used.

Throws:
ParseException

getDatePickerFormat

@Deprecated
public String getDatePickerFormat()
Deprecated. Use DateTimeFormatter.getFormatHint() instead. Since v4.4.


getDatePickerFormatSample

public String getDatePickerFormatSample(Date date)
Deprecated. Use DateTimeFormatter.format(java.util.Date) instead. Since v4.4.


getDateTimePickerFormatSample

public String getDateTimePickerFormatSample(Date date)
Deprecated. Use DateTimeFormatter.format(java.util.Date) instead. Since v4.4.


isDatePickerDate

public boolean isDatePickerDate(String value)

getDateTimePickerFormat

@Deprecated
public String getDateTimePickerFormat()
Deprecated. Use DateTimeFormatter.getFormatHint() instead. Since v4.4.


getCompleteDateTimeFormat

@Deprecated
public String getCompleteDateTimeFormat()
Deprecated. Use DateTimeFormatter.getFormatHint() instead. Since v4.4.


getCompleteDateFormat

@Deprecated
public DateFormat getCompleteDateFormat()
Deprecated. Use DateTimeFormatter.getFormatHint() instead. Since v4.4.

This helper is here to assist with formatting emails etc, and should only be used by JIRAVelocityManager.

Returns:
a DateFormat based on the run-time value of APKeys.JIRA_LF_DATE_COMPLETE


Copyright © 2002-2011 Atlassian. All Rights Reserved.