Alien-Web-ExtJS-V3

 view release on metacpan or  search on metacpan

share/docs/source/Date.html  view on Meta::CPAN

     * @return {Date} The new Date instance.
     */
    add : function(interval, value) {
        var d = this.clone();
        if (!interval || value === 0) return d;

        switch(interval.toLowerCase()) {
            case Date.MILLI:
                d.setMilliseconds(this.getMilliseconds() + value);
                break;
            case Date.SECOND:
                d.setSeconds(this.getSeconds() + value);
                break;
            case Date.MINUTE:
                d.setMinutes(this.getMinutes() + value);
                break;
            case Date.HOUR:
                d.setHours(this.getHours() + value);
                break;
            case Date.DAY:
                d.setDate(this.getDate() + value);
                break;
            case Date.MONTH:
                var day = this.getDate();
                if (day > 28) {
                    day = Math.min(day, this.getFirstDateOfMonth().add('mo', value).getLastDateOfMonth().getDate());
                }
                d.setDate(day);
                d.setMonth(this.getMonth() + value);
                break;
            case Date.YEAR:
                d.setFullYear(this.getFullYear() + value);
                break;
        }
        return d;
    },

<span id='Date-method-between'>    /**
</span>     * Checks if this date falls on or between the given start and end dates.
     * @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.
     */
    between : function(start, end) {
        var t = this.getTime();
        return start.getTime() &lt;= t &amp;&amp; t &lt;= end.getTime();
    }
});


<span id='Date-method-format'>/**
</span> * Formats a date given the supplied format string.
 * @param {String} format The format string.
 * @return {String} The formatted date.
 * @method format
 */
Date.prototype.format = Date.prototype.dateFormat;


// private
if (Ext.isSafari &amp;&amp; (navigator.userAgent.match(/WebKit\/(\d+)/)[1] || NaN) &lt; 420) {
    Ext.apply(Date.prototype, {
        _xMonth : Date.prototype.setMonth,
        _xDate  : Date.prototype.setDate,

        // Bug in Safari 1.3, 2.0 (WebKit build &lt; 420)
        // Date.setMonth does not work consistently if iMonth is not 0-11
        setMonth : function(num) {
            if (num &lt;= -1) {
                var n = Math.ceil(-num),
                    back_year = Math.ceil(n / 12),
                    month = (n % 12) ? 12 - n % 12 : 0;

                this.setFullYear(this.getFullYear() - back_year);

                return this._xMonth(month);
            } else {
                return this._xMonth(num);
            }
        },

        // Bug in setDate() method (resolved in WebKit build 419.3, so to be safe we target Webkit builds &lt; 420)
        // The parameter for Date.setDate() is converted to a signed byte integer in Safari
        // http://brianary.blogspot.com/2006/03/safari-date-bug.html
        setDate : function(d) {
            // use setTime() to workaround setDate() bug
            // subtract current day of month in milliseconds, then add desired day of month in milliseconds
            return this.setTime(this.getTime() - (this.getDate() - d) * 864e5);
        }
    });
}



/* Some basic Date tests... (requires Firebug)

Date.parseDate('', 'c'); // call Date.parseDate() once to force computation of regex string so we can console.log() it
console.log('Insane Regex for &quot;c&quot; format: %o', Date.parseCodes.c.s); // view the insane regex for the &quot;c&quot; format specifier

// standard tests
console.group('Standard Date.parseDate() Tests');
    console.log('Date.parseDate(&quot;2009-01-05T11:38:56&quot;, &quot;c&quot;)               = %o', Date.parseDate(&quot;2009-01-05T11:38:56&quot;, &quot;c&quot;)); // assumes browser's timezone setting
    console.log('Date.parseDate(&quot;2009-02-04T12:37:55.001000&quot;, &quot;c&quot;)        = %o', Date.parseDate(&quot;2009-02-04T12:37:55.001000&quot;, &quot;c&quot;)); // assumes browser's timezone setting
    console.log('Date.parseDate(&quot;2009-03-03T13:36:54,101000Z&quot;, &quot;c&quot;)       = %o', Date.parseDate(&quot;2009-03-03T13:36:54,101000Z&quot;, &quot;c&quot;)); // UTC
    console.log('Date.parseDate(&quot;2009-04-02T14:35:53.901000-0530&quot;, &quot;c&quot;)   = %o', Date.parseDate(&quot;2009-04-02T14:35:53.901000-0530&quot;, &quot;c&quot;)); // GMT-0530
    console.log('Date.parseDate(&quot;2009-05-01T15:34:52,9876000+08:00&quot;, &quot;c&quot;) = %o', Date.parseDate(&quot;2009-05-01T15:34:52,987600+08:00&quot;, &quot;c&quot;)); // GMT+08:00
console.groupEnd();

// ISO-8601 format as specified in http://www.w3.org/TR/NOTE-datetime
// -- accepts ALL 6 levels of date-time granularity
console.group('ISO-8601 Granularity Test (see http://www.w3.org/TR/NOTE-datetime)');
    console.log('Date.parseDate(&quot;1997&quot;, &quot;c&quot;)                              = %o', Date.parseDate(&quot;1997&quot;, &quot;c&quot;)); // YYYY (e.g. 1997)
    console.log('Date.parseDate(&quot;1997-07&quot;, &quot;c&quot;)                           = %o', Date.parseDate(&quot;1997-07&quot;, &quot;c&quot;)); // YYYY-MM (e.g. 1997-07)
    console.log('Date.parseDate(&quot;1997-07-16&quot;, &quot;c&quot;)                        = %o', Date.parseDate(&quot;1997-07-16&quot;, &quot;c&quot;)); // YYYY-MM-DD (e.g. 1997-07-16)
    console.log('Date.parseDate(&quot;1997-07-16T19:20+01:00&quot;, &quot;c&quot;)            = %o', Date.parseDate(&quot;1997-07-16T19:20+01:00&quot;, &quot;c&quot;)); // YYYY-MM-DDThh:mmTZD (e.g. 1997-07-16T19:20+01:00)
    console.log('Date.parseDate(&quot;1997-07-16T19:20:30+01:00&quot;, &quot;c&quot;)         = %o', Date.parseDate(&quot;1997-07-16T19:20:30+01:00&quot;, &quot;c&quot;)); // YYYY-MM-DDThh:mm:ssTZD (e.g. 1997-07-16T19:20:30+01:00)
    console.log('Date.parseDate(&quot;1997-07-16T19:20:30.45+01:00&quot;, &quot;c&quot;)      = %o', Date.parseDate(&quot;1997-07-16T19:20:30.45+01:00&quot;, &quot;c&quot;)); // YYYY-MM-DDThh:mm:ss.sTZD (e.g. 1997-07-16T19:20:30.45+01:00)
    console.log('Date.parseDate(&quot;1997-07-16 19:20:30.45+01:00&quot;, &quot;c&quot;)      = %o', Date.parseDate(&quot;1997-07-16 19:20:30.45+01:00&quot;, &quot;c&quot;)); // YYYY-MM-DD hh:mm:ss.sTZD (e.g. 1997-07-16T19:20:30.45+01:00)
    console.log('Date.parseDate(&quot;1997-13-16T19:20:30.45+01:00&quot;, &quot;c&quot;, true)= %o', Date.parseDate(&quot;1997-13-16T19:20:30.45+01:00&quot;, &quot;c&quot;, true)); // strict date parsing with invalid month value
console.groupEnd();



( run in 1.079 second using v1.01-cache-2.11-cpan-787462296c9 )