ariba.util.formatter
Class UserDateFormatter

java.lang.Object
  extended by ariba.util.formatter.Formatter
      extended by ariba.util.formatter.DateFormatter
          extended by ariba.util.formatter.UserDateFormatter
All Implemented Interfaces:
Compare, StringParser

public class UserDateFormatter
extends DateFormatter

UserDateFormatter is a subclass of DateFormatter which is responsible for parsing user date strings, i.e. string typed in or selected by the user. Additional natural language processing is done to make date input more user-friendly. The localized strings for "today", "tomorrow", and "yesterday" are recognized and converted to the appropriate date relative to the current date. Day of week strings (e.g. "monday", "sunday", etc.) are also supported for input.


Field Summary
static java.lang.String ClassName
          Our Java class name.
 
Fields inherited from class ariba.util.formatter.DateFormatter
CannotParseDateKey, ConciseDateFormatKey, ConciseDateTimeFormatKey, DateMonthYearFormatKey, DayDateMonthYearFormatKey, DefaultFormatKey, FullDateMonthYearFormatKey, FullDateMonthYearTZFormatKey, FullDayDateMonthYearFormatKey, FullDayDateMonthYearTZFormatKey, LongDayDateMonthYearFormatKey, PaddedConciseDateFormatKey, PaddedConciseDateTimeFormatKey, PaddedDateTimeFormatKey
 
Fields inherited from interface ariba.util.core.Compare
EqualTo, GreaterThan, LessThan
 
Constructor Summary
UserDateFormatter()
          Creates a new UserDateFormatter.
 
Method Summary
 java.lang.String getDateString(Date date, java.util.Locale locale, java.util.TimeZone timeZone)
           
static java.lang.String getStringValue(Date date)
          Returns a formatted string for the given Date in the default locale.
static java.lang.String getStringValue(Date date, java.util.Locale locale, java.util.TimeZone timeZone)
          Returns a formatted string for the given Date in the given locale.
static java.lang.String getStringValue(Date date, java.util.TimeZone timeZone)
          Returns a formatted string for the given Date in the given timeZone using the default locale.
 java.lang.Object getValue(java.lang.Object object, java.util.Locale locale)
          Overrides DateFormatter.parseString() to call our static method for converting an object into a date.
 java.lang.Object parseString(java.lang.String string, java.util.Locale locale, java.util.TimeZone tz)
          Parse the given string as a Date in the given locale and time zone.
 java.lang.Object parseString(java.lang.String string, java.util.Locale locale, java.util.TimeZone tz, boolean calendarDate)
          Parse the given string as a Date in the given locale and time zone.
static Date parseUserDate(java.lang.String string)
          Tries to parse the given user string as a Date in the default locale.
static Date parseUserDate(java.lang.String string, boolean calendarDate)
          Tries to parse the given user string as a Date in the default locale.
static Date parseUserDate(java.lang.String string, java.util.Locale locale)
          Tries to parse the given user string as a Date in the given locale.
static Date parseUserDate(java.lang.String string, java.util.Locale locale, boolean calendarDate)
          Tries to parse the given user string as a Date in the given locale.
static Date parseUserDate(java.lang.String string, java.util.Locale locale, java.util.TimeZone tz, boolean calendarDate)
          Tries to parse the given user string as a Date in the given locale.
static Date userDateValue(java.lang.Object object)
          Returns a new Date derived from the given object in the default locale.
static Date userDateValue(java.lang.Object object, boolean calendarDate)
          Returns a new Date derived from the given object in the default locale.
static Date userDateValue(java.lang.Object object, java.util.Locale locale)
          Returns a new Date derived from the given object in the given locale.
static Date userDateValue(java.lang.Object object, java.util.Locale locale, boolean calendarDate)
          Returns a new Date derived from the given object in the given locale.
 
