Ext.DateExtras

Mixed into

Files

Extra methods to be mixed into Ext.Date.

Require this class to get Ext.Date with all the methods listed below.

Using Ext.setup:

Ext.setup({
    requires: 'Ext.DateExtras',
    onReady: function() {
        var date = new Date();
        alert(Ext.Date.format(date, 'n/j/Y'));
    }
});

Using Ext.application:

Ext.application({
    requires: 'Ext.DateExtras',
    launch: function() {
        var date = new Date();
        alert(Ext.Date.format(date, 'n/j/Y'));
    }
});
Defined By

Properties

Ext.DateExtras
view source
: Stringreadonly
Date interval constant. ...

Date interval constant.

Defaults to: "d"

Ext.DateExtras
view source
: Stringreadonly
Date interval constant. ...

Date interval constant.

Defaults to: "h"

Ext.DateExtras
view source
: Stringreadonly
Date interval constant. ...

Date interval constant.

Defaults to: "ms"

Ext.DateExtras
view source
: Stringreadonly
Date interval constant. ...

Date interval constant.

Defaults to: "mi"

Ext.DateExtras
view source
: Stringreadonly
Date interval constant. ...

Date interval constant.

Defaults to: "mo"

Ext.DateExtras
view source
: Stringreadonly
Date interval constant. ...

Date interval constant.

Defaults to: "s"

Ext.DateExtras
view source
: Stringreadonly
Date interval constant. ...

Date interval constant.

Defaults to: "y"

Ext.DateExtras
view source
: Objectprivate
Ext.DateExtras
view source
: Array
An array of textual day names. ...

An array of textual day names. Override these values for international dates. Example:

Ext.Date.dayNames = [
    'SundayInYourLang',
    'MondayInYourLang'
    // ...
];

Defaults to: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]

The date format string that the Ext.util.Format.date function uses. ...

The date format string that the Ext.util.Format.date function uses. See Ext.Date for details.

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

Defaults to: "m/d/Y"

Ext.DateExtras
view source
: Object
An object hash containing default date values used during date parsing. ...

An object hash containing default date values used during date parsing.

The following properties are available:

  • y: Number - The default year value. Defaults to undefined.
  • m: Number - The default 1-based month value. Defaults to undefined.
  • d: Number - The default day value. Defaults to undefined.
  • h: Number - The default hour value. Defaults to undefined.
  • i: Number - The default minute value. Defaults to undefined.
  • s: Number - The default second value. Defaults to undefined.
  • ms: Number - The default millisecond value. Defaults to undefined.

Override these properties to customize the default date values used by the parse method.

Note: In countries which experience Daylight Saving Time (i.e. DST), the h, i, s and ms properties may coincide with the exact time in which DST takes effect. It is the responsibility of the developer to account for this.

Example Usage:

// set default day value to the first day of the month
Ext.Date.defaults.d = 1;

// parse a February date string containing only year and month values.
// setting the default day value to 1 prevents weird date rollover issues.
// when attempting to parse the following date string on, for example, March 31st 2009.
alert(Ext.Date.parse('2009-02', 'Y-m')); // returns a Date object representing February 1st 2009.

Defaults to: {}

The base format-code to formatting-function hashmap used by the format method. ...

The base format-code to formatting-function hashmap used by the format method. Formatting functions are strings (or functions which return strings) which will return the appropriate value when evaluated in the context of the Date object from which the format method is called. Add to / override these mappings for custom date formatting.

Note: Ext.Date.format() treats characters as literals if an appropriate mapping cannot be found.

Example:

Ext.Date.formatCodes.x = "Ext.util.Format.leftPad(this.getDate(), 2, '0')";
alert(Ext.Date.format(new Date(), 'x')); // returns the current day of the month
An object hash in which each property is a date formatting function. ...

An object hash in which each property is a date formatting function. The property name is the format string which corresponds to the produced formatted date string.

This object is automatically populated with date formatting functions as date formats are requested for Ext standard formatting strings.

Custom formatting functions may be inserted into this object, keyed by a name which from then on may be used as a format string to format.

Example:

Ext.Date.formatFunctions['x-date-format'] = myDateFormatter;

