Alien-Web-ExtJS-V3
view release on metacpan or search on metacpan
share/pkgs/ext-foundation-debug.js view on Meta::CPAN
return function() { // return a closure for efficiency
var m = this.getMonth();
return m == 1 && this.isLeapYear() ? 29 : daysInMonth[m];
};
}(),
/**
* Get the English ordinal suffix of the current day (equivalent to the format specifier 'S').
* @return {String} 'st, 'nd', 'rd' or 'th'.
*/
getSuffix : function() {
switch (this.getDate()) {
case 1:
case 21:
case 31:
return "st";
case 2:
case 22:
return "nd";
case 3:
case 23:
return "rd";
default:
return "th";
}
},
/**
* 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:
* <pre><code>
//wrong way:
var orig = new Date('10/1/2006');
var copy = orig;
copy.setDate(5);
document.write(orig); //returns 'Thu Oct 05 2006'!
//correct way:
var orig = new Date('10/1/2006');
var copy = orig.clone();
copy.setDate(5);
document.write(orig); //returns 'Thu Oct 01 2006'
</code></pre>
* @return {Date} The new Date instance.
*/
clone : function() {
return new Date(this.getTime());
},
/**
* Checks if the current date is affected by Daylight Saving Time (DST).
* @return {Boolean} True if the current date is affected by DST.
*/
isDST : function() {
// adapted from http://extjs.com/forum/showthread.php?p=247172#post247172
// courtesy of @geoffrey.mcgill
return new Date(this.getFullYear(), 0, 1).getTimezoneOffset() != this.getTimezoneOffset();
},
/**
* 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 {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.
*/
clearTime : function(clone) {
if (clone) {
return this.clone().clearTime();
}
// get current date before clearing time
var d = this.getDate();
// clear time
this.setHours(0);
this.setMinutes(0);
this.setSeconds(0);
this.setMilliseconds(0);
if (this.getDate() != d) { // account for DST (i.e. day of month changed when setting hour = 0)
// note: DST adjustments are assumed to occur in multiples of 1 hour (this is almost always the case)
// refer to http://www.timeanddate.com/time/aboutdst.html for the (rare) exceptions to this rule
// increment hour until cloned date == current date
for (var hr = 1, c = this.add(Date.HOUR, hr); c.getDate() != d; hr++, c = this.add(Date.HOUR, hr));
this.setDate(d);
this.setHours(c.getHours());
}
return this;
},
/**
* 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:
* <pre><code>
// Basic usage:
var dt = new Date('10/29/2006').add(Date.DAY, 5);
document.write(dt); //returns 'Fri Nov 03 2006 00:00:00'
// Negative values will be subtracted:
var dt2 = new Date('10/1/2006').add(Date.DAY, -5);
document.write(dt2); //returns 'Tue Sep 26 2006 00:00:00'
// You can even chain several calls together in one line:
var dt3 = new Date('10/1/2006').add(Date.DAY, 5).add(Date.HOUR, 8).add(Date.MINUTE, -30);
document.write(dt3); //returns 'Fri Oct 06 2006 07:30:00'
</code></pre>
*
* @param {String} interval A valid date interval enum value.
( run in 1.381 second using v1.01-cache-2.11-cpan-02777c243ea )