com.filenet.wcm.toolkit.server.util
Class WcmDateUtil

java.lang.Object
  extended bycom.filenet.wcm.toolkit.server.util.WcmDateUtil

public class WcmDateUtil
extends java.lang.Object

Various utility functions for working with dates.

The W3C DateTime format extends the ISO 8601 Date format:
YYYY-MM-DDThh:mm:ss[.sss][TimeZone] or YYYY-MM-DD[TimeZone]

where:

YYYY represents a 4-digit year.
MM represents a 2-digit month in the range of 01-12.
DD represents a 2-digit day in the range 01-31.
T is optional. If present, the format includes date and time, otherwise date only.
hh represents a 2-digit hour in the range of 00-23
mm represents a 2-digit minute in the range of 00-59
ss represents a 2-digit second in the range of 00-59
.sss is optional and represents milliseconds.
TimeZone is optional. It could be letter Z, which represents GMT, or time differences between local time and GMT, for example, in 1999-05-31T13:20:00-05:00, -05:00 is for EST. If it is not present, the time defaults to LOCAL TIME ZONE!

For reference, see http://www.w3.org/TR/NOTE-datetime


Field Summary
static java.util.TimeZone TIME_ZONE_GMT
           
 
Method Summary
static boolean compareDates(java.lang.String isoDateOne, java.lang.String isoDateTwo)
          Compares dates and returns true if they are equal
static java.lang.String convertDateToW3CDate(java.util.Calendar cal, boolean bDateOnly)
          Converts Date object into W3C-date-formatted string.
static java.lang.String convertDateToW3CDate(java.util.Date date, boolean bDateOnly)
          Deprecated. Use convertDateToW3CDate(Calendar cal, boolean bDateOnly)
static java.util.Calendar convertW3CDateToCalendar(java.lang.String str, boolean hyphenated)
           
static java.util.Calendar convertW3CDateToCalendar(java.lang.String str, boolean hyphenated, java.util.TimeZone defaultTimeZone)
           
static java.util.Date convertW3CDateToDate(java.lang.String str)
          Parses the string with W3C-formatted date and returns java Date object.
static java.util.Date convertW3CDateToDate(java.lang.String str, boolean hyphenated)
          Parses the string with W3C-formatted date and returns java Date object.
static java.lang.String formatCompressedISODateTime(java.lang.String month, java.lang.String day, java.lang.String year)
          Puts the date in compressed W3C format without validation.
static java.lang.String formatDateTime(java.lang.String locale, java.lang.String isoDateTime, java.lang.String dateFormat, java.lang.String timeFormat)
          Formats a date using separate format strings for date and time format
static java.lang.String formatISODateTime(java.lang.String month, java.lang.String day, java.lang.String year)
          Puts the date in W3C format without validation.
static java.lang.String getFormattedDate(java.util.Locale locale, java.lang.String isoDateTime)
          Get the formatted date corresponding to the specified W3C formatted date/time using the specified locale.
static java.lang.String getFormattedDate(java.lang.String locale, java.lang.String isoDateTime)
          Get the formatted date corresponding to the specified W3C formatted date/time using the specified locale.
static java.lang.String getFormattedDateTime(java.util.Locale locale, java.lang.String isoDateTime)
          Get the formatted date/time corresponding to the specified W3C formatted date/time using the specified locale.
static java.lang.String getFormattedDateTime(java.lang.String locale, java.lang.String isoDateTime)
          Get the formatted date/time corresponding to the specified W3C formatted date/time using the specified locale.
static java.lang.String localISODateTime(java.lang.String isoDateTime)
          Returns the date in W3C format shifted from GMT to local time.
static java.util.Date parseCompressedISODateTimeNoShift(java.lang.String isoDateTime)
          Parses an W3C-formatted date String into a Date object.
static java.util.Date parseISODateTimeNoShift(java.lang.String isoDateTime)
          Parses an W3C-formatted date String into a Date object.
static java.lang.String validateCompressedISODateTime(java.lang.String newDate, java.lang.String min, java.lang.String max)
          Validates a date and returns it in GMT time zone.
static java.lang.String validateISODateTime(java.lang.String newDate, java.lang.String min, java.lang.String max)
          Validates a date and returns it in GMT time zone.
static java.lang.String validateISODateTimeNoShift(java.lang.String input, java.lang.String min, java.lang.String max, java.util.Locale locale, java.util.TimeZone tz)
          Validates a date for min and max.