A formatting function should return a string representation of the Date object which is the scope (this) of the function.

To enable date strings to also be parsed according to that format, a corresponding parsing function must be placed into the parseFunctions property.

An array of textual month names. ...

An array of textual month names. Override these values for international dates. Example:

Ext.Date.monthNames = [
    'JanInYourLang',
    'FebInYourLang'
    // ...
];

Defaults to: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]

An object hash of zero-based JavaScript month numbers (with short month names as keys). ...

An object hash of zero-based JavaScript month numbers (with short month names as keys).

Note: keys are case-sensitive.

Override these values for international dates. Example:

Ext.Date.monthNumbers = {
    'ShortJanNameInYourLang': 0,
    'ShortFebNameInYourLang': 1
    // ...
};

Defaults to: {Jan: 0, Feb: 1, Mar: 2, Apr: 3, May: 4, Jun: 5, Jul: 6, Aug: 7, Sep: 8, Oct: 9, Nov: 10, Dec: 11}

Ext.DateExtras
view source
: Objectprivate
An object hash in which each property is a date parsing function. ...

An object hash in which each property is a date parsing function. The property name is the format string which that function parses.

This object is automatically populated with date parsing functions as date formats are requested for Ext standard formatting strings.

Custom parsing functions may be inserted into this object, keyed by a name which from then on may be used as a format string to parse.

Example:

Ext.Date.parseFunctions['x-date-format'] = myDateParser;

A parsing function should return a Date object, and is passed the following parameters:

  • date: String - The date string to parse.
  • strict: Boolean - true to validate date strings while parsing (i.e. prevent JavaScript Date "rollover"). The default must be false. Invalid date strings should return null when parsed.

To enable Dates to also be formatted according to that format, a corresponding formatting function must be placed into the formatFunctions property.

Ext.DateExtras
view source
: Arrayprivate
...

Defaults to: []

Global flag which determines if strict date parsing should be used. ...

Global flag which determines if strict date parsing should be used. Strict date parsing will not roll-over invalid dates, which is the default behavior of JavaScript Date objects. (see parse for more information)

Defaults to: false

Ext.DateExtras
view source
: Numberprivate
...

Defaults to: 50

Defined By

Methods

Ext.DateExtras
view source
( date, interval, value ) : Date
Provides a convenient method for performing basic date arithmetic. ...

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.

// Basic usage:
var dt = Ext.Date.add(new Date('10/29/2006'), Ext.Date.DAY, 5);
alert(dt); // 'Fri Nov 03 2006 00:00:00'

You can also subtract date values by passing a negative value:

// Negative values will be subtracted:
var dt2 = Ext.Date.add(new Date('10/1/2006'), Ext.Date.DAY, -5);
alert(dt2); // 'Tue Sep 26 2006 00:00:00'

Parameters

  • date : Date

    The date to modify.

  • interval : String

    A valid date interval enum value.

  • value : Number

    The amount to add to the current date.

Returns

  • Date

    The new Date instance.

Ext.DateExtras
view source
( date, unit ) : Date
Align the date to unit. ...

Align the date to unit.

Parameters

  • date : Date

    The date to be aligned.

  • unit : String

    The unit. This unit is compatible with the date interval constants.

Returns

  • Date

    The aligned date.

Ext.DateExtras
view source
( date, start, end ) : Boolean
Checks if a date falls on or between the given start and end dates. ...

Checks if a date falls on or between the given start and end dates.

Parameters

  • date : Date

    The date to check.

  • start : Date

    Start date.

  • end : Date

    End date.

Returns

  • Boolean

    true if this date falls on or between the given start and end dates.

Ext.DateExtras
view source
( date, [clone] ) : Date
Attempts to clear all time information from this Date by setting the time to midnight of the same day, automatically ...

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.

Parameters

  • date : Date

    The date.

  • clone : Boolean (optional)

    true to create a clone of this date, clear the time and return it.

    Defaults to: false

Returns

  • Date

    this or the clone.

Ext.DateExtras
view source
( date ) : Date
Creates and returns a new Date instance with the exact same date value as the called instance. ...

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'

Parameters

  • date : Date

    The date.

Returns

  • Date

    The new Date instance.

Ext.DateExtras
view source
( format )private
...

