com.atlassian.jira.web.util
Class OutlookDate

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

public class OutlookDate
extends java.lang.Object

Class to give a nice String representation of a date (inspired by Outlook)

Note: This class is not Threadsafe due to its use of DateFormat objects. Do not cache this object across Threads.


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(java.util.Locale locale)
           
OutlookDate(java.util.Locale locale, ApplicationProperties applicationProperties)
           
 
Method Summary
 int daysAgo(java.util.Date date)
           
 int daysAgo(java.util.Date theDate, java.util.Date theReferenceDate)
          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).
 java.lang.String format()
           
 java.lang.String format(java.util.Date date)
          Attempt to format a date in a nice way, by using words like "Today", "Yesterday" or the day of the week if the date falls within the previous week.
 java.lang.String format(java.util.Date date, java.util.Locale remoteUserLocale)
          Deprecated. Please use format(java.util.Date) instead.
 java.lang.String formatDatePicker(java.util.Date date)
           
 java.lang.String formatDateTimePicker(java.util.Date date)
           
 java.lang.String formatDay(java.util.Date date)
           
 java.lang.String formatDMY(java.util.Date date)
           
 java.lang.String formatDMYHMS(java.util.Date date)
           
 java.lang.String formatIso8601(java.util.Date date)
          Formats the given date into ISO8601 format.
 java.lang.String formatIso8601Date(java.util.Date date)
          Formats the given date into ISO8601 format.
static java.lang.String formatRss(java.util.Date date)
          Format a date for RSS feeds.
static java.lang.String formatRssRfc822(java.util.Date date)
          Formats a date using the correct RFC822 format as indicated in the RSS v2 specification and not using the MailDateFormat which is technically incorrect.
 java.lang.String formatSmart(java.util.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.
 java.lang.String formatTime(java.util.Date date)
           
 java.text.DateFormat getCompleteDateFormat()
          This helper is here to assist with formatting emails etc, and should only be used by JIRAVelocityManager.
 java.lang.String getCompleteDateTimeFormat()
           
 java.lang.String getDatePickerFormat()
           
 java.lang.String getDatePickerFormatSample(java.util.Date date)
           
 java.lang.String getDateTimePickerFormat()
           
 java.lang.String getDateTimePickerFormatSample(java.util.Date date)
           
 java.util.Locale getLocale()
           
 java.util.Date getNow()
          Returns new date
 boolean isDatePickerDate(java.lang.String value)
           
 java.util.Date parseCompleteDateTime(java.lang.String value)
           
 java.util.Date parseDatePicker(java.lang.String value)
           
 java.util.Date parseDateTimePicker(java.lang.String value)
           
static java.util.Date parseRss(java.lang.String rssDate)
          Parse a date from RSS feeds.
 
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(java.util.Locale locale)

OutlookDate

public OutlookDate(java.util.Locale locale,
                   ApplicationProperties applicationProperties)
Method Detail

getLocale

public java.util.Locale getLocale()

formatIso8601

public java.lang.String formatIso8601(java.util.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 java.lang.String formatIso8601Date(java.util.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

public java.lang.String formatDMY(java.util.Date date)

formatDMYHMS

public java.lang.String formatDMYHMS(java.util.Date date)

formatTime

public java.lang.String formatTime(java.util.Date date)

formatDay

public java.lang.String formatDay(java.util.Date date)

formatDatePicker

public java.lang.String formatDatePicker(java.util.Date date)

formatDateTimePicker

public java.lang.String formatDateTimePicker(java.util.Date date)

formatRss

public static java.lang.String formatRss(java.util.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 static java.lang.String formatRssRfc822(java.util.Date date)
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

parseRss

public static java.util.Date parseRss(java.lang.String rssDate)
                               throws java.text.ParseException
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:
java.text.ParseException - if string parsing fails

format

public java.lang.String format()

format

public java.lang.String format(java.util.Date date)
Attempt to format a date in a nice way, by using words like "Today", "Yesterday" or the day of the week if the date falls within the previous week. 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 java.lang.String formatSmart(java.util.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)

format

@Deprecated
public java.lang.String format(java.util.Date date,
                                          java.util.Locale remoteUserLocale)
Deprecated. Please use format(java.util.Date) instead.

Formats the given date.

Parameters:
date - date to format
remoteUserLocale - this parameter is ignored
Returns:
formatted date as string

getNow

public java.util.Date getNow()
Returns new date

Returns:
new date

daysAgo

public int daysAgo(java.util.Date date)

daysAgo

public int daysAgo(java.util.Date theDate,
                   java.util.Date theReferenceDate)
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

public java.util.Date parseCompleteDateTime(java.lang.String value)
                                     throws java.text.ParseException
Throws:
java.text.ParseException

parseDatePicker

public java.util.Date parseDatePicker(java.lang.String value)
                               throws java.text.ParseException
Throws:
java.text.ParseException

parseDateTimePicker

public java.util.Date parseDateTimePicker(java.lang.String value)
                                   throws java.text.ParseException
Throws:
java.text.ParseException

getDatePickerFormat

public java.lang.String getDatePickerFormat()

getDatePickerFormatSample

public java.lang.String getDatePickerFormatSample(java.util.Date date)

getDateTimePickerFormatSample

public java.lang.String getDateTimePickerFormatSample(java.util.Date date)

isDatePickerDate

public boolean isDatePickerDate(java.lang.String value)

getDateTimePickerFormat

public java.lang.String getDateTimePickerFormat()

getCompleteDateTimeFormat

public java.lang.String getCompleteDateTimeFormat()

getCompleteDateFormat

public java.text.DateFormat getCompleteDateFormat()
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-2010 Atlassian. All Rights Reserved.