static boolean validateMonthDayYear(int month, int day, int year)
          Validates the month, day, and year values of a date.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TIME_ZONE_GMT

public static final java.util.TimeZone TIME_ZONE_GMT
Method Detail

formatDateTime

public static java.lang.String formatDateTime(java.lang.String locale,
                                              java.lang.String isoDateTime,
                                              java.lang.String dateFormat,
                                              java.lang.String timeFormat)
                                       throws java.lang.Exception
Formats a date using separate format strings for date and time format

Parameters:
locale - encoded locale
isoDateTime - date/time in iso gmt
dateFormat -
timeFormat -
Returns:
formatted date/time as a String
Throws:
java.lang.Exception

getFormattedDate

public static java.lang.String getFormattedDate(java.util.Locale locale,
                                                java.lang.String isoDateTime)
                                         throws java.lang.Exception
Get the formatted date corresponding to the specified W3C formatted date/time using the specified locale.

Parameters:
locale - The Locale object specifying the locale
isoDateTime - The W3C date/time value in GTM time zone
Returns:
The formatted date/time as a String in LOCAL time zone
Throws:
java.lang.Exception

getFormattedDate

public static java.lang.String getFormattedDate(java.lang.String locale,
                                                java.lang.String isoDateTime)
                                         throws java.lang.Exception
Get the formatted date corresponding to the specified W3C formatted date/time using the specified locale.

Parameters:
locale - The String locale value as specified by WcmUi.encodeLocale
isoDateTime - The W3C date/time value in GTM time zone
Returns:
The formatted date/time as a String in LOCAL time zone
Throws:
java.lang.Exception

getFormattedDateTime

public static java.lang.String getFormattedDateTime(java.util.Locale locale,
                                                    java.lang.String isoDateTime)
                                             throws java.lang.Exception
Get the formatted date/time corresponding to the specified W3C formatted date/time using the specified locale.

Parameters:
locale - The Locale object specifying the locale
isoDateTime - The W3C date/time value in GMT time zone
Returns:
The formatted date/time as a String in LOCAL time zone
Throws:
java.lang.Exception

getFormattedDateTime

public static java.lang.String getFormattedDateTime(java.lang.String locale,
                                                    java.lang.String isoDateTime)
                                             throws java.lang.Exception
Get the formatted date/time corresponding to the specified W3C formatted date/time using the specified locale.

Parameters:
locale - The String locale value as specified by WcmUi.encodeLocale
isoDateTime - The W3C date/time value in GMT time zone
Returns:
The formatted date/time as a String in LOCAL time zone
Throws:
java.lang.Exception

localISODateTime

public static java.lang.String localISODateTime(java.lang.String isoDateTime)
                                         throws java.lang.Exception
Returns the date in W3C format shifted from GMT to local time.

Parameters:
isoDateTime - The W3C date/time value in GMT time zone
Returns:
The W3C date/time value in LOCAL time zone
Throws:
java.lang.Exception

formatISODateTime

public static java.lang.String formatISODateTime(java.lang.String month,
                                                 java.lang.String day,
                                                 java.lang.String year)
Puts the date in W3C format without validation. Pads with leading zeros as needed. Caller should make sure the month and day are 2 chars or less, and the year is 4 chars or less.

Parameters:
month - The month, 2 chars or less
day - The day, 2 chars or less
year - The year, 4 chars or less
Returns:
The date in W3C format without validation

formatCompressedISODateTime

public static java.lang.String formatCompressedISODateTime(java.lang.String month,
                                                           java.lang.String day,
                                                           java.lang.String year)
Puts the date in compressed W3C format without validation. Pads with leading zeros as needed. Caller should make sure the month and day are 2 chars or less, and the year is 4 chars or less.

Parameters:
month - The month, 2 chars or less
day - The day, 2 chars or less
year - The year, 4 chars or less
Returns:
The date in compressed W3C format without validation

validateISODateTimeNoShift

public static java.lang.String validateISODateTimeNoShift(java.lang.String input,
                                                          java.lang.String min,
                                                          java.lang.String max,
                                                          java.util.Locale locale,
                                                          java.util.TimeZone tz)
                                                   throws java.lang.Exception
Validates a date for min and max. Does not do any time conversion.