Methods inherited from class ariba.util.formatter.DateFormatter
compareDates, formatMillisAsDuration, getDatePatternEquivalentToSunFormat, getDateString, getDateString, getDateTimePatternEquivalentToSunFormat, getDateValue, getDateValue, getDateValue, getDateValue, getDefaultLocale, getDefaultTimeZone, getMillisecondsTest, getStringValue, getStringValue, getStringValue, getStringValue, getStringValue, getStringValue, getStringValueUsingFormats, getTimePatternEquivalentToSunFormat, parseDate, parseDate, parseDate, parseDate, parseDate, parseDate, parseDate, parseDate, parseDate, parseDate, parseDateCXML, parseDateCXMLWithMs, parseDateGMT, parseDateUsingFormats, parseDateUsingFormats, parseDateUsingFormats, parseDateUTC, parseString, toConciseDateString, toConciseDateString, toConciseDateString, toConciseDateTimeString, toConciseDateTimeString, toConciseDateTimeString, tocXML, tocXML, toDateMonthYearString, toDateMonthYearString, toDateMonthYearString, toDayDateMonthYearString, toDayDateMonthYearString, toDayDateMonthYearString, toDayOfWeekString, toDayOfWeekString, toFileTimeString, toFullDateMonthYearString, toFullDateMonthYearString, toFullDateMonthYearTZString, toFullDayDateMonthYearString, toFullDayDateMonthYearString, toFullDayDateMonthYearString, toFullDayDateMonthYearTZString, toGMT, toHourMinSecString, toHourMinSecString, toJavaFormat, toJavaFormat, toLongDayDateMonthYearString, toLongDayDateMonthYearString, toMilitaryTimeString, toPaddedConciseDateString, toPaddedConciseDateString, toPaddedConciseDateString, toPaddedConciseDateTimeString, toPaddedConciseDateTimeString, toPaddedConciseDateTimeString, toPaddedDateTimeString, toPaddedDateTimeString, toPaddedDateTimeString, toUTC, toYearMonthDate
 
Methods inherited from class ariba.util.formatter.Formatter
canFormatNulls, compare, compare, equal, equal, getFormat, getFormat, getFormatterClassForType, getFormatterForObject, getFormatterForType, getLocale, getStringValue, getStringValue, getValue, handlesNulls, isBidirectional, makeParseException, makeParseException, makeParseException, makeParseExceptionMessage, makeParseExceptionMessage, objectsAreEqual, objectsAreEqual, parse, parse, parseString, parseString, quickCompare, quickCompare, quickCompareValue, registerFormatter
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ClassName

public static final java.lang.String ClassName
Our Java class name.

See Also:
Constant Field Values
Constructor Detail

UserDateFormatter

public UserDateFormatter()
Creates a new UserDateFormatter.

Method Detail

getStringValue

public static java.lang.String getStringValue(Date date)
Returns a formatted string for the given Date in the default locale. Recognizes if the given Date is today and formats the output accordingly.

Parameters:
date - the Date to format into a string
Returns:
a string representation of the Date

getStringValue

public static java.lang.String getStringValue(Date date,
                                              java.util.TimeZone timeZone)
Returns a formatted string for the given Date in the given timeZone using the default locale. Recognizes if the given Date is today and formats the output accordingly.

Parameters:
date - the Date to format into a string
timeZone - the TimeZone to use for formatting
Returns:
a string representation of the Date

getStringValue

public static java.lang.String getStringValue(Date date,
                                              java.util.Locale locale,
                                              java.util.TimeZone timeZone)
Returns a formatted string for the given Date in the given locale. Recognizes if the given Date is today and formats the output accordingly.

Parameters:
date - the Date to format into a string
locale - the Locale to use for formatting
timeZone - the TimeZone to use for formatting
Returns:
a string representation of the Date

getDateString

public java.lang.String getDateString(Date date,
                                      java.util.Locale locale,
                                      java.util.TimeZone timeZone)

parseUserDate

public static Date parseUserDate(java.lang.String string,
                                 boolean calendarDate)
                          throws java.text.ParseException
Tries to parse the given user string as a Date in the default locale. In addition to the default date parsing, this method will also try to handle a number of more natural date strings, e.g. the string "today", "tomorrow", "monday", etc. It also handles cases where the string is incomplete, e.g. "2/21". In this case, the current year is used as the default.

Parameters:
string - the string to parse as a Date
calendarDate - if true, a calendar date will be created
Returns:
a Date derived from the string
Throws:
java.text.ParseException - if the string can't be parsed as a Date

parseUserDate

public static Date parseUserDate(java.lang.String string)
                          throws java.text.ParseException
Tries to parse the given user string as a Date in the default locale. In addition to the default date parsing, this method will also try to handle a number of more natural date strings, e.g. the string "today", "tomorrow", "monday", etc. It also handles cases where the string is incomplete, e.g. "2/21". In this case, the current year is used as the default.

Parameters:
string - the string to parse as a Date
Returns:
a Date derived from the string
Throws:
java.text.ParseException - if the string can't be parsed as a Date

parseUserDate

public static Date parseUserDate(java.lang.String string,
                                 java.util.Locale locale)
                          throws java.text.ParseException
Tries to parse the given user string as a Date in the given locale. In addition to the default date parsing, this method will also try to handle a number of more natural date strings, e.g. the string "today", "tomorrow", "monday", etc. It also handles cases where the string is incomplete, e.g. "2/21". In this case, the current year is used as the default.

