Clear Up
SharpKit Reference

DateExtras Class

Namespace: Ext

Base Types

System.Object

Constructors

Name Description
DateExtras()

Methods

Name Description
add(JsDate, JsString, JsNumber) Provides a convenient method for performing basic date arithmetic. This method does not modify the Date instance being called - it creates and returns a new Date instance containing the resulting date value. * Examples:
  
// Basic usage:
var dt = Ext.Date.add(new Date('10/29/2006'), Ext.Date.DAY, 5);
console.log(dt); //returns 'Fri Nov 03 2006 00:00:00'
// Negative values will be subtracted:
var dt2 = Ext.Date.add(new Date('10/1/2006'), Ext.Date.DAY, -5);
console.log(dt2); //returns 'Tue Sep 26 2006 00:00:00'
            
* @param {Date} date The date to modify @param {String} interval A valid date interval enum value. @param {Number} value The amount to add to the current date. @return {Date} The new Date instance.
between(JsDate, JsDate, JsDate) Checks if a date falls on or between the given start and end dates. @param {Date} date The date to check @param {Date} start Start date @param {Date} end End date @return {Boolean} true if this date falls on or between the given start and end dates.
clearTime(JsDate, bool) Attempts to clear all time information from this Date by setting the time to midnight of the same day, automatically adjusting for Daylight Saving Time (DST) where applicable. (note: DST timezone information for the browser's host operating system is assumed to be up-to-date) @param {Date} date The date @param {Boolean} clone true to create a clone of this date, clear the time and return it (defaults to false). @return {Date} this or the clone.
clone(JsDate) Creates and returns a new Date instance with the exact same date value as the called instance. Dates are copied and passed by reference, so if a copied date variable is modified later, the original variable will also be changed. When the intention is to create a new variable that will not modify the original instance, you should create a clone. * Example of correctly cloning a date:
  
//wrong way:
var orig = new Date('10/1/2006');
var copy = orig;
copy.setDate(5);
console.log(orig);  //returns 'Thu Oct 05 2006'!
//correct way:
var orig = new Date('10/1/2006'),
copy = Ext.Date.clone(orig);
copy.setDate(5);
console.log(orig);  //returns 'Thu Oct 01 2006'
            
@param {Date} date The date @return {Date} The new Date instance.
createFormat(object)
dateFormat(object, object)
format(JsDate, JsString) Formats a date given the supplied format string. @param {Date} date The date to format @param {String} format The format string @return {String} The formatted date
formatCodeToRegex(object, object)
getDayOfYear(JsDate) Get the numeric day number of the year, adjusted for leap year. @param {Date} date The date @return {Number} 0 to 364 (365 in leap years).
getElapsed(JsDate, JsDate) Returns the number of milliseconds between two dates @param {Date} dateA The first date @param {Date} dateB (optional) The second date, defaults to now @return {Number} The difference in milliseconds
getFirstDateOfMonth(JsDate) Get the date of the first day of the month in which this date resides. @param {Date} date The date @return {Date}
getFirstDayOfMonth(JsDate) Get the first day of the current month, adjusted for leap year. The returned value is the numeric day index within the week (0-6) which can be used in conjunction with the {@link #monthNames} array to retrieve the textual day name. Example:
  
var dt = new Date('1/10/2007'),
firstDay = Ext.Date.getFirstDayOfMonth(dt);
console.log(Ext.Date.dayNames[firstDay]); //output: 'Monday'
            
@param {Date} date The date @return {Number} The day number (0-6).
getFormatCode(object)
getGMTOffset(JsDate, bool) Get the offset from GMT of the current date (equivalent to the format specifier 'O'). @param {Date} date The date @param {Boolean} colon (optional) true to separate the hours and minutes with a colon (defaults to false). @return {String} The 4-character offset string prefixed with + or - (e.g. '-0600').
getLastDateOfMonth(JsDate) Get the date of the last day of the month in which this date resides. @param {Date} date The date @return {Date}
getLastDayOfMonth(JsDate) Get the last day of the current month, adjusted for leap year. The returned value is the numeric day index within the week (0-6) which can be used in conjunction with the {@link #monthNames} array to retrieve the textual day name. Example:
  
var dt = new Date('1/10/2007'),
lastDay = Ext.Date.getLastDayOfMonth(dt);
console.log(Ext.Date.dayNames[lastDay]); //output: 'Wednesday'
            
@param {Date} date The date @return {Number} The day number (0-6).
getMonthNumber(JsString) Get the zero-based javascript month number for the given short/full month name. Override this function for international dates. @param {String} name The short/full month name. @return {Number} The zero-based javascript month number.
getShortDayName(JsNumber) Get the short day name for the given day number. Override this function for international dates. @param {Number} day A zero-based javascript day number. @return {String} The short day name.
getShortMonthName(JsNumber) Get the short month name for the given month number. Override this function for international dates. @param {Number} month A zero-based javascript month number. @return {String} The short month name.
getSuffix(JsDate) Get the English ordinal suffix of the current day (equivalent to the format specifier 'S'). @param {Date} date The date @return {String} 'st, 'nd', 'rd' or 'th'.
getTimezone(JsDate) Get the timezone abbreviation of the current date (equivalent to the format specifier 'T'). * Note: The date string returned by the javascript Date object's toString() method varies between browsers (e.g. FF vs IE) and system region settings (e.g. IE in Asia vs IE in America). For a given date string e.g. "Thu Oct 25 2007 22:55:35 GMT+0800 (Malay Peninsula Standard Time)", getTimezone() first tries to get the timezone abbreviation from between a pair of parentheses (which may or may not be present), failing which it proceeds to get the timezone abbreviation from the GMT offset portion of the date string. @param {Date} date The date @return {String} The abbreviated timezone name (e.g. 'CST', 'PDT', 'EDT', 'MPST' ...).
isDST(JsDate) Checks if the current date is affected by Daylight Saving Time (DST). @param {Date} date The date @return {Boolean} True if the current date is affected by DST.
isLeapYear(JsDate) Checks if the current date falls within a leap year. @param {Date} date The date @return {Boolean} True if the current date falls within a leap year, false otherwise.
isValid(JsNumber, JsNumber, JsNumber, JsNumber, JsNumber, JsNumber, JsNumber) Checks if the passed Date parameters will cause a javascript Date "rollover". @param {Number} year 4-digit year @param {Number} month 1-based month-of-year @param {Number} day Day of month @param {Number} hour (optional) Hour @param {Number} minute (optional) Minute @param {Number} second (optional) Second @param {Number} millisecond (optional) Millisecond @return {Boolean} true if the passed parameters do not cause a Date "rollover", false otherwise.
parse(JsString, JsString, bool) Parses the passed string using the specified date format. Note that this function expects normal calendar dates, meaning that months are 1-based (i.e. 1 = January). The {@link #defaults} hash will be used for any date value (i.e. year, month, day, hour, minute, second or millisecond) which cannot be found in the passed string. If a corresponding default date value has not been specified in the {@link #defaults} hash, the current date's year, month, day or DST-adjusted zero-hour time value will be used instead. Keep in mind that the input date string must precisely match the specified format string in order for the parse operation to be successful (failed parse operations return a null value).

Example:

  
//dt = Fri May 25 2007 (current date)
var dt = new Date();
//dt = Thu May 25 2006 (today's month/day in 2006)
dt = Ext.Date.parse("2006", "Y");
//dt = Sun Jan 15 2006 (all date parts specified)
dt = Ext.Date.parse("2006-01-15", "Y-m-d");
//dt = Sun Jan 15 2006 15:20:01
dt = Ext.Date.parse("2006-01-15 3:20:01 PM", "Y-m-d g:i:s A");
// attempt to parse Sun Feb 29 2006 03:20:01 in strict mode
dt = Ext.Date.parse("2006-02-29 03:20:01", "Y-m-d H:i:s", true); // returns null
            
@param {String} input The raw date string. @param {String} format The expected date string format. @param {Boolean} strict (optional) True to validate date strings while parsing (i.e. prevents javascript Date "rollover") (defaults to false). Invalid date strings will return null when parsed. @return {Date} The parsed Date.
parseDate(object, object, object)

Properties

Name Description
DAY Date interval constant @type String
defaultFormat

The date format string that the {@link Ext.util.Format#date} function uses. See {@link Ext.Date} for details.

This defaults to

m/d/Y
, but may be overridden in a locale file.

@property defaultFormat @type String
HOUR @type String
MILLI Date interval constant @type String
MINUTE Date interval constant @type String
MONTH Date interval constant @type String
SECOND Date interval constant @type String
useStrict Global flag which determines if strict date parsing should be used. Strict date parsing will not roll-over invalid dates, which is the default behaviour of javascript Date objects. (see {@link #parse} for more information) Defaults to false. @type Boolean
y2kYear
YEAR Date interval constant @type String
© Copyright 2005-2011 SharpKit. All rights reserved.