com.smartgwt.client.util
Class DateUtil

java.lang.Object
  extended by com.smartgwt.client.util.DateUtil

public class DateUtil
extends Object

Extensions to the Date class, including added static methods on the Date object, and additional instance methods available on all date instances.


Field Summary
static DateDisplayFormatter TO24HOURTIME
          String will display with seconds in 24 hour time: [H]H:MM:SS.
static DateDisplayFormatter TODATESTAMP
          Date in the format <YYYYMMDD>T<HHMMSS>Z Example: 20051104T111001Z
static DateDisplayFormatter TOEUROPEANSHORTDATE
          Short date in format DD/MM/YYYY.
Example: 4/11/2005
static DateDisplayFormatter TOEUROPEANSHORTDATETIME
          Short date with time in format DD/MM/YYYY HH:MM
Example: 4/11/2005 11:03
static DateDisplayFormatter TOJAPANSHORTDATE
          Short date in format YYYY/MM/DD.
Example: 2005/11/4
static DateDisplayFormatter TOJAPANSHORTDATETIME
          Short date with time in format YYYY/MM/DD HH:MM
Example: 2005/11/4 11:03
static DateDisplayFormatter TOLOCALESTRING
          Default native browser 'toLocaleString()' implementation.
static DateDisplayFormatter TONORMALDATE
          Normal date format for the locale
static DateDisplayFormatter TONORMALDATETIME
          Normal datetime format for the locale
static DateDisplayFormatter TOPADDED24HOURTIME
          String will display with seconds, with a 2 digit hour in 24 hour format: HH:MM:SS.
static DateDisplayFormatter TOPADDEDTIME
          String will display with seconds, with a 2 digit hour and am/pm indicator: HH:MM:SS am|pm.
static DateDisplayFormatter TOSERIALIZEABLEDATE
          Date in the format YYYY-MM-DD HH:MM:SS
Example: 2005-11-04 11:09:15
static DateDisplayFormatter TOSHORT24HOURTIME
          String will have no seconds and be in 24 hour format: [H]H:MM.
Example:15:25
static DateDisplayFormatter TOSHORTPADDED24HOURTIME
          String will have no seconds and will display with a 2 digit hour in 24 hour clock format: HH:MM.
Examples: 15:25, 03:16
static DateDisplayFormatter TOSHORTPADDEDTIME
          String will have no seconds and will display a 2 digit hour, in 12 hour clock format: HH:MM am|pm.
Example: 03:25 pm
static DateDisplayFormatter TOSHORTTIME
          String will have no seconds and be in 12 hour format: [H]H:MM am|pm.
Example: 3:25 pm
static DateDisplayFormatter TOSTRING
          Default native browser 'toString()' implementation.
static DateDisplayFormatter TOTIME
          String will display with seconds and am/pm indicator: [H]H:MM:SS am|pm.
static DateDisplayFormatter TOUSSHORTDATE
          Short date in format MM/DD/YYYY.
Example: 11/4/2005
static DateDisplayFormatter TOUSSHORTDATETIME
          Short date with time in format MM/DD/YYYY HH:MM
Example: 11/4/2005 11:03
 
Constructor Summary
DateUtil()
           
 
Method Summary
static void autoDetectFormats()
          Use the GWT LocaleInfo class to auto-detect the various formats for dates and times.
static Date combineLogicalDateAndTime(Date date, Date time)
          Combine a logical date (a value appropriate for a DataSourceField of type "date") with a logical time (a value appropriate for a DataSourceField of type "time") into a datetime value (a value appropriate for a DataSourceField of type "datetime")
static int compareDates(Date date1, Date date2)
          Compare two dates; returns 0 if equal, -1 if the first date is greater (later), or 1 if the second date is greater.
static int compareLogicalDates(Date date1, Date date2)
          Compare two dates, normalizing out the time elements so that only the date elements are considered; returns 0 if equal, -1 if the first date is greater (later), or 1 if the second date is greater.
static Date create()
          Create a new Date object - synonym for new Date(arguments)
static LogicalDate createLogicalDate(int year, int month, int date)
          Create a new Date to represent a logical date value (rather than a specific datetime value), typically for display in a +link{DataSourceField.type,date type field}.
static LogicalTime createLogicalTime(int hour, int minute, int second, int millisecond)
          Create a new Date object to represent a logical time value (rather than a specific datetime value), typically for display in a +link{DataSourceField.type,time type field}.
static String format(Date date)
          Format a date as a string according to the format specified by setNormalDateDisplayFormatter(DateDisplayFormatter).
static String format(Date date, String format)
          Format the parameter date using the parameter format string.
static String formatAsNormalDate(Date date)
          Format a date as a string according to the format specified by setNormalDateDisplayFormatter(DateDisplayFormatter).
static String formatAsShortDate(Date date)
          Format a date as a string according to the format specified by setShortDateDisplayFormatter(DateDisplayFormatter).
static String formatAsShortDatetime(Date date)
          Format a date as a string according to the format specified by setShortDatetimeDisplayFormatter(DateDisplayFormatter).
static Date getAbsoluteDate(RelativeDate relativeDate)
          Converts a RelativeDate to a concrete Date.
static Date getAbsoluteDate(RelativeDate relativeDate, Date baseDate, RelativeDateRangePosition position)
          Converts a RelativeDate to a concrete Date.
 String getDayName()
          Return the full day of week name for this date (Monday, Tuesday, etc).
static String getDefaultDateSeparator()
          Returns the default date separator.
static int getFirstDayOfWeek()
          Returns the global attribute that dictates which day should be treated as the first day of the week in calendars and date calculations.
static FiscalCalendar getFiscalCalendar()
          Returns the global FiscalCalendar object representing the start month and date of the fiscal year in the current locale.
static Date getFiscalStartDate(Date date)
          Returns the start date of the fiscal year for the passed date.
static Date getFiscalStartDate(Date date, FiscalCalendar fiscalCalendar)
          Returns the start date of the fiscal year for the passed date.
static Date getFiscalStartDate(Integer year, FiscalCalendar fiscalCalendar)
          Get the start date of the fiscal period for the passed year.
 int getFiscalWeek()
          Returns the fiscal week number of the current date, according to the global FiscalCalendar.
