com.smartgwt.client.util
Class DateUtil

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

public class DateUtil
extends Object

Date related utility methods.


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 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 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 setNormalDateDisplayFormat(DateDisplayFormat) or setNormalDateDisplayFormatter(DateDisplayFormatter).
static String formatAsNormalDate(Date date)
          Format a date as a string according to the format specified by setNormalDateDisplayFormat(DateDisplayFormat) or setNormalDateDisplayFormatter(DateDisplayFormatter).
static String formatAsShortDate(Date date)
          Format a date as a string according to the format specified by setShortDateDisplayFormat(DateDisplayFormat) or setShortDateDisplayFormatter(DateDisplayFormatter).
static String formatAsShortDatetime(Date date)
          Format a date as a string according to the format specified by setShortDatetimeDisplayFormat(DateDisplayFormat) or 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.
static String getDefaultDateSeparator()
          Returns the default date separator.
static FiscalCalendar getFiscalCalendar()
          Get the system wide com.cmartget.client.widgets.FiscalCalendar.
static Date getFiscalStartDate(Date date, FiscalCalendar fiscalCalendar)
          Get the start date of the fiscal period in which the passed date exists.
static Date getFiscalStartDate(Integer year, FiscalCalendar fiscalCalendar)
          Get the start date of the fiscal period for the passed year.
static Integer getFiscalWeek(Date date, FiscalCalendar fiscalCalendar)
          Get the fiscal week in the period in which the passed date exists.
static FiscalYear getFiscalYear(Date date, FiscalCalendar fiscalCalendar)
          Get the fiscal year object in which the passed date exists.
static FiscalYear getFiscalYear(Integer year, FiscalCalendar fiscalCalendar)
          Get the fiscal year object for the passed year.
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").
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 formatted date string into a 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 setFiscalCalendar(FiscalCalendar fiscalCalendar)
          Set the system wide com.cmartget.client.widgets.FiscalCalendar for use when working with Dates.
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 setShortTimeDisplayFormatter(DateDisplayFormatter formatter)
          Set up a system wide default short time formatting function.
static void setShowChooserFiscalYearPickers(boolean showFiscalYearPickers)
          Should the Fiscal Year picker be displayed by default in all DateChoosers?
static void setShowChooserWeekPickers(boolean showWeekPickers)
          Should the Week picker be displayed by default in all DateChoosers?
 
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

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;
     }
 });
 

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 http://en.wikipedia.org/wiki/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 http://en.wikipedia.org/wiki/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

parseInput

public static Date parseInput(String dateString)
Parse a formatted date string into a Date object.

This calls the default parsing function used by SmartGWT components.

If setDateInputFormat(String) or setDateParser(DateParser) has been specified it will be respected.

Parameters:
dateString - string to parse into a Date
Returns:
date value from the string (or null if the string passed in could not be converted to a date).

formatAsShortDate

public static String formatAsShortDate(Date date)
Format a date as a string according to the format specified by setShortDateDisplayFormat(DateDisplayFormat) or 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 setShortDatetimeDisplayFormat(DateDisplayFormat) or 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 setNormalDateDisplayFormat(DateDisplayFormat) or 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 setNormalDateDisplayFormat(DateDisplayFormat) or 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 #setDateInputFormat(String),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:

  • If this method is never called, the system attempts to automatically determine the standard input format will be automatically determined based on the specified #setShortDateDisplayFormat(DateDisplayFormat),short date display format. For example if the short display format has been set to "toEuropeanShortDate" the input format will default to "DMY".
  • The default date parsing functionality built into SmartGWT will handle dates presented with any separator string, and can 1 or 2 digit day and month values and 2 or 4 digit year values. This means that in many cases custom date display formats can be parsed back to Date values without the need for explicit custom formatter functions. However if more sophisticated parsing logic is required an entirely custom parser function may be applied via setDateParser().
  • Date parsing and formatting logic may be overridden at the component level by setting properties directly on the component or field in question.

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.

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

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 display timezone (see setDefaultDisplayTimezone()),, specifically, the returned Date will reflect the day, month and year that appears when the datetime is rendered by a SmartGWT 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 com.smartgwt.client.docs.DateFormatAndStorage, this overview.


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 display timezone (see setDefaultDisplayTimezone()), specifically, the returned Date will reflect the hour, minute and second that appears when the datetime is rendered by a SmartGWT 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 the com.smartgwt.client.docs.DateFormatAndStorage, this overview.


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 com.smartgwt.client.docs.DateFormatAndStorage, this overview.

Parameters:
date -
time -
Returns:

setFiscalCalendar

public static void setFiscalCalendar(FiscalCalendar fiscalCalendar)
Set the system wide com.cmartget.client.widgets.FiscalCalendar for use when working with Dates.

Parameters:
fiscalCalendar - the FiscalCalendar

getFiscalCalendar

public static FiscalCalendar getFiscalCalendar()
Get the system wide com.cmartget.client.widgets.FiscalCalendar.

Returns:

getFiscalStartDate

public static Date getFiscalStartDate(Date date,
                                      FiscalCalendar fiscalCalendar)
Get the start date of the fiscal period in which the passed date exists.

Returns:

getFiscalStartDate

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

Returns:

getFiscalYear

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

Returns:

getFiscalYear

public static FiscalYear getFiscalYear(Integer year,
                                       FiscalCalendar fiscalCalendar)
Get the fiscal year object for the passed year.

Returns:

getFiscalWeek

public static Integer getFiscalWeek(Date date,
                                    FiscalCalendar fiscalCalendar)
Get the fiscal week in the period in which the passed date exists.

Returns:

setShowChooserFiscalYearPickers

public static void setShowChooserFiscalYearPickers(boolean showFiscalYearPickers)
Should the Fiscal Year picker be displayed by default in all DateChoosers?


setShowChooserWeekPickers

public static void setShowChooserWeekPickers(boolean showWeekPickers)
Should the Week picker be displayed by default in all DateChoosers?