Parameters:
input - The date to validate in ISO format, GMT time.
min - The minimum date value in W3C format
max - The maximum date value in W3C format
Throws:
java.lang.Exception

validateISODateTime

public static java.lang.String validateISODateTime(java.lang.String newDate,
                                                   java.lang.String min,
                                                   java.lang.String max)
                                            throws java.lang.Exception
Validates a date and returns it in GMT time zone.

Parameters:
newDate - The date to validate in W3C format, local time
min - The minimum date value in W3C format
max - The maximum date value in W3C format
Returns:
The validated date in W3C format, GMT time
Throws:
java.lang.Exception

validateCompressedISODateTime

public static java.lang.String validateCompressedISODateTime(java.lang.String newDate,
                                                             java.lang.String min,
                                                             java.lang.String max)
                                                      throws java.lang.Exception
Validates a date and returns it in GMT time zone.

Parameters:
newDate - The date to validate in W3C format, local time
min - The minimum date value in W3C format
max - The maximum date value in W3C format
Returns:
The validated date in W3C format, GMT time
Throws:
java.lang.Exception

validateMonthDayYear

public static boolean validateMonthDayYear(int month,
                                           int day,
                                           int year)
Validates the month, day, and year values of a date.

Parameters:
month - Integer holding the month
day - Integer holding the day
year - Integer holding the year
Returns:
True if the date validates successfully; False otherwise

parseISODateTimeNoShift

public static java.util.Date parseISODateTimeNoShift(java.lang.String isoDateTime)
                                              throws java.text.ParseException
Parses an W3C-formatted date String into a Date object. W3C-formatted date is NOT time shifted.

Parameters:
isoDateTime - The W3C formatted date/time
Returns:
An instance of Date object, un-shifted
Throws:
java.text.ParseException

parseCompressedISODateTimeNoShift

public static java.util.Date parseCompressedISODateTimeNoShift(java.lang.String isoDateTime)
                                                        throws java.text.ParseException
Parses an W3C-formatted date String into a Date object. W3C-formatted date is NOT time shifted.

Parameters:
isoDateTime - The W3C formatted date/time
Returns:
An instance of Date object, un-shifted
Throws:
java.text.ParseException

convertDateToW3CDate

public static java.lang.String convertDateToW3CDate(java.util.Date date,
                                                    boolean bDateOnly)
Deprecated. Use convertDateToW3CDate(Calendar cal, boolean bDateOnly)


convertDateToW3CDate

public static java.lang.String convertDateToW3CDate(java.util.Calendar cal,
                                                    boolean bDateOnly)
Converts Date object into W3C-date-formatted string.

Parameters:
cal - an object of type java.util.date
bDateOnly - This is a pass-in parameter. If true, the returned W3C format string only contains date, otherwise if false, the returned string contains both date and time.
Returns:
a W3C-date-formatted string

compareDates

public static boolean compareDates(java.lang.String isoDateOne,
                                   java.lang.String isoDateTwo)
Compares dates and returns true if they are equal

Parameters:
isoDateOne - First date to compare
isoDateTwo - Second date to compare
Returns:
True if dates are equal

convertW3CDateToDate

public static java.util.Date convertW3CDateToDate(java.lang.String str)
                                           throws WcmException
Parses the string with W3C-formatted date and returns java Date object.

Parameters:
str - a String object containing an W3C-date-formatted string.
Returns:
Date object
Throws:
WcmException - if the input is not in the right format.

convertW3CDateToCalendar

public static java.util.Calendar convertW3CDateToCalendar(java.lang.String str,
                                                          boolean hyphenated)
                                                   throws WcmException
Throws:
WcmException

convertW3CDateToCalendar

public static java.util.Calendar convertW3CDateToCalendar(java.lang.String str,
                                                          boolean hyphenated,
                                                          java.util.TimeZone defaultTimeZone)
                                                   throws WcmException
Throws:
WcmException

convertW3CDateToDate

public static java.util.Date convertW3CDateToDate(java.lang.String str,
                                                  boolean hyphenated)
                                           throws WcmException
Parses the string with W3C-formatted date and returns java Date object.

Parameters:
str - a String object containing an W3C-date-formatted string.
hyphenated - Specify true to indicate date/time format either "2004-05-01..." or "20040501..."
Returns:
Date object
Throws:
WcmException - if the input is not in the right format.


© Copyright IBM Corp. 2002, 2007. All Rights Reserved.