static int getFiscalWeek(Date date)
          Returns a date's week-number, according to the fiscal calendar
static int getFiscalWeek(Date date, FiscalCalendar fiscalCalendar)
          Returns a date's week-number, according to the fiscal calendar
 int getFiscalWeek(FiscalCalendar fiscalCalendar)
          Returns the fiscal week number of the current date, according to the global FiscalCalendar.
 FiscalYear getFiscalYear()
          Returns the FiscalYear object appropriate for the the current date, according to the FiscalCalendar.
static FiscalYear getFiscalYear(Date date)
          Returns the FiscalYear object for the fiscal year in which the passed date exists.
static FiscalYear getFiscalYear(Date date, FiscalCalendar fiscalCalendar)
          Returns the FiscalYear object for the fiscal year in which the passed date exists.
static String getInputFormat()
          Retrieves the default format for strings being parsed into dates via Date.parseInput()
static LogicalDate getLogicalDateOnly(Date date)
          Get a logical date - a value appropriate for a DataSourceField of type "date" - from a datetime value (a value from a DataSourceField of type "datetime").
static LogicalTime getLogicalTimeOnly(Date date)
          Get a logical time - a value appropriate for a DataSourceField of type "time" - from a datetime value (a value from a DataSourceField of type "datetime").
 String getMonthName()
          Return the full name of the month for this date (January, February, etc) To modify the value returned by this method, use com.smartgwt.client.util.DateUtil#setMonthNames().
 String getShortDayName(int length)
          Return the abbreviated (up to 3 chars) day of week name for this date (Mon, Tue, etc).
 String getShortMonthName(int length)
          Return the abbreviated name of the month for this date (Jan, Feb, etc) To modify the value returned by this method, use com.smartgwt.client.util.DateUtil#setShortMonthNames().
 String getShortYear()
          Return a 2 digit year for this date.
 int getWeek()
          Returns an integer containing the week number
static Integer[] getWeekendDays()
          Return an array of days that are considered "weekend" days.
static String mapRelativeDateShortcut(String relativeDateShortcut)
           
static String mapRelativeDateShortcut(String relativeDateShortcut, RelativeDateRangePosition position)
          Converts a RelativeDate shortcut string such as "$today" to a RelativeDateString such as "+0D"
static Date parseInput(String dateString)
          Parse a date passed in as a string, returning the appropriate date object.
static Date parseInput(String dateString, String format)
           
static Date parseInput(String dateString, String format, Integer centuryThreshold)
           
static Date parseInput(String dateString, String format, Integer centuryThreshold, Boolean suppressConversion)
          Parse a date passed in as a string, returning the appropriate date object.
static void setAdjustForDST(boolean adjustForDST)
          Determines whether, when formatting values of type datetime and time, the effect of Daylight Saving Time should be considered when computing offsets from UTC.
static void setDateInputFormat(String inputFormat)
          Sets up the default system-wide input format for strings being parsed into dates via SmartGWT utilities and components (see parseInput(String)).
static void setDateInputFormatter(DateInputFormatter formatter)
          Deprecated. in favor of setDateParser()
static void setDateParser(DateParser parser)
          Sets up a custom parsing function to use by default when converting dates or datetimes from formatted string values to Dates.
static void setDefaultDateSeparator(String separator)
          Sets a new default separator that will be used when formatting dates.
static void setDefaultDisplayTimezone(String offset)
          Globally sets the offset from UTC to use when formatting values of type datetime and time with standard display formatters.
static void setFirstDayOfWeek(int firstDayOfWeek)
          Sets the global attribute that dictates which day should be treated as the first day of the week in calendars and date calculations.
static void setFiscalCalendar(FiscalCalendar fiscalCalendar)
          Sets the global fiscal calendar, which is used for all calls to getFiscalYear() / getFiscalWeek() if those methods aren't passed a fiscalCalander.
static void setInputFormat(String format)
          Sets up the default system-wide input format for strings being parsed into dates via Date.parseInput().
static void setMonthNames(String[] monthNames)
          Set the array of names of months.
static void setNormalDateDisplayFormat(DateDisplayFormat format)
          Deprecated. This method is deprecated in favor of setNormalDateDisplayFormatter(DateDisplayFormatter).
static void setNormalDateDisplayFormatter(DateDisplayFormatter formatter)
          Set the default formatter for date objects to the custom DateDisplayFormatter passed in.
static void setNormalDatetimeDisplayFormatter(DateDisplayFormatter formatter)
          Set the default datetime format for date objects to the DateDisplayFormat passed in.
static void setNormalTimeDisplayFormatter(DateDisplayFormatter formatter)
          Set up a system wide default normal time formatting function.
static void setShortDateDisplayFormat(DateDisplayFormat format)
          Deprecated. This method is deprecated in favor of setShortDateDisplayFormatter(DateDisplayFormatter).
static void setShortDateDisplayFormatter(DateDisplayFormatter formatter)
          Set up a system wide default short date formatting function.
static void setShortDatetimeDisplayFormat(DateDisplayFormat format)
          Deprecated. This method is deprecated in favor of setShortDatetimeDisplayFormatter(DateDisplayFormatter).
static void setShortDatetimeDisplayFormatter(DateDisplayFormatter formatter)
          Set up a system wide default short datetime formatting function.
static void setShortDisplayFormat(String format)
          Set the default short format for dates.
static void setShortMonthNames(String[] shortMonthNames)
          Set the array of names of months.
static void setShortTimeDisplayFormatter(DateDisplayFormatter formatter)
          Set up a system wide default short time formatting function.
static void setShowChooserFiscalYearPickers(boolean showChooserFiscalYearPickers)
          Sets the global attribute that dictates whether the choosers shelled from DateItems show a UI for working with Fiscal Years.
static void setShowChooserWeekPickers(boolean showChooserWeekPickers)
          Sets the global attribute that dictates whether the choosers shelled from DateItems show a UI for working with Weeks.