Parameters:
string - the string to parse as a Date
locale - the Locale to use for parsing
Returns:
a Date derived from the string
Throws:
java.text.ParseException - if the string can't be parsed as a Date

parseUserDate

public static Date parseUserDate(java.lang.String string,
                                 java.util.Locale locale,
                                 boolean calendarDate)
                          throws java.text.ParseException
Tries to parse the given user string as a Date in the given locale. In addition to the default date parsing, this method will also try to handle a number of more natural date strings, e.g. the string "today", "tomorrow", "monday", etc. It also handles cases where the string is incomplete, e.g. "2/21". In this case, the current year is used as the default.

Parameters:
string - the string to parse as a Date
locale - the Locale to use for parsing
calendarDate - if true, a calendar date will be created
Returns:
a Date derived from the string
Throws:
java.text.ParseException - if the string can't be parsed as a Date

parseUserDate

public static Date parseUserDate(java.lang.String string,
                                 java.util.Locale locale,
                                 java.util.TimeZone tz,
                                 boolean calendarDate)
                          throws java.text.ParseException
Tries to parse the given user string as a Date in the given locale. In addition to the default date parsing, this method will also try to handle a number of more natural date strings, e.g. the string "today", "tomorrow", "monday", etc. It also handles cases where the string is incomplete, e.g. "2/21". In this case, the current year is used as the default.

Parameters:
string - the string to parse as a Date
locale - the Locale to use for parsing
tz - the TimeZone to use for parsing
calendarDate - if true, a calendar date will be created
Returns:
a Date derived from the string
Throws:
java.text.ParseException - if the string can't be parsed as a Date

userDateValue

public static Date userDateValue(java.lang.Object object,
                                 boolean calendarDate)
Returns a new Date derived from the given object in the default locale. If the object is not a Date, it is converted to a string and parsed as a user string. Returns null if the object can't be converted to a Date.

Parameters:
object - the object to convert to a Date
calendarDate - if true, a calendar date will be created
Returns:
a Date derived from the given object

userDateValue

public static Date userDateValue(java.lang.Object object)
Returns a new Date derived from the given object in the default locale. If the object is not a Date, it is converted to a string and parsed as a user string. Returns null if the object can't be converted to a Date.

Parameters:
object - the object to convert to a Date
Returns:
a Date derived from the given object

userDateValue

public static Date userDateValue(java.lang.Object object,
                                 java.util.Locale locale)
Returns a new Date derived from the given object in the given locale. If the object is not a Date, it is converted to a string and parsed as a user string. Returns null if the object can't be converted to a Date.

Parameters:
object - the object to convert to a Date
locale - the Locale to use for conversion
Returns:
a Date derived from the given object

userDateValue

public static Date userDateValue(java.lang.Object object,
                                 java.util.Locale locale,
                                 boolean calendarDate)
Returns a new Date derived from the given object in the given locale. If the object is not a Date, it is converted to a string and parsed as a user string. Returns null if the object can't be converted to a Date.

Parameters:
object - the object to convert to a Date
locale - the Locale to use for conversion
calendarDate - if true, a calendar date will be created
Returns:
a Date derived from the given object

parseString

public java.lang.Object parseString(java.lang.String string,
                                    java.util.Locale locale,
                                    java.util.TimeZone tz)
                             throws java.text.ParseException
Parse the given string as a Date in the given locale and time zone. The locale and timeZone parameters must be non-null.

Overrides:
parseString in class DateFormatter
Parameters:
string - the string to parse
locale - the Locale to use for parsing
tz - the TimeZone to use for parsing
Returns:
a Date object derived from the string
Throws:
java.text.ParseException - if the string can't be parsed as a Date object in the given locale

parseString

public java.lang.Object parseString(java.lang.String string,
                                    java.util.Locale locale,
                                    java.util.TimeZone tz,
                                    boolean calendarDate)
                             throws java.text.ParseException
Parse the given string as a Date in the given locale and time zone. The locale and timeZone parameters must be non-null.

Overrides:
parseString in class DateFormatter
Parameters:
string - the string to parse as a Date
locale - the Locale to use for parsing
tz - the TimeZone to use for parsing
calendarDate - if true, a calendar date will be created
Returns:
a Date derived from the string
Throws:
java.text.ParseException - if the string can't be parsed as a Date

getValue

public java.lang.Object getValue(java.lang.Object object,
                                 java.util.Locale locale)
Overrides DateFormatter.parseString() to call our static method for converting an object into a date.

Overrides:
getValue in class DateFormatter
Parameters:
object - the object to convert to a Date
locale - the Locale to use for conversion
Returns:
a Date derived from the string


AribaWeb User Interface Development Framework
Copyright © 2000-2014 Ariba, Inc. All Rights Reserved.