Parameters

Ext.DateExtras
view source
( date, format )private
Old Ext.Date prototype methods. ...

Old Ext.Date prototype methods.

Parameters

Ext.DateExtras
view source
( min, max, unit ) : Number
Calculate how many units are there between two time. ...

Calculate how many units are there between two time.

Parameters

  • min : Date

    The first time.

  • max : Date

    The second time.

  • unit : String

    The unit. This unit is compatible with the date interval constants.

Returns

  • Number

    The maximum number n of units that min + n * unit <= max.

Ext.DateExtras
view source
( date, format ) : String
Formats a date given the supplied format string. ...

Formats a date given the supplied format string.

Parameters

  • date : Date

    The date to format.

  • format : String

    The format string.

Returns

Ext.DateExtras
view source
( character, currentGroup )private
...

Parameters

Ext.DateExtras
view source
( date ) : Number
Get the numeric day number of the year, adjusted for leap year. ...

Get the numeric day number of the year, adjusted for leap year.

var dt = new Date('9/17/2011');
alert(Ext.Date.getDayOfYear(dt)); // 259

Parameters

  • date : Date

    The date.

Returns

  • Number

    0 to 364 (365 in leap years).

Ext.DateExtras
view source
( date ) : Number
Get the number of days in the current month, adjusted for leap year. ...

Get the number of days in the current month, adjusted for leap year.

var dt = new Date('1/10/2007');
alert(Ext.Date.getDaysInMonth(dt)); // 31

Parameters

  • date : Date

    The date.

Returns

  • Number

    The number of days in the month.

Ext.DateExtras
view source
( dateA, [dateB] ) : Number
Returns the number of milliseconds between two dates. ...

Returns the number of milliseconds between two dates.

Parameters

  • dateA : Date

    The first date.

  • dateB : Date (optional)

    The second date, defaults to now.

    Defaults to: new Date()

Returns

  • Number

    The difference in milliseconds.

Ext.DateExtras
view source
( date ) : Date
Get the date of the first day of the month in which this date resides. ...

Get the date of the first day of the month in which this date resides.

var dt = new Date('1/10/2007'),
    lastDate = Ext.Date.getFirstDateOfMonth(dt);
alert(lastDate); // Mon Jan 01 2007 00:00:00 GMT-0800 (PST)

Parameters

  • date : Date

    The date.

Returns

Ext.DateExtras
view source
( date ) : Number
Get the first day of the current month, adjusted for leap year. ...

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 monthNames array to retrieve the textual day name.

var dt = new Date('1/10/2007'),
    firstDay = Ext.Date.getFirstDayOfMonth(dt);
alert(Ext.Date.dayNames[firstDay]); // 'Monday'

Parameters

  • date : Date

    The date

Returns

Ext.DateExtras
view source
( character )private
...

Parameters

Ext.DateExtras
view source
( date, [colon] ) : String
Get the offset from GMT of the current date (equivalent to the format specifier 'O'). ...

Get the offset from GMT of the current date (equivalent to the format specifier 'O').

var dt = new Date('9/17/2011');
alert(Ext.Date.getGMTOffset(dt));

Parameters

  • date : Date

    The date.

  • colon : Boolean (optional)

    true to separate the hours and minutes with a colon.

    Defaults to: false

Returns

  • String

    The 4-character offset string prefixed with + or - (e.g. '-0600').

Ext.DateExtras
view source
( date ) : Date
Get the date of the last day of the month in which this date resides. ...

Get the date of the last day of the month in which this date resides.

var dt = new Date('1/10/2007'),
    lastDate = Ext.Date.getLastDateOfMonth(dt);
alert(lastDate); // Wed Jan 31 2007 00:00:00 GMT-0800 (PST)

Parameters

  • date : Date

    The date.

Returns

Ext.DateExtras
view source
( date ) : Number
Get the last day of the current month, adjusted for leap year. ...

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 monthNames array to retrieve the textual day name.

var dt = new Date('1/10/2007'),
    lastDay = Ext.Date.getLastDayOfMonth(dt);
alert(Ext.Date.dayNames[lastDay]); // 'Wednesday'

Parameters

  • date : Date

    The date.