static void setWeekendDays(Integer[] weekendDays)
          Sets the days that are considered weekend days.
 String toDateStamp()
          Return this date in the format (UTC timezone): YYYYMMDDTHHMMSS[Z]
 String toEuropeanShortDate()
          Return this date in the format: DD/MM/YYYY
 String toEuropeanShortDateTime()
          Return this date in the format: DD/MM/YYYY HH:MM.
 String toJapanShortDate()
          Return the date in this format: YYYY/MM/DD
 String toJapanShortDateTime()
          Return this date in the format: YYYY/MM/DD HH:MM:SS
 String toNormalDate(DateDisplayFormat format)
          Returns the date as a formatted string using the format set up via the setNormalDisplayFormat() method.
 String toNormalDatetime(DateDisplayFormat format)
          Returns the datetime as a formatted string using the format set up via the setNormalDatetimeDisplayFormat() method.
 String toNormalDatetime(DateDisplayFormat format, Boolean useCustomTimezone)
          Returns the datetime as a formatted string using the format set up via the setNormalDatetimeDisplayFormat() method.
 String toSerializeableDate()
          Return this date in 'serialized' format YYYY-MM-DD HH:MM:SS
 String toShortDate(DateDisplayFormat format)
          Returns the date as a formatted string using the format set up via the setShortDisplayFormat() method.
 String toShortDate(DateDisplayFormat format, Boolean useCustomTimezone)
          Returns the date as a formatted string using the format set up via the setShortDisplayFormat() method.
 String toShortDateTime(DateDisplayFormat format)
          Returns the datetime as a formatted string using the format set up via the setShortDatetimeDisplayFormat() method.
 String toShortDateTime(DateDisplayFormat format, Boolean useCustomTimezone)
          Returns the datetime as a formatted string using the format set up via the setShortDatetimeDisplayFormat() method.
 String toUSShortDate()
          Return this date in the format: MM/DD/YYYY
 String toUSShortDateTime()
          Return this date in the format: MM/DD/YYYY HH:MM
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TOSTRING

public static final DateDisplayFormatter TOSTRING
Default native browser 'toString()' implementation. May vary by browser.
Example: Fri Nov 04 2005 11:03:00 GMT-0800 (Pacific Standard Time)


TOLOCALESTRING

public static final DateDisplayFormatter TOLOCALESTRING
Default native browser 'toLocaleString()' implementation. May vary by browser. Example: Friday, November 04, 2005 11:03:00 AM


TONORMALDATE

public static final DateDisplayFormatter TONORMALDATE
Normal date format for the locale


TONORMALDATETIME

public static final DateDisplayFormatter TONORMALDATETIME
Normal datetime format for the locale


TOUSSHORTDATE

public static final DateDisplayFormatter TOUSSHORTDATE
Short date in format MM/DD/YYYY.
Example: 11/4/2005


TOUSSHORTDATETIME

public static final DateDisplayFormatter TOUSSHORTDATETIME
Short date with time in format MM/DD/YYYY HH:MM
Example: 11/4/2005 11:03


TOEUROPEANSHORTDATE

public static final DateDisplayFormatter TOEUROPEANSHORTDATE
Short date in format DD/MM/YYYY.
Example: 4/11/2005


TOEUROPEANSHORTDATETIME

public static final DateDisplayFormatter TOEUROPEANSHORTDATETIME
Short date with time in format DD/MM/YYYY HH:MM
Example: 4/11/2005 11:03


TOJAPANSHORTDATE

public static final DateDisplayFormatter TOJAPANSHORTDATE
Short date in format YYYY/MM/DD.
Example: 2005/11/4


TOJAPANSHORTDATETIME

public static final DateDisplayFormatter TOJAPANSHORTDATETIME
Short date with time in format YYYY/MM/DD HH:MM
Example: 2005/11/4 11:03


TOSERIALIZEABLEDATE

public static final DateDisplayFormatter TOSERIALIZEABLEDATE
Date in the format YYYY-MM-DD HH:MM:SS
Example: 2005-11-04 11:09:15


TODATESTAMP

public static final DateDisplayFormatter TODATESTAMP
Date in the format <YYYYMMDD>T<HHMMSS>Z Example: 20051104T111001Z


TOTIME

public static final DateDisplayFormatter TOTIME
String will display with seconds and am/pm indicator: [H]H:MM:SS am|pm.
Example: 3:25:15 pm


TO24HOURTIME

public static final DateDisplayFormatter TO24HOURTIME
String will display with seconds in 24 hour time: [H]H:MM:SS.
Example: 15:25:15


TOPADDEDTIME

public static final DateDisplayFormatter TOPADDEDTIME
String will display with seconds, with a 2 digit hour and am/pm indicator: HH:MM:SS am|pm.
Example: 03:25:15 pm


TOPADDED24HOURTIME

public static final DateDisplayFormatter TOPADDED24HOURTIME
String will display with seconds, with a 2 digit hour in 24 hour format: HH:MM:SS.
Examples: 15:25:15, 03:16:45


TOSHORTTIME

public static final DateDisplayFormatter TOSHORTTIME
String will have no seconds and be in 12 hour format: [H]H:MM am|pm.
Example: 3:25 pm


TOSHORT24HOURTIME

public static final DateDisplayFormatter TOSHORT24HOURTIME
String will have no seconds and be in 24 hour format: [H]H:MM.
Example:15:25


TOSHORTPADDEDTIME

public static final DateDisplayFormatter TOSHORTPADDEDTIME
String will have no seconds and will display a 2 digit hour, in 12 hour clock format: HH:MM am|pm.
Example: 03:25 pm


TOSHORTPADDED24HOURTIME

public static final DateDisplayFormatter TOSHORTPADDED24HOURTIME
String will have no seconds and will display with a 2 digit hour in 24 hour clock format: HH:MM.
Examples: 15:25, 03:16

Constructor Detail

DateUtil

public DateUtil()
Method Detail

getDayName

public String getDayName()
Return the full day of week name for this date (Monday, Tuesday, etc). To modify the value returned by this method, set dayNames

Returns:
Day name

getFiscalWeek

public int getFiscalWeek()
Returns the fiscal week number of the current date, according to the global FiscalCalendar.

Returns:
the week number, offset from the start of the fiscal period

getFiscalWeek

public int getFiscalWeek(FiscalCalendar fiscalCalendar)
Returns the fiscal week number of the current date, according to the global FiscalCalendar.

Parameters:
fiscalCalendar - the object representing the starts of fiscal years
Returns:
the week number, offset from the start of the fiscal period

getFiscalYear

