com.cometway.util
Class DateTools

java.lang.Object
  extended by com.cometway.util.DateTools

public class DateTools
extends java.lang.Object

Set of utilities for manipulating date info.


Field Summary
protected static java.lang.String[] daysTable
           
static java.text.SimpleDateFormat ISO8601_DATEFORMAT
           
static java.text.SimpleDateFormat ISO8601_DATETIMEFORMAT
           
static java.text.SimpleDateFormat ISO8601_TIMEFORMAT
           
static int kDaysPerWeek
           
static int kMonthsPerYear
           
protected static java.lang.String[] monthsTable
           
 
Constructor Summary
DateTools()
           
 
Method Summary
static java.lang.String getAbbrDate(java.util.Date date)
          Returns a date string in this formate: MMM D, YYYY or MMM DD, YYYY where M=month, D=date, and Y = year.
static java.lang.String getAbbrDate(java.util.Date date, java.util.TimeZone tz)
           
static java.lang.String getDay(int theDay)
          Retuns a string of the Day, no abbreviation, given the day int.
static java.lang.String getDay(int theDay, int maxLength)
          Returns a string of the Day, abbreivate to maxLength characters.
static java.lang.String getLongDate(java.util.Date date)
          Returns a date string like getAbbrDate except the month is not abbreviated.
static java.lang.String getLongDate(java.util.Date date, java.util.TimeZone tz)
           
static java.lang.String getMonth(int theMonth)
          get the String name of the month from the int value of the month (0-11)
static java.lang.String getMonth(int theMonth, int maxLength)
          get the String name of the month and truncate it to maxLength if needed
static java.lang.String getShortDate(java.util.Date date)
          returns a date string in the format: MM/DD/YY, where MM is the month int+1, DD is the date, and YY is the year.
static java.lang.String getShortDate(java.util.Date date, java.util.TimeZone tz)
           
static java.lang.String getShortDateTime(java.util.Date date, boolean wantYear, boolean wantSeconds)
          returns an abbreviated date string with the time
static java.lang.String getShortDateTime(java.util.Date date, boolean wantYear, boolean wantSeconds, java.util.TimeZone tz)
           
static java.lang.String getTime(java.util.Date date, boolean wantSeconds)
          returns a time string
static java.lang.String getTime(java.util.Date date, boolean wantSeconds, java.util.TimeZone tz)
           
static java.util.Date parseISO8601String(java.lang.String dateStr)
           
static java.util.Date today()
           
static java.lang.String toISO8601String(java.util.Date d)
           
static java.lang.String toRFC822String(java.util.Date inDate)
          Returns a date string specified by RFC 822: \"Standard for the format of ARPA Internet Messages\".
static java.lang.String toRFC822String(java.util.Date inDate, java.util.TimeZone tz)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

kDaysPerWeek

public static final int kDaysPerWeek
See Also:
Constant Field Values

kMonthsPerYear

public static final int kMonthsPerYear
See Also:
Constant Field Values

daysTable

protected static final java.lang.String[] daysTable

monthsTable

protected static final java.lang.String[] monthsTable

ISO8601_DATETIMEFORMAT

public static final java.text.SimpleDateFormat ISO8601_DATETIMEFORMAT

ISO8601_DATEFORMAT

public static final java.text.SimpleDateFormat ISO8601_DATEFORMAT

ISO8601_TIMEFORMAT

public static final java.text.SimpleDateFormat ISO8601_TIMEFORMAT
Constructor Detail

DateTools

public DateTools()
Method Detail

toISO8601String

public static java.lang.String toISO8601String(java.util.Date d)

parseISO8601String

public static java.util.Date parseISO8601String(java.lang.String dateStr)
                                         throws java.text.ParseException
Throws:
java.text.ParseException

getAbbrDate

public static java.lang.String getAbbrDate(java.util.Date date)
Returns a date string in this formate: MMM D, YYYY or MMM DD, YYYY where M=month, D=date, and Y = year.

Parameters:
date - This is the date object to convert to string.
Returns:
A string in the above format.

getAbbrDate

public static java.lang.String getAbbrDate(java.util.Date date,
                                           java.util.TimeZone tz)

getDay

public static java.lang.String getDay(int theDay)
Retuns a string of the Day, no abbreviation, given the day int.


getDay

public static java.lang.String getDay(int theDay,
                                      int maxLength)
Returns a string of the Day, abbreivate to maxLength characters.


getLongDate

public static java.lang.String getLongDate(java.util.Date date)
Returns a date string like getAbbrDate except the month is not abbreviated.


getLongDate

public static java.lang.String getLongDate(java.util.Date date,
                                           java.util.TimeZone tz)

getMonth

public static java.lang.String getMonth(int theMonth)
get the String name of the month from the int value of the month (0-11)


getMonth

public static java.lang.String getMonth(int theMonth,
                                        int maxLength)
get the String name of the month and truncate it to maxLength if needed


getShortDate

public static java.lang.String getShortDate(java.util.Date date)
returns a date string in the format: MM/DD/YY, where MM is the month int+1, DD is the date, and YY is the year.


getShortDate

public static java.lang.String getShortDate(java.util.Date date,
                                            java.util.TimeZone tz)

getShortDateTime

public static java.lang.String getShortDateTime(java.util.Date date,
                                                boolean wantYear,
                                                boolean wantSeconds)
returns an abbreviated date string with the time


getShortDateTime

public static java.lang.String getShortDateTime(java.util.Date date,
                                                boolean wantYear,
                                                boolean wantSeconds,
                                                java.util.TimeZone tz)

getTime

public static java.lang.String getTime(java.util.Date date,
                                       boolean wantSeconds)
returns a time string


getTime

public static java.lang.String getTime(java.util.Date date,
                                       boolean wantSeconds,
                                       java.util.TimeZone tz)

today

public static java.util.Date today()

toRFC822String

public static java.lang.String toRFC822String(java.util.Date inDate)
Returns a date string specified by RFC 822: \"Standard for the format of ARPA Internet Messages\".

Parameters:
inDate - This is the Date to turn into a string, null will give current date
Returns:
Returns a string in the form of: day, date month year time zone-offset <=> 3*ALPHA ", " 2*DIGIT " " 3*ALPHA " " 4*DIGIT " " 2*DIGIT ":" 2*DIGIT ":" 2*DIGIT " " ("+"/"-")4*DIGIT

toRFC822String

public static java.lang.String toRFC822String(java.util.Date inDate,
                                              java.util.TimeZone tz)