Returns

Ext.DateExtras
view source
( name ) : Number
Get the zero-based JavaScript month number for the given short/full month name. ...

Get the zero-based JavaScript month number for the given short/full month name. Override this function for international dates.

Parameters

  • name : String

    The short/full month name.

Returns

  • Number

    The zero-based JavaScript month number.

Ext.DateExtras
view source
( day ) : String
Get the short day name for the given day number. ...

Get the short day name for the given day number. Override this function for international dates.

Parameters

  • day : Number

    A zero-based JavaScript day number.

Returns

Ext.DateExtras
view source
( month ) : String
Get the short month name for the given month number. ...

Get the short month name for the given month number. Override this function for international dates.

Parameters

  • month : Number

    A zero-based JavaScript month number.

Returns

Ext.DateExtras
view source
( date ) : String
Get the English ordinal suffix of the current day (equivalent to the format specifier 'S'). ...

Get the English ordinal suffix of the current day (equivalent to the format specifier 'S').

var dt = new Date('9/17/2011');
alert(Ext.Date.getSuffix(dt)); // 'th'

Parameters

  • date : Date

    The date.

Returns

  • String

    'st', 'nd', 'rd' or 'th'.

Ext.DateExtras
view source
( date ) : String
Get the timezone abbreviation of the current date (equivalent to the format specifier 'T'). ...

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.

var dt = new Date('9/17/2011');
alert(Ext.Date.getTimezone(dt));

Parameters

  • date : Date

    The date.

Returns

  • String

    The abbreviated timezone name (e.g. 'CST', 'PDT', 'EDT', 'MPST' ...).

Ext.DateExtras
view source
( date ) : Number
Get the numeric ISO-8601 week number of the year (equivalent to the format specifier 'W', but without a leading zero). ...

Get the numeric ISO-8601 week number of the year (equivalent to the format specifier 'W', but without a leading zero).

var dt = new Date('9/17/2011');
alert(Ext.Date.getWeekOfYear(dt)); // 37

Parameters

  • date : Date

    The date.

Returns

Ext.DateExtras
view source
( date ) : Boolean
Checks if the current date is affected by Daylight Saving Time (DST). ...

Checks if the current date is affected by Daylight Saving Time (DST).

var dt = new Date('9/17/2011');
alert(Ext.Date.isDST(dt));

Parameters

  • date : Date

    The date.

Returns

  • Boolean

    true if the current date is affected by DST.

Ext.DateExtras
view source
( date ) : Boolean
Checks if the current date falls within a leap year. ...

Checks if the current date falls within a leap year.

var dt = new Date('1/10/2011');
alert(Ext.Date.isLeapYear(dt)); // false

Parameters

  • date : Date

    The date.

Returns

  • Boolean

    true if the current date falls within a leap year, false otherwise.

Ext.DateExtras
view source
( year, month, day, [hour], [minute], [second], [millisecond] ) : Boolean
Checks if the passed Date parameters will cause a JavaScript Date "rollover". ...

Checks if the passed Date parameters will cause a JavaScript Date "rollover".

Parameters

  • year : Number

    4-digit year.

  • month : Number

    1-based month-of-year.

  • day : Number

    Day of month.

  • hour : Number (optional)

    Hour.

  • minute : Number (optional)

    Minute.

  • second : Number (optional)

    Second.

  • millisecond : Number (optional)

    Millisecond.

Returns

  • Boolean

    true if the passed parameters do not cause a Date "rollover", false otherwise.

Ext.DateExtras
view source
( ) : Number
Returns the current timestamp. ...

Returns the current timestamp.

Returns

Ext.DateExtras
view source
( input, format, [strict] ) : Date/null
Parses the passed string using the specified date format. ...

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 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 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); // null

Parameters

  • input : String/Number

    The raw date string.

  • format : String

    The expected date string format.

  • strict : Boolean (optional)

    true to validate date strings while parsing (i.e. prevents JavaScript Date "rollover"). Invalid date strings will return null when parsed.

    Defaults to: false

Returns

  • Date/null

    The parsed Date, or null if an invalid date string.

Ext.DateExtras
view source
( input, format, strict )private
Backwards compat ...

Backwards compat

Parameters