public FiscalYear getFiscalYear()
Returns the FiscalYear object appropriate for the the current date, according to the FiscalCalendar.

Returns:
the fiscal year object

getMonthName

public String getMonthName()
Return the full name of the month for this date (January, February, etc) To modify the value returned by this method, use com.smartgwt.client.util.DateUtil#setMonthNames().

Returns:
Month name

getShortDayName

public String getShortDayName(int length)
Return the abbreviated (up to 3 chars) day of week name for this date (Mon, Tue, etc). To modify the value returned by this method, set shortDayNames

Parameters:
length - Number of characters to return (Defaults to 3, can't be longer than 3)
Returns:
Abbreviated day name

getShortMonthName

public String getShortMonthName(int length)
Return the abbreviated name of the month for this date (Jan, Feb, etc) To modify the value returned by this method, use com.smartgwt.client.util.DateUtil#setShortMonthNames().

Parameters:
length - Number of characters to return (Defaults to 3, can't be longer than 3)
Returns:
Abbreviated month name (3 character string)

getShortYear

public String getShortYear()
Return a 2 digit year for this date.

Returns:
year number, padded to 2 characters

getWeek

public int getWeek()
Returns an integer containing the week number

Returns:
week number, starting with 1

toDateStamp

public String toDateStamp()
Return this date in the format (UTC timezone): YYYYMMDDTHHMMSS[Z]

Returns:
formatted date string

toEuropeanShortDate

public String toEuropeanShortDate()
Return this date in the format: DD/MM/YYYY

Returns:
formatted date string

toEuropeanShortDateTime

public String toEuropeanShortDateTime()
Return this date in the format: DD/MM/YYYY HH:MM.

Returns:
formatted date string

toJapanShortDate

public String toJapanShortDate()
Return the date in this format: YYYY/MM/DD

Returns:
formatted date string

toJapanShortDateTime

public String toJapanShortDateTime()
Return this date in the format: YYYY/MM/DD HH:MM:SS

Returns:
formatted date string

toNormalDate

public String toNormalDate(DateDisplayFormat format)
Returns the date as a formatted string using the format set up via the setNormalDisplayFormat() method. Note that the default formatter for this method is "toLocaleString".

Parameters:
format - Optional Format for the date returned
Returns:
formatted date string

toNormalDatetime

public String toNormalDatetime(DateDisplayFormat format)
Returns the datetime as a formatted string using the format set up via the setNormalDatetimeDisplayFormat() method.

Parameters:
format - Optional Format for the date returned
Returns:
formatted date string

toNormalDatetime

public String toNormalDatetime(DateDisplayFormat format,
                               Boolean useCustomTimezone)
Returns the datetime as a formatted string using the format set up via the setNormalDatetimeDisplayFormat() method.

Parameters:
format - Optional Format for the date returned
useCustomTimezone - If a custom timezone has been set via Time.setDefaultDisplayTimezone(), by default date formatters will respect this timezone. To suppress this behavior, this parameter should be set to false.
Returns:
formatted date string

toSerializeableDate

public String toSerializeableDate()
Return this date in 'serialized' format YYYY-MM-DD HH:MM:SS

Returns:
formatted date string

toShortDate

public String toShortDate(DateDisplayFormat format)
Returns the date as a formatted string using the format set up via the setShortDisplayFormat() method.

Parameters:
format - Optional Format for the date returned
Returns:
formatted date string

toShortDate

public String toShortDate(DateDisplayFormat format,
                          Boolean useCustomTimezone)
Returns the date as a formatted string using the format set up via the setShortDisplayFormat() method.

Parameters:
format - Optional Format for the date returned
useCustomTimezone - If a custom timezone has been set via Time.setDefaultDisplayTimezone(), by default date formatters will respect this timezone. to suppress this behavior, this parameter should be set to false.
Returns:
formatted date string

toShortDateTime

public String toShortDateTime(DateDisplayFormat format)
Returns the datetime as a formatted string using the format set up via the setShortDatetimeDisplayFormat() method.

Parameters:
format - Optional Format for the date returned
Returns:
formatted date string

toShortDateTime

public String toShortDateTime(DateDisplayFormat format,
                              Boolean useCustomTimezone)
Returns the datetime as a formatted string using the format set up via the setShortDatetimeDisplayFormat() method.

Parameters:
format - Optional Format for the date returned
useCustomTimezone - If a custom timezone has been set via Time.setDefaultDisplayTimezone(), by default date formatters will respect this timezone. to suppress this behavior, this parameter should be set to false.
Returns:
formatted date string

toUSShortDate

public String toUSShortDate()
Return this date in the format: MM/DD/YYYY

Returns:
formatted date string

toUSShortDateTime

public String toUSShortDateTime()
Return this date in the format: MM/DD/YYYY HH:MM

Returns:
formatted date string

compareDates

public static int compareDates(Date date1,
                               Date date2)
Compare two dates; returns 0 if equal, -1 if the first date is greater (later), or 1 if the second date is greater. If either value is not a Date object, it is treated as the epoch (midnight on Jan 1 1970) for comparison purposes.

Parameters:
date1 - first date to compare
date2 - second date to compare
Returns:
0 if equal, -1 if first date > second date, 1 if second date > first date

compareLogicalDates

public static int compareLogicalDates(Date date1,
                                      Date date2)
Compare two dates, normalizing out the time elements so that only the date elements are considered; returns 0 if equal, -1 if the first date is greater (later), or 1 if the second date is greater.

Parameters:
date1 - first date to compare
date2 - second date to compare
Returns:
0 if equal, -1 if first date > second date, 1 if second date > first date. Returns false if either argument is not a date

create

public static Date create()
Create a new Date object - synonym for new Date(arguments)

Returns:
Date object

getFirstDayOfWeek

public static int getFirstDayOfWeek()
Returns the global attribute that dictates which day should be treated as the first day of the week in calendars and date calculations. The parameter is expected to be an integer value between 0 (Sunday) and 6 (Saturday).

The default value is picked up from the current locale.

Returns:
the number of the day being used as the first day of the week

getFiscalCalendar

public static FiscalCalendar getFiscalCalendar()
Returns the global FiscalCalendar object representing the start month and date of the fiscal year in the current locale.

Returns:
the FiscalCalendar object

getFiscalStartDate

public static Date getFiscalStartDate(Date date)
Returns the start date of the fiscal year for the passed date.

Parameters:
date - the date, or the year-number, to get the fiscal year for
Returns:
the start of the fiscal year for the passed date and fiscalCalendar

getFiscalStartDate

public static Date getFiscalStartDate(Date date,
                                      FiscalCalendar fiscalCalendar)
Returns the start date of the fiscal year for the passed date.

Parameters:
date - the date, or the year-number, to get the fiscal year for
fiscalCalendar - the object representing the starts of one or more fiscal years
Returns:
the start of the fiscal year for the passed date and fiscalCalendar

getFiscalWeek

public static int getFiscalWeek(Date date)
Returns a date's week-number, according to the fiscal calendar

Parameters:
date - the date to get the fiscal year for
Returns:
the fiscal week for the passed date

getFiscalWeek

public static int getFiscalWeek(Date date,
                                FiscalCalendar fiscalCalendar)
Returns a date's week-number, according to the fiscal calendar

Parameters:
date - the date to get the fiscal year for
fiscalCalendar - the object representing the starts of fiscal years
Returns:
the fiscal week for the passed date

getFiscalYear

public static FiscalYear getFiscalYear(Date date)
Returns the FiscalYear object for the fiscal year in which the passed date exists.

Parameters:
date - the date to get the fiscal year for
Returns:
the FiscalYear object for the passed date

getFiscalYear

public static FiscalYear getFiscalYear(Date date,
                                       FiscalCalendar fiscalCalendar)
Returns the FiscalYear object for the fiscal year in which the passed date exists.

Parameters:
date - the date to get the fiscal year for
fiscalCalendar - the object representing the start of the fiscal period
Returns:
the FiscalYear object for the passed date

getInputFormat

public static String getInputFormat()
Retrieves the default format for strings being parsed into dates via Date.parseInput()

Returns:
the current inputFormat for dates
See Also:
com.smartgwt.client.util.Date#setInputFormat

getWeekendDays

public static Integer[] getWeekendDays()
Return an array of days that are considered "weekend" days. Values will be the integers returned by the JavaScript built-in Date.getDay(), eg, 0 is Sunday and 6 is Saturday. Override weekendDays to accommodate different workweeks such as Saudi Arabia (Saturday -> Wednesday) or Israel (Sunday -> Thursday).

Returns:
array of weekend days

parseInput

public static Date parseInput(String dateString)
Parse a date passed in as a string, returning the appropriate date object.

Parameters:
dateString - date value as a string
Returns:
date value, or null if the string could not be parsed to a valid date.

parseInput

public static Date parseInput(String dateString,
                              String format)
See Also:
Date#parseInput()}

parseInput

public static Date parseInput(String dateString,
                              String format,
                              Integer centuryThreshold)
See Also:
Date#parseInput()}

parseInput

public static Date parseInput(String dateString,
                              String format,
                              Integer centuryThreshold,
                              Boolean suppressConversion)
Parse a date passed in as a string, returning the appropriate date object.

Parameters:
dateString - date value as a string
format - Format of the date string being passed. If not passed, the default date input format as set up via setInputFormat() will be used.. See DateInputFormat
centuryThreshold - For date formats that support a 2 digit year, if parsed year is 2 digits and less than this number, assume year to be 20xx rather than 19xx
suppressConversion - If the string passed in was not a valid date, in some cases we can convert to a valid date (for example incrementing the year if the month is greater than 12). This optional parameter will suppress such conversions - anything that doesn't parse directly to a valid date will simply return null.
Returns:
date value, or null if the string could not be parsed to a valid date.

setFirstDayOfWeek

public static void setFirstDayOfWeek(int firstDayOfWeek)
Sets the global attribute that dictates which day should be treated as the first day of the week in calendars and date calculations. The parameter is expected to be an integer value between 0 (Sunday) and 6 (Saturday).

The default value is picked up from the current locale.

Parameters:
firstDayOfWeek - the number of the day to use as the first day of the week

setFiscalCalendar

public static void setFiscalCalendar(FiscalCalendar fiscalCalendar)
Sets the global fiscal calendar, which is used for all calls to getFiscalYear() / getFiscalWeek() if those methods aren't passed a fiscalCalander.

Parameters:
fiscalCalendar - the object representing the start month and date of the fiscal year in the current locale

setInputFormat

public static void setInputFormat(String format)
Sets up the default system-wide input format for strings being parsed into dates via Date.parseInput(). This will effect how Smart GWT components showing editable date or datetime fields parse user-entered values into live Date objects.

The input format can be specified as a DateInputFormat - a 3 character string like "MDY" indicating the order of the Month, Day and Year components of date strings.

As an example - an input format of "MDY" would parse "01/02/1999" to Jan 2nd 1999
This standard parsing logic will also handle date-time strings such as "01/02/1999 08:45", or "01/02/1999 16:21:05".

Notes:

Parameters:
format - Default format for strings to be parsed into Dates.. See DateInputFormat
See Also:
com.smartgwt.client.util.Date#parseInput

setShortDisplayFormat

public static void setShortDisplayFormat(String format)
Set the default short format for dates. After calling this method, subsequent calls to Date.toShortDate will return a string formatted according to this format specification. Note that this will be the standard short date format used by Smart GWT components.

The format parameter may be a FormatString, a DateDisplayFormat string, or a function. If passed a function, this function will be executed in the scope of the Date and should return the formatted string.

Initial default shortDateFormat is "toUSShortDate". This property is commonly modified for localization of applications. See http://en.wikipedia.org/wiki/Date_format_by_country for a useful overview of standard date formats per country.

Parameters:
format - new formatter. See FormatString

setShowChooserFiscalYearPickers

public static void setShowChooserFiscalYearPickers(boolean showChooserFiscalYearPickers)
Sets the global attribute that dictates whether the choosers shelled from DateItems show a UI for working with Fiscal Years.

Parameters:
showChooserFiscalYearPickers - whether to show Fiscal Year pickers in DateChoosers by default

setShowChooserWeekPickers

public static void setShowChooserWeekPickers(boolean showChooserWeekPickers)
Sets the global attribute that dictates whether the choosers shelled from DateItems show a UI for working with Weeks.

Parameters:
showChooserWeekPickers - whether to show Fiscal Week pickers in DateChoosers by default

setWeekendDays

public static void setWeekendDays(Integer[] weekendDays)
Sets the days that are considered weekend days. The parameter should be array of the integers returned by the JavaScript built-in Date.getDay(), eg, 0 is Sunday and 6 is Saturday. Override to accommodate different workweeks such as Saudi Arabia (Saturday -> Wednesday) or Israel (Sunday -> Thursday).

Parameters:
weekendDays - the array of day-numbers to assign as weekend days

setDefaultDisplayTimezone

public static void setDefaultDisplayTimezone(String offset)
Globally sets the offset from UTC to use when formatting values of type datetime and time with standard display formatters. This property effects how dates are displayed and also the assumed timezone for user-input.

If this method is never called, the default display timezone for times and datetimes will be derived from the native browser local timezone.

Note that by default daylight savings time adjustments (based on browser locale) may also be applied when formatting datetimes. setAdjustForDST(boolean) may be used to disable this adjustment.

Parameters:
offset - offset from UTC. This should be a string in the format +/-HH:MM for example "-08:00"

setAdjustForDST

public static void setAdjustForDST(boolean adjustForDST)
Determines whether, when formatting values of type datetime and time, the effect of Daylight Saving Time should be considered when computing offsets from UTC. By default, this flag is set during framework initialization if SmartGWT detects that it is running in a locale that is observing DST this year. If you do not want DST adjustments to be applied, set this flag to false.

Note that setting this flag to true will have no effect unless you are in a locale that is observing Daylight Saving Time this year; this is because we rely on the browser for offset information, and browsers are only capable of returning local date and time information for the computer's current locale.

Parameters:
whether - time and datetimes should account for daylight savings time in this application

setDefaultDateSeparator

public static void setDefaultDateSeparator(String separator)
Sets a new default separator that will be used when formatting dates. By default, this is a forward slash character: "/"

Parameters:
separator - the date separator

getDefaultDateSeparator

public static String getDefaultDateSeparator()
Returns the default date separator.

Returns:
the default date separator

setNormalDateDisplayFormat

@Deprecated
public static void setNormalDateDisplayFormat(DateDisplayFormat format)
Deprecated. This method is deprecated in favor of setNormalDateDisplayFormatter(DateDisplayFormatter).

Set the default format for date objects to the DateDisplayFormat passed in. After calling this method, subsequent calls to Date.toNormalDate will return a string formatted according to this format specification.
Note: this will be the standard long date format used by SmartGWT components. Initial default normalDisplayFormat is "toLocaleString"

Parameters:
format - the DateDisplayFormat

setNormalDatetimeDisplayFormatter

public static void setNormalDatetimeDisplayFormatter(DateDisplayFormatter formatter)
Set the default datetime format for date objects to the DateDisplayFormat passed in. After calling this method, subsequent calls to Date.toNormalDate will return a string formatted according to this format specification.
Note: this will be the standard long datetime format used by SmartGWT components. Initial default normalDatetimeDisplayFormat is "toLocaleString"

Parameters:
format - the DateDisplayFormatter

setNormalDateDisplayFormatter

public static void setNormalDateDisplayFormatter(DateDisplayFormatter formatter)
Set the default formatter for date objects to the custom DateDisplayFormatter passed in. After calling this method, subsequent calls to Date.toNormalDate will return a string formatted according to this formatter specification.

When writing custom date formatting and parsing logic, developers may find the DateTimeFormat class helpful. SmartGWT includes several built-in DateDisplayFormatters for common formats - see DateDisplayFormatter for details. Sample code :

 DateUtil.setNormalDateDisplayFormatter(new DateDisplayFormatter() {
     public String format(Date date) {
         if(date == null) return null;
         final DateTimeFormat dateFormatter = DateTimeFormat.getFormat("yyyy.MM.dd HH:mm:ss");
         String format = dateFormatter.format(date);
         return format;
     }
 });
 
As of version 4.1, SmartGWT has built-in string-based formatting of date and time values via the DateFormatStringFormatter class. The main advantage of using the built-in formatting feature is that it is harmonized with the formatting we export to Excel and other targets, leading to an exported document that more closely resembles the original application. See com.smartgwt.client.data.DataSOurceField#format for details. Sample code :
 DateUtil.setNormalDateDisplayFormatter(new DateFormatStringFormatter("yyyy.MM.dd HH:mm:ss"));
 

Parameters:
formatter - the DateDisplayFormatter

setShortDateDisplayFormat

@Deprecated
public static void setShortDateDisplayFormat(DateDisplayFormat format)
Deprecated. This method is deprecated in favor of setShortDateDisplayFormatter(DateDisplayFormatter).

Set the system wide default short date format. The specified format will be used by default by SmartGwt components when formatting date values to short date format (and by formatAsShortDate(Date)).

This method, together with setDefaultDateSeparator(String) provide support for most standard "short date" formats. However if a custom format which doesn't match any of the specified DateDisplayFormat types is required, a custom formatting function may be provided via setShortDateDisplayFormatter(DateDisplayFormatter).

Note that the default short date format is initially set to DateDisplayFormat.TOUSSHORTDATE. This property is commonly modified for localization of applications. See Date format by country for a useful overview of standard date formats per country.

Parameters:
format - the DateDisplayFormat

setShortDateDisplayFormatter

public static void setShortDateDisplayFormatter(DateDisplayFormatter formatter)
Set up a system wide default short date formatting function. The formatter passed in will be used by default by SmartGwt components when formatting date values to short date format (and by formatAsShortDate(Date)).

If a custom short date formatter is applied, bear in mind that it will be applied by default when editing date values, so the system will need to be able to parse an edited date string in this format back to a live date object. Developers calling this method will therefore also commonly want to apply custom parsing logic via setDateInputFormat(String) or setDateParser(DateParser).

When writing custom date formatting and parsing logic, developers may find the DateTimeFormat class helpful. SmartGWT includes several built-in DateDisplayFormatters for common formats - see DateDisplayFormatter for details. Sample code :

 DateUtil.setShortDateDisplayFormatter(new DateDisplayFormatter() {
     public String format(Date date) {
         if(date == null) return null;
         final DateTimeFormat dateFormatter = DateTimeFormat.getFormat("MMM d, yyyy");
         String format = dateFormatter.format(date);
         return format;
     }
 });
 

Parameters:
formatter - the DateDisplayFormatter

setShortDatetimeDisplayFormat

@Deprecated
public static void setShortDatetimeDisplayFormat(DateDisplayFormat format)
Deprecated. This method is deprecated in favor of setShortDatetimeDisplayFormatter(DateDisplayFormatter).

Set the system wide default short datetime format. The specified format will be used by default by SmartGwt components when formatting datetime field values to short datetime format (and by formatAsShortDatetime(Date)).

This method, together with setDefaultDateSeparator(String) provide support for most standard "short date" formats. However if a custom format which doesn't match any of the specified DateDisplayFormat types is required, a custom formatting function may be provided via setShortDatetimeDisplayFormatter(DateDisplayFormatter).

Note that the default short datetime format is initially set to DateDisplayFormat.TOUSSHORTDATETIME. This property is commonly modified for localization of applications. See Date format by country for a useful overview of standard date formats per country.

Parameters:
format - the DateDisplayFormat

setShortDatetimeDisplayFormatter

public static void setShortDatetimeDisplayFormatter(DateDisplayFormatter formatter)
Set up a system wide default short datetime formatting function. The formatter passed in will be used by default by SmartGwt components when formatting date values to short datetime format (and by formatAsShortDatetime(Date)).

If a custom short datetime formatter is applied, bear in mind that it will be applied by default when editing date values, so the system will need to be able to parse an edited date string in this format back to a live date object. Developers calling this method will therefore also commonly want to apply custom parsing logic via setDateInputFormat(String) or setDateParser(DateParser).

When writing custom date formatting and parsing logic, developers may find the DateTimeFormat class helpful. SmartGWT includes several built-in DateDisplayFormatters for common formats - see DateDisplayFormatter for details.

Parameters:
formatter - the DateDisplayFormatter

createLogicalDate

public static LogicalDate createLogicalDate(int year,
                                            int month,
                                            int date)
Create a new Date to represent a logical date value (rather than a specific datetime value), typically for display in a +link{DataSourceField.type,date type field}. The generated Date value will have year, month and date set to the specified values (in browser native local time).

See the docs for a discussion of the difference between datetime field values and logical date field values, logical time field values.

Parameters:
year -
month -
date -
Returns:
LogicalDate representing a logical date.

createLogicalTime

public static LogicalTime createLogicalTime(int hour,
                                            int minute,
                                            int second,
                                            int millisecond)
Create a new Date object to represent a logical time value (rather than a specific datetime value), typically for display in a +link{DataSourceField.type,time type field}. The generated Date value will have year, month and date set to the epoch date (Jan 1 1970), and time elements set to the supplied hour, minute and second (in browser native local time).

See the docs for a discussion of the difference between datetime field values and logical date field values, logical time field values.

Parameters:
hour - (0-23)
minute - (0-59)
second - (0-59)
millisecond - (0-999)
Returns:
new LogicalTime representing the time in question

getLogicalDateOnly

public static LogicalDate getLogicalDateOnly(Date date)
Get a logical date - a value appropriate for a DataSourceField of type "date" - from a datetime value (a value from a DataSourceField of type "datetime").

This method correctly takes into account the current String, specifically, the returned Date will reflect the day, month and year that appears when the datetime is rendered by a Smart GWT component rather than the date values that would be returned by Date.getDay() et al (which can differ, since getDay() uses the browser's local timezone).

For further background on date, time and datetime types, storage and transmission, see this overview.

Parameters:
date - a Date instance representing a datetime value
Returns:
a Date instance representing just the date portion of the datetime value, as a logical date

getLogicalTimeOnly

public static LogicalTime getLogicalTimeOnly(Date date)
Get a logical time - a value appropriate for a DataSourceField of type "time" - from a datetime value (a value from a DataSourceField of type "datetime").

This method correctly takes into account the current String, specifically, the returned Date will reflect the hour, minute and second that appears when the datetime is rendered by a Smart GWT component rather than the time values that would be returned by Date.getHours() et al (which can differ, since getHours() uses the browser's local timezone).

For further background on date, time and datetime types, storage and transmission, see this overview.

Parameters:
date - a Date instance representing a datetime value
Returns:
a Date instance representing just the time portion of the datetime value, as a logical time

formatAsShortDate

public static String formatAsShortDate(Date date)
Format a date as a string according to the format specified by setShortDateDisplayFormatter(DateDisplayFormatter).

This calls the standard date formatting function used by SmartGWT components to display short-formatted dates.

Parameters:
date -
Returns:

formatAsShortDatetime

public static String formatAsShortDatetime(Date date)
Format a date as a string according to the format specified by setShortDatetimeDisplayFormatter(DateDisplayFormatter).

This calls the standard date formatting function used by SmartGWT components to display short-formatted date-times.

Parameters:
date -
Returns:

format

public static String format(Date date)
Format a date as a string according to the format specified by setNormalDateDisplayFormatter(DateDisplayFormatter).

This calls the standard date formatting function used by SmartGWT components to display short-formatted dates.

Parameters:
date -
Returns:

formatAsNormalDate

public static String formatAsNormalDate(Date date)
Format a date as a string according to the format specified by setNormalDateDisplayFormatter(DateDisplayFormatter).

This calls the standard date formatting function used by SmartGWT components to display normal-formatted dates.

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

setDateInputFormatter

public static void setDateInputFormatter(DateInputFormatter formatter)
Deprecated. in favor of setDateParser()

Sets up the default format for strings being parsed into dates via DateUtil.parseInput
Sample code :
 DateUtil.setDateInputFormatter(new DateInputFormatter() {
    public Date format(String dateString) {
       final DateTimeFormat dateFormatter = DateTimeFormat.getFormat("MMM d, yyyy");
       Date date = dateFormatter.parse(dateString);
       return date;
    }
 });
 

Parameters:
formatter - the DateInputFormatter

setDateParser

public static void setDateParser(DateParser parser)
Sets up a custom parsing function to use by default when converting dates or datetimes from formatted string values to Dates. This custom parser will be used by SmartGwt components parsing editable date or datetime type values back to live dates by default. The string passed in will be formatted according to the standard "short date" or "short datetime" format (which may be customized via setShortDateDisplayFormat(DateDisplayFormat) or setShortDateDisplayFormatter(DateDisplayFormatter) and setShortDatetimeDisplayFormat(DateDisplayFormat) or setShortDatetimeDisplayFormatter(DateDisplayFormatter) methods.

Note that the default date parsing logic already handles all standard short date formats, including those formatted with custom separators. In most cases rather than applying an entirely custom date parser method, desired behavior can be achieved via changing the standard input format.

When writing custom date formatting and parsing logic, developers may find the DateTimeFormat class helpful.

Sample code :

 DateUtil.setDateParser(new DateParser() {
    public Date parse(String dateString) {
       final DateTimeFormat format = DateTimeFormat.getFormat("MMM d, yyyy");
       Date date = format.parse(dateString);
       return date;
    }
 });
 

Individual components may also override date formatting and parsing functions directly.

Parameters:
parser -

setDateInputFormat

public static void setDateInputFormat(String inputFormat)
Sets up the default system-wide input format for strings being parsed into dates via SmartGWT utilities and components (see parseInput(String)). This input format is respected when parsing formatted strings to "date" or "datetime" type values.

This method takes a 3 character string like "MDY" indicating the order of the Month, Day and Year components of date strings.

As an example - an input format of "MDY" would parse "01/02/1999" to Jan 2nd 1999
This standard parsing logic will also handle date-time strings such as "01/02/1999 08:45", or "01/02/1999 16:21:05".

Notes:

Parameters:
inputFormat -

mapRelativeDateShortcut

public static String mapRelativeDateShortcut(String relativeDateShortcut,
                                             RelativeDateRangePosition position)
Converts a RelativeDate shortcut string such as "$today" to a RelativeDateString such as "+0D"

Parameters:
relativeDateShortcut - shortcut string to convert
position - Are we interested in the start or end of the specified relative date? This applies to shortcuts which do not specify a specific moment (such as $today) - it does not apply to shortcuts which already specify a specific moment such as $startOfToday. If unspecified rangePosition is always assumed to be "start"
Returns:
converted relative date string

mapRelativeDateShortcut

public static String mapRelativeDateShortcut(String relativeDateShortcut)

getAbsoluteDate

public static Date getAbsoluteDate(RelativeDate relativeDate)
Converts a RelativeDate to a concrete Date.

Returns:

getAbsoluteDate

public static Date getAbsoluteDate(RelativeDate relativeDate,
                                   Date baseDate,
                                   RelativeDateRangePosition position)
Converts a RelativeDate to a concrete Date.

Returns:

setNormalTimeDisplayFormatter

public static void setNormalTimeDisplayFormatter(DateDisplayFormatter formatter)
Set up a system wide default normal time formatting function. After calling this method, subsequent calls to isc.Time.toTime() will return a string formatted according to this formatter specification. Note: this will be the standard time format used by SmartGWT components. The initial default normal time display formatter is DateUtil.TOTIME.

SmartGWT includes several built-in DateDisplayFormatters for common formats - see DateDisplayFormatter for details.

As of version 4.1, SmartGWT has built-in string-based formatting of date and time values via the DateFormatStringFormatter class. The main advantage of using the built-in formatting feature is that it is harmonized with the formatting we export to Excel and other targets, leading to an exported document that more closely resembles the original application. See com.smartgwt.client.data.DataSourceField#format for details. Sample code :

 DateUtil.setNormalTimeDisplayFormatter(new DateFormatStringFormatter("HH-mm-ss"));
 

Parameters:
formatter - the DateDisplayFormatter

setShortTimeDisplayFormatter

public static void setShortTimeDisplayFormatter(DateDisplayFormatter formatter)
Set up a system wide default short time formatting function. After calling this method, subsequent calls to isc.Time.toShortTime() will return a string formatted according to this formatter specification. Note: this will be the standard time format used by SmartGWT components. The initial default normal time display formatter is DateUtil.TOSHORTTIME.

SmartGWT includes several built-in DateDisplayFormatters for common formats - see DateDisplayFormatter for details.

Parameters:
formatter - the DateDisplayFormatter

combineLogicalDateAndTime

public static Date combineLogicalDateAndTime(Date date,
                                             Date time)
Combine a logical date (a value appropriate for a DataSourceField of type "date") with a logical time (a value appropriate for a DataSourceField of type "time") into a datetime value (a value appropriate for a DataSourceField of type "datetime")

This method correctly takes into account the current display timezone (see #setDefaultDisplayTimezone()), specifically, the returned datetime value will show the same date and time as the passed date and time objects when rendered by a SmartGWT component that has been configured with a field of type "datetime".

For further background on date, time and datetime types, storage this overview.

Parameters:
date -
time -
Returns:

format

public static String format(Date date,
                            String format)
Format the parameter date using the parameter format string. This is a convenience method; it simply creates a DateFormatStringFormatter and calls its format() method

Parameters:
date - the Date to format
format - the format string to use
Returns:
the parameter date formatted according to the parameter format string

setMonthNames

public static void setMonthNames(String[] monthNames)
Set the array of names of months. For example:
 new String[] {
     "January", "February", "March", "April", "May", "June", "July",
     "August", "September", "October", "November", "December" }
 
The appropriate month name will then be returned from getMonthName(), and may be used whenever SmartGWT components display month-names (for example in the DateItem class).

Note : This is an advanced setting

Parameters:
monthNames - a length 12 array of month names

setShortMonthNames

public static void setShortMonthNames(String[] shortMonthNames)
Set the array of names of months. For example:
 new String[] {
     "Jan", "Feb", "Mar", "Apr", "May", "Jun",
     "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }
 
The appropriate month name will then be returned from #getShortMonthName(), and may be used whenever SmartGWT components display month-names (for example in the DateItem class).

Note : This is an advanced setting

Parameters:
shortMonthNames - a length 12 array of abbreviated month names

getFiscalStartDate

public static Date getFiscalStartDate(Integer year,
                                      FiscalCalendar fiscalCalendar)
Get the start date of the fiscal period for the passed year.

Returns:

autoDetectFormats

public static void autoDetectFormats()
Use the GWT LocaleInfo class to auto-detect the various formats for dates and times.