Comparing version 0.3.7 to 0.3.8
342
d8.js
@@ -5,3 +5,3 @@ ;!function( util ) { | ||
/*~ d8/src/utils.js ~*/ | ||
/*~ src/utils.js ~*/ | ||
// utility methods | ||
@@ -23,6 +23,16 @@ function _indexOf( o, k ) { var i = o.indexOf( k ); return i == -1 ? null : i; } | ||
/*~ d8/src/fns.js ~*/ | ||
/*~ src/fns.js ~*/ | ||
// private methods | ||
function _24hrTime( o, res ) { return ( o = Number( o ) ) < 12 && _lc( res.ampm ) == _lc( LOCALE.PM ) ? o += 12 : o; } | ||
function _adjust( d, v, k ) { return d.adjust( k, v ); } | ||
function _adjust_toobj( a ) { | ||
return adjust_order.reduce( function( v, k, i ) { | ||
var delta = parseFloat( a[i] ); | ||
if ( !isNaN( delta ) && delta !== 0 ) | ||
v[k] = delta; | ||
return v; | ||
}, util.obj() ); | ||
} | ||
function _dayOffset( d ) { return Math.floor( ( d - getISOFirstMondayOfYear.call( d ) ) / MS_DAY ); } | ||
@@ -41,17 +51,25 @@ function _timezoneOffset( o ) { | ||
function adjust( o, v ) { | ||
if ( util.nativeType( o ) == 'object' ) { | ||
Object.reduce( o, _adjust, this ); | ||
return this; | ||
var date = this, day, fn, weekday; // noinspection FallthroughInSwitchStatementJS | ||
switch ( util.ntype( o ) ) { | ||
case 'number' : o = _adjust_toobj( arguments ); // allow fall-through | ||
case 'object' : Object.reduce( o, _adjust, date ); break; | ||
case 'string' : | ||
fn = adjust_by[o.toLowerCase()]; | ||
if ( fn && v !== 0 ) { | ||
LOCALE.setLeapYear( date ); | ||
if ( fn == adjust_by.month ) { | ||
day = date.getDate(); | ||
day < 28 || date.setDate( Math.min( day, getLastOfTheMonth.call( getFirstOfTheMonth.call( date ).adjust( Type.MONTH, v ) ).getDate() ) ); | ||
} | ||
fn != adjust_by.week || ( weekday = date.getDay() ); | ||
date[fn[1]]( date[fn[0]]() + v ); | ||
!weekday || date.setDate( date.getDate() + weekday ); | ||
} | ||
} | ||
var day, fn = adjust_by[o.toLowerCase()], weekday; | ||
if ( !fn || v === 0 ) return this; | ||
LOCALE.setLeapYear( this ); | ||
if ( fn == adjust_by.month ) { | ||
day = this.getDate(); | ||
day < 28 || this.setDate( Math.min( day, getLastOfTheMonth.call( getFirstOfTheMonth.call( this ).adjust( Type.MONTH, v ) ) ).getDate() ); | ||
} | ||
fn != adjust_by.week || ( weekday = this.getDay() ); | ||
this[fn[1]]( this[fn[0]]() + v ); | ||
!weekday || this.setDate( this.getDate() + weekday ); | ||
return this; | ||
return date; | ||
} | ||
@@ -112,19 +130,21 @@ | ||
/*~ d8/src/format.js ~*/ | ||
function buildTemplate( o ) { | ||
if ( cache_format[o] ) return cache_format[o]; | ||
/*~ src/format.js ~*/ | ||
function buildTemplate( date_format ) { | ||
if ( cache_format[date_format] ) return cache_format[date_format]; | ||
var fn = ['var out=[];'], i = -1, p, parts = o.replace( re_add_nr, NOREPLACE_RB ).replace( re_add_enr, NOREPLACE_RE ).split( re_split ), re_invalid = /^[^A-Za-z]*$/g, l = parts.length; | ||
var fn = ['var out=[];'], i = -1, part, | ||
parts = date_format.replace( re_add_nr, NOREPLACE_RB ).replace( re_add_enr, NOREPLACE_RE ).split( re_split ), | ||
re_invalid = /^[^A-Za-z]*$/g, l = parts.length; | ||
while( ++i < l ) { | ||
p = parts[i]; | ||
p == NOREPLACE ? ( fn.push( tplOut( parts[++i] ) ), ++i ) | ||
: re_invalid.test( p ) | ||
? fn.push( tplOut( p ) ) | ||
: fn.push( compileTplStr( p ) ); | ||
part = parts[i]; | ||
part == NOREPLACE ? ( fn.push( tplOut( parts[++i] ) ), ++i ) | ||
: re_invalid.test( part ) | ||
? fn.push( tplOut( part ) ) | ||
: fn.push( compileTplStr( part ) ); | ||
} | ||
fn.push( 'return out.join( "" );' ); | ||
fn.push( 'return out.join( "" );\n//@ sourceURL=d8/format/' + date_format ); | ||
return cache_format[o] = new Function( 'filter', 'date', fn.join( '\n' ) ); | ||
return cache_format[date_format] = new Function( 'filter', 'date', fn.join( '\n' ) ); | ||
} | ||
@@ -138,14 +158,16 @@ | ||
/*~ d8/src/toDate.js ~*/ | ||
function buildParser( o ) { | ||
if ( cache_parse[o] ) return cache_parse[o]; | ||
var fn = {}, keys = [], i = -1, parts = o.replace( re_add_nr, NOREPLACE_RB ).replace( re_add_enr, NOREPLACE_RE ).split( re_split ), | ||
l = parts.length, p, re = []; | ||
/*~ src/toDate.js ~*/ | ||
function buildParser( date_format ) { | ||
if ( cache_parse[date_format] ) return cache_parse[date_format]; | ||
var parsers = {}, keys = [], i = -1, part, | ||
parts = date_format.replace( re_add_nr, NOREPLACE_RB ).replace( re_add_enr, NOREPLACE_RE ).split( re_split ), | ||
l = parts.length, re = []; | ||
while ( ++i < l ) { | ||
p = parts[i]; | ||
if ( p == NOREPLACE ) { | ||
re.push( parts[++i] ); ++i; continue; | ||
part = parts[i]; | ||
if ( part == NOREPLACE ) { | ||
re.push( parts[++i] ); ++i; | ||
continue; | ||
} | ||
p.replace( re_compile, function( m, p1, p2, p3 ) { | ||
part.replace( re_compile, function( m, p1, p2, p3 ) { | ||
var _fn, _k, _p; | ||
@@ -155,3 +177,3 @@ if ( !( _p = parser[p2] ) ) return; | ||
keys.push( _p.k ); | ||
if ( _p.fn ) fn[_p.k] = _p.fn; | ||
if ( _p.fn ) parsers[_p.k] = _p.fn; | ||
} | ||
@@ -162,3 +184,3 @@ if ( _p.combo ) { | ||
keys.push.apply( keys, _k ); | ||
util.copy( fn, _fn, true ); | ||
util.copy( parsers, _fn, true ); | ||
} | ||
@@ -168,45 +190,53 @@ if ( _p.re ) re.push( p1, _p.re, p3 ); | ||
} | ||
return cache_parse[o] = parse.bind( null, new RegExp( re.join( '' ) ), keys, fn ); | ||
return cache_parse[date_format] = parse.bind( null, new RegExp( re.join( '' ) ), keys, parsers ); | ||
} | ||
function parse( re, keys, fn, s ) { | ||
var d = new Type(), m = s.match( re ), o = associate( m.slice( 1 ), keys ); | ||
var date = new Type(), parts = s.match( re ), | ||
parsers = associate( parts.slice( 1 ), keys ); | ||
Object.reduce( o, function( n, v, k ) { if ( fn[k] ) o[k] = fn[k]( v, o ); return n; }, null ); | ||
Object.reduce( parsers, function( n, v, k ) { | ||
if ( typeof v == 'string' && fn[k] ) | ||
parsers[k] = fn[k]( v, parsers ); | ||
return n; | ||
}, null ); | ||
if ( !isNaN( o[UNIX] ) ) d.setTime( o[UNIX] ); | ||
if ( !isNaN( parsers[UNIX] ) ) date.setTime( parsers[UNIX] ); | ||
else { | ||
parse_setTime( d, o[HOUR], o[MINUTE], o[SECOND], o[MILLISECOND] ); | ||
parse_setDate( d, o ); | ||
parse_setTimezoneOffset( d, o[TIMEZONE] ); | ||
parse_setTime( date, parsers[HOUR], parsers[MINUTE], parsers[SECOND], parsers[MILLISECOND] ); | ||
parse_setDate( date, parsers ); | ||
parse_setTimezoneOffset( date, parsers[TIMEZONE] ); | ||
} | ||
return d; | ||
return date; | ||
} | ||
function parse_setDate( d, o ) { | ||
var dw, l, ly, odc, i = -1; | ||
function parse_setDate( date, parsers ) { | ||
var dayweek, i = -1, l, leapyr, ordinal; | ||
if ( date_members.every( util.has.bind( null, o ) ) ) return; // only set the date if there's one to set (i.e. the format is not just for time) | ||
if ( date_members.every( util.has.bind( null, parsers ) ) ) return; // only set the date if there's one to set (i.e. the format is not just for time) | ||
if ( isNaN( o[YEAR] ) ) o[YEAR] = d.getFullYear(); | ||
if ( isNaN( parsers[YEAR] ) ) parsers[YEAR] = date.getFullYear(); | ||
if ( isNaN( o[MONTH] ) ) { | ||
ly = LOCALE.isLeapYear( o[YEAR] ) ? 1 : 0; odc = LOCALE.ordinal_day_count[ly]; l = odc.length; o[MONTH] = 0; | ||
if ( isNaN( parsers[MONTH] ) ) { | ||
leapyr = LOCALE.isLeapYear( parsers[YEAR] ) ? 1 : 0; | ||
ordinal = LOCALE.ordinal_day_count[leapyr]; | ||
l = ordinal.length; | ||
parsers[MONTH] = 0; | ||
if ( o[WEEK] && !o[DAYYEAR] ) { // give precedence to the day of the year | ||
dw = o[DAYWEEK]; | ||
dw = isNaN( dw ) ? 0 : !dw ? 7 : dw; | ||
o[DAYYEAR] = ( o[WEEK] * 7 ) - ( 4 - dw ); | ||
if ( parsers[WEEK] && !parsers[DAYYEAR] ) { // give precedence to the day of the year | ||
dayweek = parsers[DAYWEEK]; | ||
dayweek = isNaN( dayweek ) ? 0 : !dayweek ? 7 : dayweek; | ||
parsers[DAYYEAR] = ( parsers[WEEK] * 7 ) - ( 4 - dayweek ); | ||
} | ||
if ( !isNaN( o[DAYYEAR] ) ) { | ||
if ( o[DAYYEAR] > odc[odc.length - 1] ) { | ||
o[DAYYEAR] -= odc[odc.length - 1]; | ||
++o[YEAR]; | ||
if ( !isNaN( parsers[DAYYEAR] ) ) { | ||
if ( parsers[DAYYEAR] > ordinal[ordinal.length - 1] ) { | ||
parsers[DAYYEAR] -= ordinal[ordinal.length - 1]; | ||
++parsers[YEAR]; | ||
} | ||
while( ++i < l ) { | ||
if ( between_equalto( o[DAYYEAR], odc[i], odc[i+1] ) ) { | ||
o[MONTH] = i; | ||
o[DAY] = odc[i] == 0 ? o[DAYYEAR] : ( o[DAYYEAR] - odc[i] ); | ||
if ( between_equalto( parsers[DAYYEAR], ordinal[i], ordinal[i+1] ) ) { | ||
parsers[MONTH] = i; | ||
parsers[DAY] = ordinal[i] == 0 ? parsers[DAYYEAR] : ( parsers[DAYYEAR] - ordinal[i] ); | ||
break; | ||
@@ -218,21 +248,147 @@ } | ||
if ( isNaN( o[DAY] ) ) o[DAY] = 1; | ||
if ( isNaN( parsers[DAY] ) ) parsers[DAY] = 1; | ||
d.setYear( o[YEAR] ); d.setMonth( o[MONTH] ); d.setDate( o[DAY] ); | ||
date.setYear( parsers[YEAR] ); date.setMonth( parsers[MONTH] ); date.setDate( parsers[DAY] ); | ||
} | ||
function parse_setTime( d, h, m, s, ms ) { | ||
d.setHours( h || 0 ); d.setMinutes( m || 0 ); | ||
d.setSeconds( s || 0 ); d.setMilliseconds( ms || 0 ); | ||
function parse_setTime( date, hr, min, sec, ms ) { | ||
date.setHours( hr || 0 ); date.setMinutes( min || 0 ); | ||
date.setSeconds( sec || 0 ); date.setMilliseconds( ms || 0 ); | ||
} | ||
function parse_setTimezoneOffset( d, tzo ) { | ||
!between_equalto( tzo, -43200, 50400 ) || d.adjust( Type.SECOND, ( -d.getTimezoneOffset() * 60 ) - tzo ); | ||
function parse_setTimezoneOffset( date, tzoffset ) { | ||
!between_equalto( tzoffset, -43200, 50400 ) || date.adjust( Type.SECOND, ( -date.getTimezoneOffset() * 60 ) - tzoffset ); | ||
} | ||
function toDate( s, f ) { return buildParser( f )( s ); } | ||
function toDate( date_str, date_format ) { | ||
return buildParser( date_format )( date_str ); | ||
} | ||
/*~ d8/src/vars.js ~*/ | ||
/*~ src/diff.js ~*/ | ||
function diff( now, props ) { //noinspection FallthroughInSwitchStatementJS | ||
switch ( util.ntype( now ) ) { | ||
case 'string' : | ||
if ( isNaN( +( new Date( now ) ) ) ) { | ||
if ( props ) { | ||
now = Date.now(); | ||
break; | ||
} | ||
} | ||
else { | ||
now = new Date( now ); | ||
break; | ||
} // allow [specific] fall-through | ||
case 'array' : case 'object' : | ||
props = now; | ||
now = Date.now(); | ||
break; | ||
case 'date' : if ( !isNaN( +( new Date( now ) ) ) ) break; // allow fall-through if not a valid date | ||
default : now = Date.now(); | ||
} | ||
var ddiiff, | ||
ms = now - ( +this ), | ||
tense = ms < 0 ? 1 : ms > 0 ? -1 : 0; | ||
ddiiff = tense === 0 ? util.obj() : diff_get( Math.abs( ms ), diff_get_exclusions( props ) ); | ||
ddiiff.tense = tense; | ||
return ddiiff; | ||
} | ||
function diff_eval( ddiiff, calc, i, calcs ) { | ||
var time; | ||
if ( ddiiff.__ms__ ) { | ||
if ( !ddiiff.excl[calc[0]] ) { | ||
if ( ddiiff.__ms__ >= calc[1] ) { | ||
time = ddiiff.__ms__ / calc[1]; | ||
if ( !( calc[0] in ddiiff.val ) ) { | ||
ddiiff.__ms__ = ( time % 1 ) * calc[1]; | ||
ddiiff.val[calc[0]] = Math.floor( time ); | ||
} | ||
else { | ||
time = Math.floor( time ); | ||
ddiiff.__ms__ -= time * calc[1]; | ||
ddiiff.val[calc[0]] += time; | ||
} | ||
} | ||
return ddiiff; | ||
} | ||
// round up or down depending on what's available | ||
if ( ( !calcs[i + 1] || ddiiff.excl[calcs[i + 1][0]] ) && ( calc = calcs[i - 1] ) ) { | ||
time = ddiiff.__ms__ / calc[1]; | ||
ddiiff.__ms__ = ( Math.round( time ) * calc[1] ) + ( ( ( ddiiff.__ms__ / calcs[i][1] ) % 1 ) * calcs[i][1] ); | ||
return diff_eval( ddiiff, calc, i - 1, [] ); | ||
} | ||
return ddiiff; | ||
} | ||
return ddiiff; | ||
} | ||
function diff_get( ms, excl ) { | ||
var ddiiff = diff_calc.reduce( diff_eval, { | ||
__ms__ : ms, | ||
excl : excl, | ||
val : util.obj() | ||
} ).val; | ||
ddiiff.value = ms; | ||
return ddiiff; | ||
} | ||
function diff_get_exclusions( props ) { | ||
var excl = util.obj(), incl_remaining = true; | ||
if ( props ) { //noinspection FallthroughInSwitchStatementJS | ||
switch ( util.ntype( props ) ) { | ||
case 'object' : incl_remaining = false; break; | ||
case 'string' : props = props.split( ' ' ); // allow fall-through | ||
case 'array' : props = props.reduce( diff_excl, excl ); | ||
incl_remaining = !!util.len( excl ); | ||
} | ||
} | ||
diff_props.map( function( prop ) { | ||
if ( !( prop in this ) ) | ||
this[prop] = !incl_remaining; | ||
}, excl ); | ||
return excl; | ||
} | ||
function diff_excl( excl, val ) { | ||
var prop = ( val = String( val ).toLowerCase() ).substring( 1 ); | ||
switch ( val.charAt( 0 ) ) { | ||
case '-' : excl[prop] = true; break; | ||
case '+' : excl[prop] = false; break; | ||
case '>' : | ||
diff_calc.map( diff_excl_iter, { excl : excl, prop : prop, val : true } ); | ||
break; | ||
case '<' : | ||
diff_calc.slice().reverse().map( diff_excl_iter, { excl : excl, prop : prop, val : false } ); | ||
break; | ||
default : excl[val] = false; | ||
} | ||
return excl; | ||
} | ||
function diff_excl_iter( calc ) { | ||
if ( calc[0] === this.prop ) | ||
this.SET_VALID = true; | ||
if ( this.SET_VALID ) | ||
this.excl[calc[0]] = this.val; | ||
} | ||
/*~ src/vars.js ~*/ | ||
var LOCALE = Type.locale, U, | ||
// DAY_OFFSETS is the amount of days from the current day to the Monday of the week it belongs to | ||
DAY_OFFSETS = [9, 1, 0, -1, -2, 4, 3], MS_DAY = 864e5, MS_WEEK = 6048e5, | ||
DAY_OFFSETS = [9, 1, 0, -1, -2, 4, 3], MS_DAY = 864e5, MS_HOUR = 3600000, MS_MINUTE = 60000, | ||
MS_MONTH = 2592e6, MS_SECOND = 1000, MS_WEEK = 6048e5, MS_YEAR = 31536e6, | ||
SHORT_DAYS = LOCALE.days.map( _substr ), SHORT_MONTHS = LOCALE.months.map( _substr ), | ||
@@ -243,6 +399,18 @@ // parser keys | ||
// used by Date.prototype.format && Date.toDate to replace escaped chars | ||
NOREPLACE = 'NOREPLACE', NOREPLACE_RB = '<' + NOREPLACE + '<', NOREPLACE_RE = '>END' + NOREPLACE + '>', | ||
adjust_by = { day : ['getDate', 'setDate'], hr : ['getHours', 'setHours'], min : ['getMinutes', 'setMinutes'], month : ['getMonth', 'setMonth'], ms : ['getMilliseconds', 'setMilliseconds'], sec : ['getSeconds', 'setSeconds'], week : ['getWeek', 'setWeek'], year : ['getFullYear', 'setFullYear'] }, | ||
NOREPLACE = 'NOREPLACE', NOREPLACE_RB = '<' + NOREPLACE + '<', NOREPLACE_RE = '>END' + NOREPLACE + '>', | ||
adjust_by = { day : ['getDate', 'setDate'], hr : ['getHours', 'setHours'], min : ['getMinutes', 'setMinutes'], month : ['getMonth', 'setMonth'], ms : ['getMilliseconds', 'setMilliseconds'], sec : ['getSeconds', 'setSeconds'], week : ['getWeek', 'setWeek'], year : ['getFullYear', 'setFullYear'] }, | ||
adjust_order = [YEAR, MONTH, WEEK, DAY, 'hr', MINUTE.substring( 0, 3 ), SECOND.substring( 0, 3 ), MILLISECOND], | ||
// cache objects | ||
cache_format = {}, cache_parse = {}, date_members = [DAY, DAYWEEK, DAYYEAR, MONTH, WEEK, YEAR], | ||
diff_calc = [ // the order of this Array is important as it is the remainder of the larger | ||
[YEAR + 's', MS_YEAR], // time unit that gets passed to the following time unit — as such we want | ||
[MONTH + 's', MS_MONTH], // to keep the order in case we want to exclude time units from the diff | ||
[WEEK + 's', MS_WEEK], | ||
[DAY + 's', MS_DAY], | ||
[HOUR + 's', MS_HOUR], | ||
[MINUTE + 's', MS_MINUTE], | ||
[SECOND + 's', MS_SECOND], | ||
[MILLISECOND, 1] | ||
], | ||
diff_props = diff_calc.map( function( calc ) { return calc[0]; } ), | ||
filter = { | ||
@@ -267,3 +435,3 @@ // day | ||
// year | ||
L : function( d ) { return ( d.isLeapYear() ) ? 1 : 0; }, // Whether it's a leap year | ||
L : function( d ) { return d.isLeapYear() ? 1 : 0; }, // Whether it's a leap year | ||
o : function( d ) { // ISO-8601 year number. This has the same value as Y, except that if the ISO | ||
@@ -353,4 +521,4 @@ var m = d.getMonth(), w = getISOWeek.call( d ); // week number (W) belongs to the previous or next year, that year is used instead. | ||
parser.c = { | ||
combo : [parser.Y, parser.m, parser.d, parser.H, parser.i, parser.s, parser.P], | ||
re : [parser.Y.re, '-', parser.m.re, '-', parser.d.re, 'T', parser.H.re, ':', parser.i.re, ':', parser.s.re, parser.P.re].join( '' ) | ||
combo : [parser.Y, parser.m, parser.d, parser.H, parser.i, parser.s, parser.u, parser.P], | ||
re : [parser.Y.re, '-', parser.m.re, '-', parser.d.re, 'T', parser.H.re, ':', parser.i.re, ':', parser.s.re, '(?:\\.', parser.u.re, '){0,1}', parser.P.re, '{0,1}'].join( '' ) | ||
}; | ||
@@ -362,12 +530,12 @@ parser.r = { | ||
/*~ d8/src/expose.js ~*/ | ||
/*~ src/expose.js ~*/ | ||
// instance methods | ||
util.defs( Type.prototype, { | ||
adjust : adjust, between : between, clearTime : clearTime, | ||
clone : clone, format : format, getDayOfYear : getDayOfYear, | ||
getFirstOfTheMonth : getFirstOfTheMonth, getGMTOffset : getGMTOffset, getISODay : getISODay, | ||
getISODaysInYear : getISODaysInYear, getISOFirstMondayOfYear : getISOFirstMondayOfYear, getISOWeek : getISOWeek, | ||
getISOWeeksInYear : getISOWeeksInYear, getLastOfTheMonth : getLastOfTheMonth, getWeek : getWeek, | ||
isDST : isDST, isLeapYear : isLeapYear, setWeek : setWeek, | ||
timezone : timezone | ||
adjust : adjust, between : between, clearTime : clearTime, | ||
clone : clone, diff : diff, format : format, | ||
getDayOfYear : getDayOfYear, getFirstOfTheMonth : getFirstOfTheMonth, getGMTOffset : getGMTOffset, | ||
getISODay : getISODay, getISODaysInYear : getISODaysInYear, getISOFirstMondayOfYear : getISOFirstMondayOfYear, | ||
getISOWeek : getISOWeek, getISOWeeksInYear : getISOWeeksInYear, getLastOfTheMonth : getLastOfTheMonth, | ||
getWeek : getWeek, isDST : isDST, isLeapYear : isLeapYear, | ||
setWeek : setWeek, timezone : timezone | ||
}, 'r' ); | ||
@@ -380,3 +548,3 @@ | ||
// constants defining milliseconds for different times | ||
MS_DAY : MS_DAY, MS_WEEK : MS_WEEK, MS_MONTH : 2592e6, MS_YEAR : 31536e6, | ||
MS_DAY : MS_DAY, MS_HOUR : MS_HOUR, MS_MINUTE : MS_MINUTE, MS_MONTH : MS_MONTH, MS_SECOND : MS_SECOND, MS_WEEK : MS_WEEK, MS_YEAR : MS_YEAR, | ||
// filters and formats | ||
@@ -383,0 +551,0 @@ filters : { value : filter }, formats : { value : formats }, parsers : { value : parser }, |
@@ -1,1 +0,1 @@ | ||
!function(e){"use strict";e.x.cache("Date",function(t){function n(e,t){var n=e.indexOf(t);return n==-1?null:n}function r(e){return e.toLowerCase()}function i(e){return e.substring(0,3)}function s(e){return e.toUpperCase()}function o(e,t){return e.reduce(function(e,n,r){return e[t[r]]=n,e},{})}function u(e,t,n){return t<=e&&e<=n}function a(e,t,n){var r=-1,i=e.toString(n||10);t-=i.length;while(++r<t)i="0"+i;return i}function f(e,t){return e.reduce(function(e,n){return!(t in n)||e.push(n[t]),e},[])}function l(e,t){return e+t}function c(e,t){return(e=Number(e))<12&&r(t.ampm)==r(X.PM)?e+=12:e}function h(e,t,n){return e.adjust(n,t)}function p(e){return Math.floor((e-C.call(e))/J)}function d(e){var t=!!e.indexOf("-"),n=e.match(_t),r=(Number(n[1])+n[2]/60)*3600;return t?r:-r}function v(e){return Math.floor(Math.abs(p(e)/7))}function m(e,t){return isNaN(t)?Number(e)-1:t==e?0:Number(t)}function g(n,r){if(e.nativeType(n)=="object")return Object.reduce(n,h,this),this;var i,s=dt[n.toLowerCase()],o;return!s||r===0?this:(X.setLeapYear(this),s==dt.month&&(i=this.getDate(),i<28||this.setDate(Math.min(i,A.call(S.call(this).adjust(t.MONTH,r))).getDate())),s!=dt.week||(o=this.getDay()),this[s[1]](this[s[0]]()+r),!o||this.setDate(this.getDate()+o),this)}function y(e,t){return this>=e&&this<=t}function b(){return this.setHours(0),this.setMinutes(0),this.setSeconds(0),this.setMilliseconds(0),this}function w(){return new t(this.getTime())}function E(){return X.setLeapYear(this),X.day_count.slice(0,this.getMonth()).reduce(l,0)+this.getDate()-1}function S(){return new t(this.getFullYear(),this.getMonth(),1)}function x(e){var t=this.getTimezoneOffset();return[t>0?"-":"+",a(Math.floor(Math.abs(t)/60),2),e?":":"",a(Math.abs(t%60),2)].join("")}function T(){return this.getDay()||7}function N(){return Math.ceil((C.call(new t(this.getFullYear()+1,0,1))-C.call(this))/J)}function C(){var e=this.getFullYear();return new t(e,0,$[(new t(e,0,1)).getDay()])}function k(){var e,n=this.getFullYear();return this>=C.call(new t(n+1,0,1))?1:(e=Math.floor((E.call(this)-T.call(this)+10)/7),e==0?L.call(new t(n-1,0,1))-v(this):e)}function L(){return Math.round((C.call(new t(this.getFullYear()+1,0,1))-C.call(this))/K)}function A(){var e=this.getMonth();return X.setLeapYear(this),new t(this.getFullYear(),e,X.day_count[e])}function O(){return Math.floor(E.call(this)/7)}function M(){return(new t(this.getFullYear(),0,1)).getTimezoneOffset()!=this.getTimezoneOffset()}function _(){return X.isLeapYear(this.getFullYear())}function D(e){return this.setMonth(0),this.setDate(1),this.adjust(t.DAY,e*7).getTime()}function P(){var e=this.toString().split(" ");return e.splice(4,e.length).join(" ").replace(Ot,"$1").replace(Mt,"")}function H(e){if(vt[e])return vt[e];var t=["var out=[];"],n=-1,r,i=e.replace(Tt,ht).replace(xt,pt).split(At),s=/^[^A-Za-z]*$/g,o=i.length;while(++n<o)r=i[n],r==ct?(t.push(F(i[++n])),++n):s.test(r)?t.push(F(r)):t.push(j(r));return t.push('return out.join( "" );'),vt[e]=new Function("filter","date",t.join("\n"))}function B(e){return H(e)(yt,this)}function j(e){return e.replace(Nt,function(e,t,n,r){return F(t+"', filter."+n+"( date ), '"+r)})}function F(e){return"out.push( '"+e+"' );"}function I(t){if(mt[t])return mt[t];var n={},r=[],i=-1,s=t.replace(Tt,ht).replace(xt,pt).split(At),u=s.length,a,l=[];while(++i<u){a=s[i];if(a==ct){l.push(s[++i]),++i;continue}a.replace(Nt,function(t,i,s,u){var a,c,h;if(!(h=Dt[s]))return;h.k&&(r.push(h.k),h.fn&&(n[h.k]=h.fn)),h.combo&&(c=f(h.combo,"k"),a=o(f(h.combo,"fn"),c),r.push.apply(r,c),e.copy(n,a,!0)),h.re&&l.push(i,h.re,u)})}return mt[t]=q.bind(null,new RegExp(l.join("")),r,n)}function q(e,n,r,i){var s=new t,u=i.match(e),a=o(u.slice(1),n);return Object.reduce(a,function(e,t,n){return r[n]&&(a[n]=r[n](t,a)),e},null),isNaN(a[at])?(U(s,a[nt],a[it],a[ot],a[rt]),R(s,a),z(s,a[ut])):s.setTime(a[at]),s}function R(t,n){var r,i,s,o,a=-1;if(gt.every(e.has.bind(null,n)))return;isNaN(n[lt])&&(n[lt]=t.getFullYear());if(isNaN(n[st])){s=X.isLeapYear(n[lt])?1:0,o=X.ordinal_day_count[s],i=o.length,n[st]=0,n[ft]&&!n[tt]&&(r=n[et],r=isNaN(r)?0:r?r:7,n[tt]=n[ft]*7-(4-r));if(!isNaN(n[tt])){n[tt]>o[o.length-1]&&(n[tt]-=o[o.length-1],++n[lt]);while(++a<i)if(u(n[tt],o[a],o[a+1])){n[st]=a,n[Z]=o[a]==0?n[tt]:n[tt]-o[a];break}}}isNaN(n[Z])&&(n[Z]=1),t.setYear(n[lt]),t.setMonth(n[st]),t.setDate(n[Z])}function U(e,t,n,r,i){e.setHours(t||0),e.setMinutes(n||0),e.setSeconds(r||0),e.setMilliseconds(i||0)}function z(e,n){!u(n,-43200,50400)||e.adjust(t.SECOND,-e.getTimezoneOffset()*60-n)}function W(e,t){return I(t)(e)}var X=t.locale,V,$=[9,1,0,-1,-2,4,3],J=864e5,K=6048e5,Q=X.days.map(i),G=X.months.map(i),Y="ampm",Z="day",et="dayweek",tt="dayyear",nt="hour",rt="ms",it="minute",st="month",ot="second",ut="timezone",at="unix",ft="week",lt="year",ct="NOREPLACE",ht="<"+ct+"<",pt=">END"+ct+">",dt={day:["getDate","setDate"],hr:["getHours","setHours"],min:["getMinutes","setMinutes"],month:["getMonth","setMonth"],ms:["getMilliseconds","setMilliseconds"],sec:["getSeconds","setSeconds"],week:["getWeek","setWeek"],year:["getFullYear","setFullYear"]},vt={},mt={},gt=[Z,et,tt,st,ft,lt],yt={d:function(e){return a(e.getDate(),2)},D:function(e){return X.days[e.getDay()].substring(0,3)},j:function(e){return e.getDate()},l:function(e){return X.days[e.getDay()]},N:function(e){return T.call(e)},S:function(e){return X.getOrdinal(e.getDate())},w:function(e){return e.getDay()},z:function(e){return e.getDayOfYear()},W:function(e){return k.call(e)},F:function(e){return X.months[e.getMonth()]},m:function(e){return a(e.getMonth()+1,2)},M:function(e){return X.months[e.getMonth()].substring(0,3)},n:function(e){return e.getMonth()+1},t:function(e){return X.setLeapYear(e),X.day_count[e.getMonth()]},L:function(e){return e.isLeapYear()?1:0},o:function(e){var t=e.getMonth(),n=k.call(e);return e.getFullYear()+(n==1&&t>0?1:n>=52&&t<11?-1:0)},Y:function(e){return e.getFullYear()},y:function(e){return String(e.getFullYear()).substring(2,4)},a:function(e){return r(e.getHours()<12?X.AM:X.PM)},A:function(e){return s(e.getHours()<12?X.AM:X.PM)},g:function(e){return e.getHours()%12||12},G:function(e){return e.getHours()},h:function(e){return a(yt.g(e),2)},H:function(e){return a(yt.G(e),2)},i:function(e){return a(e.getMinutes(),2)},s:function(e){return a(e.getSeconds(),2)},u:function(e){return a(e.getMilliseconds(),3)},O:function(e){return x.call(e)},P:function(e){return x.call(e,!0)},T:function(e){return P.call(e)},Z:function(e){return e.getTimezoneOffset()*-60},c:function(e){return B.call(e,wt.ISO_8601)},r:function(e){return B.call(e,wt.RFC_2822)},U:function(e){return e.getTime()}},bt=Object.keys(yt).sort().join(""),wt=e.copy({ISO_8601:"Y-m-d<T>H:i:s.u<Z>",ISO_8601_SHORT:"Y-m-d",RFC_850:"l, d-M-y H:i:s T",RFC_2822:"D, d M Y H:i:s O",sortable:"Y-m-d H:i:sO"},X.formats),Et,St="(am|pm)",xt=/>/g,Tt=/</g,Nt=new RegExp("([^"+bt+"]*)(["+bt+"])([^"+bt+"]*)","g"),Ct="([0-9]{1,2})",kt="([0-9]{2})",Lt="([0-9]{4})",At=/[<>]/,Ot=/[^\(]*\(([^\)]+)\)/g,Mt=/[^A-Z]+/g,_t=/[\+-]?([0-9]{2}):?([0-9]{2})/,Dt={d:{k:Z,fn:Number,re:kt},D:{k:et,fn:n.bind(null,Q),re:"("+Q.join("|")+")"},j:{k:Z,fn:Number,re:Ct},l:{k:et,fn:n.bind(null,X.days),re:"("+X.days.join("|")+")"},N:{k:et,fn:m.bind(null,7),re:"([1-7])"},S:{re:"(?:"+X.ordinal.join("|")+")"},w:{k:et,fn:Number,re:"([0-6])"},z:{k:tt,fn:Number,re:"([0-9]{1,3})"},W:{k:ft,fn:Number,re:kt},F:{k:st,fn:n.bind(null,X.months),re:"("+X.months.join("|")+")"},m:{k:st,fn:m,re:kt},M:{k:st,fn:n.bind(null,G),re:"("+G.join("|")+")"},n:{k:st,fn:m,re:Ct},t:{re:"[0-9]{2}"},L:{re:"(?:0|1)"},o:{k:lt,fn:Number,re:Lt},Y:{k:lt,fn:Number,re:Lt},y:{k:lt,fn:function(e){return e=Number(e),e+=e<30?2e3:1900},re:kt},a:{k:Y,fn:e,re:St},A:{k:Y,fn:r,re:s(St)},g:{k:nt,fn:c,re:Ct},G:{k:nt,fn:Number,re:Ct},h:{k:nt,fn:c,re:kt},H:{k:nt,fn:Number,re:kt},i:{k:it,fn:Number,re:kt},s:{k:ot,fn:Number,re:kt},u:{k:rt,fn:Number,re:"([0-9]{1,})"},O:{k:ut,fn:d,re:"([\\+-][0-9]{4})"},P:{k:ut,fn:d,re:"([\\+-][0-9]{2}:[0-9]{2})"},T:{re:"[A-Z]{1,4}"},Z:{k:ut,fn:Number,re:"([\\+-]?[0-9]{5})"},U:{k:at,fn:Number,re:"(-?[0-9]{1,})"}};wt.atom=wt.ISO_8601,wt.cookie=wt.RFC_850,wt.rss=wt.RFC_2822,Dt.c={combo:[Dt.Y,Dt.m,Dt.d,Dt.H,Dt.i,Dt.s,Dt.P],re:[Dt.Y.re,"-",Dt.m.re,"-",Dt.d.re,"T",Dt.H.re,":",Dt.i.re,":",Dt.s.re,Dt.P.re].join("")},Dt.r={combo:[Dt.D,Dt.d,Dt.M,Dt.Y,Dt.H,Dt.i,Dt.s,Dt.O],re:[Dt.D.re,", ",Dt.d.re," ",Dt.M.re," ",Dt.Y.re," ",Dt.H.re,":",Dt.i.re,":",Dt.s.re," ",Dt.O.re].join("")},e.defs(t.prototype,{adjust:g,between:y,clearTime:b,clone:w,format:B,getDayOfYear:E,getFirstOfTheMonth:S,getGMTOffset:x,getISODay:T,getISODaysInYear:N,getISOFirstMondayOfYear:C,getISOWeek:k,getISOWeeksInYear:L,getLastOfTheMonth:A,getWeek:O,isDST:M,isLeapYear:_,setWeek:D,timezone:P},"r"),e.defs(t,{DAY:Z,HOUR:"hr",MINUTE:it.substring(0,3),MILLISECOND:rt,MONTH:st,SECOND:ot.substring(0,3),WEEK:ft,YEAR:lt,MS_DAY:J,MS_WEEK:K,MS_MONTH:2592e6,MS_YEAR:31536e6,filters:{value:yt},formats:{value:wt},parsers:{value:Dt},getOrdinal:X.getOrdinal,isLeapYear:X.isLeapYear,setLeapYear:X.setLeapYear,toDate:W},"r")}).x(Date)}(typeof m8!="undefined"?m8:typeof require!="undefined"?require("m8"):null) | ||
!function(e){"use strict";e.x.cache("Date",function(t){function n(e,t){var n=e.indexOf(t);return n==-1?null:n}function r(e){return e.toLowerCase()}function i(e){return e.substring(0,3)}function s(e){return e.toUpperCase()}function o(e,t){return e.reduce(function(e,n,r){return e[t[r]]=n,e},{})}function u(e,t,n){return t<=e&&e<=n}function a(e,t,n){var r=-1,i=e.toString(n||10);t-=i.length;while(++r<t)i="0"+i;return i}function f(e,t){return e.reduce(function(e,n){return!(t in n)||e.push(n[t]),e},[])}function l(e,t){return e+t}function c(e,t){return(e=Number(e))<12&&r(t.ampm)==r(Y.PM)?e+=12:e}function h(e,t,n){return e.adjust(n,t)}function p(t){return kt.reduce(function(e,n,r){var i=parseFloat(t[r]);return!isNaN(i)&&i!==0&&(e[n]=i),e},e.obj())}function d(e){return Math.floor((e-k.call(e))/tt)}function v(e){var t=!!e.indexOf("-"),n=e.match($t),r=(Number(n[1])+n[2]/60)*3600;return t?r:-r}function m(e){return Math.floor(Math.abs(d(e)/7))}function g(e,t){return isNaN(t)?Number(e)-1:t==e?0:Number(t)}function y(n,r){var i=this,s,o,u;switch(e.ntype(n)){case"number":n=p(arguments);case"object":Object.reduce(n,h,i);break;case"string":o=Ct[n.toLowerCase()],o&&r!==0&&(Y.setLeapYear(i),o==Ct.month&&(s=i.getDate(),s<28||i.setDate(Math.min(s,O.call(x.call(i).adjust(t.MONTH,r)).getDate()))),o!=Ct.week||(u=i.getDay()),i[o[1]](i[o[0]]()+r),!u||i.setDate(i.getDate()+u))}return i}function b(e,t){return this>=e&&this<=t}function w(){return this.setHours(0),this.setMinutes(0),this.setSeconds(0),this.setMilliseconds(0),this}function E(){return new t(this.getTime())}function S(){return Y.setLeapYear(this),Y.day_count.slice(0,this.getMonth()).reduce(l,0)+this.getDate()-1}function x(){return new t(this.getFullYear(),this.getMonth(),1)}function T(e){var t=this.getTimezoneOffset();return[t>0?"-":"+",a(Math.floor(Math.abs(t)/60),2),e?":":"",a(Math.abs(t%60),2)].join("")}function N(){return this.getDay()||7}function C(){return Math.ceil((k.call(new t(this.getFullYear()+1,0,1))-k.call(this))/tt)}function k(){var e=this.getFullYear();return new t(e,0,et[(new t(e,0,1)).getDay()])}function L(){var e,n=this.getFullYear();return this>=k.call(new t(n+1,0,1))?1:(e=Math.floor((S.call(this)-N.call(this)+10)/7),e==0?A.call(new t(n-1,0,1))-m(this):e)}function A(){return Math.round((k.call(new t(this.getFullYear()+1,0,1))-k.call(this))/ot)}function O(){var e=this.getMonth();return Y.setLeapYear(this),new t(this.getFullYear(),e,Y.day_count[e])}function M(){return Math.floor(S.call(this)/7)}function _(){return(new t(this.getFullYear(),0,1)).getTimezoneOffset()!=this.getTimezoneOffset()}function D(){return Y.isLeapYear(this.getFullYear())}function P(e){return this.setMonth(0),this.setDate(1),this.adjust(t.DAY,e*7).getTime()}function H(){var e=this.toString().split(" ");return e.splice(4,e.length).join(" ").replace(Xt,"$1").replace(Vt,"")}function B(e){if(Lt[e])return Lt[e];var t=["var out=[];"],n=-1,r,i=e.replace(It,Tt).replace(Ft,Nt).split(Wt),s=/^[^A-Za-z]*$/g,o=i.length;while(++n<o)r=i[n],r==xt?(t.push(I(i[++n])),++n):s.test(r)?t.push(I(r)):t.push(F(r));return t.push('return out.join( "" );\n//@ sourceURL=d8/format/'+e),Lt[e]=new Function("filter","date",t.join("\n"))}function j(e){return B(e)(Dt,this)}function F(e){return e.replace(qt,function(e,t,n,r){return I(t+"', filter."+n+"( date ), '"+r)})}function I(e){return"out.push( '"+e+"' );"}function q(t){if(At[t])return At[t];var n={},r=[],i=-1,s,u=t.replace(It,Tt).replace(Ft,Nt).split(Wt),a=u.length,l=[];while(++i<a){s=u[i];if(s==xt){l.push(u[++i]),++i;continue}s.replace(qt,function(t,i,s,u){var a,c,h;if(!(h=Jt[s]))return;h.k&&(r.push(h.k),h.fn&&(n[h.k]=h.fn)),h.combo&&(c=f(h.combo,"k"),a=o(f(h.combo,"fn"),c),r.push.apply(r,c),e.copy(n,a,!0)),h.re&&l.push(i,h.re,u)})}return At[t]=R.bind(null,new RegExp(l.join("")),r,n)}function R(e,n,r,i){var s=new t,u=i.match(e),a=o(u.slice(1),n);return Object.reduce(a,function(e,t,n){return typeof t=="string"&&r[n]&&(a[n]=r[n](t,a)),e},null),isNaN(a[wt])?(z(s,a[dt],a[mt],a[yt],a[vt]),U(s,a),W(s,a[bt])):s.setTime(a[wt]),s}function U(t,n){var r,i=-1,s,o,a;if(Ot.every(e.has.bind(null,n)))return;isNaN(n[St])&&(n[St]=t.getFullYear());if(isNaN(n[gt])){o=Y.isLeapYear(n[St])?1:0,a=Y.ordinal_day_count[o],s=a.length,n[gt]=0,n[Et]&&!n[pt]&&(r=n[ht],r=isNaN(r)?0:r?r:7,n[pt]=n[Et]*7-(4-r));if(!isNaN(n[pt])){n[pt]>a[a.length-1]&&(n[pt]-=a[a.length-1],++n[St]);while(++i<s)if(u(n[pt],a[i],a[i+1])){n[gt]=i,n[ct]=a[i]==0?n[pt]:n[pt]-a[i];break}}}isNaN(n[ct])&&(n[ct]=1),t.setYear(n[St]),t.setMonth(n[gt]),t.setDate(n[ct])}function z(e,t,n,r,i){e.setHours(t||0),e.setMinutes(n||0),e.setSeconds(r||0),e.setMilliseconds(i||0)}function W(e,n){!u(n,-43200,50400)||e.adjust(t.SECOND,-e.getTimezoneOffset()*60-n)}function X(e,t){return q(t)(e)}function V(t,n){switch(e.ntype(t)){case"string":if(!isNaN(+(new Date(t)))){t=new Date(t);break}if(n){t=Date.now();break};case"array":case"object":n=t,t=Date.now();break;case"date":if(!isNaN(+(new Date(t))))break;default:t=Date.now()}var r,i=t- +this,s=i<0?1:i>0?-1:0;return r=s===0?e.obj():J(Math.abs(i),K(n)),r.tense=s,r}function $(e,t,n,r){var i;return e.__ms__?e.excl[t[0]]?(!r[n+1]||e.excl[r[n+1][0]])&&(t=r[n-1])?(i=e.__ms__/t[1],e.__ms__=Math.round(i)*t[1]+e.__ms__/r[n][1]%1*r[n][1],$(e,t,n-1,[])):e:(e.__ms__>=t[1]&&(i=e.__ms__/t[1],t[0]in e.val?(i=Math.floor(i),e.__ms__-=i*t[1],e.val[t[0]]+=i):(e.__ms__=i%1*t[1],e.val[t[0]]=Math.floor(i))),e):e}function J(t,n){var r=Mt.reduce($,{__ms__:t,excl:n,val:e.obj()}).val;return r.value=t,r}function K(t){var n=e.obj(),r=!0;if(t)switch(e.ntype(t)){case"object":r=!1;break;case"string":t=t.split(" ");case"array":t=t.reduce(Q,n),r=!!e.len(n)}return _t.map(function(e){e in this||(this[e]=!r)},n),n}function Q(e,t){var n=(t=String(t).toLowerCase()).substring(1);switch(t.charAt(0)){case"-":e[n]=!0;break;case"+":e[n]=!1;break;case">":Mt.map(G,{excl:e,prop:n,val:!0});break;case"<":Mt.slice().reverse().map(G,{excl:e,prop:n,val:!1});break;default:e[t]=!1}return e}function G(e){e[0]===this.prop&&(this.SET_VALID=!0),this.SET_VALID&&(this.excl[e[0]]=this.val)}var Y=t.locale,Z,et=[9,1,0,-1,-2,4,3],tt=864e5,nt=36e5,rt=6e4,it=2592e6,st=1e3,ot=6048e5,ut=31536e6,at=Y.days.map(i),ft=Y.months.map(i),lt="ampm",ct="day",ht="dayweek",pt="dayyear",dt="hour",vt="ms",mt="minute",gt="month",yt="second",bt="timezone",wt="unix",Et="week",St="year",xt="NOREPLACE",Tt="<"+xt+"<",Nt=">END"+xt+">",Ct={day:["getDate","setDate"],hr:["getHours","setHours"],min:["getMinutes","setMinutes"],month:["getMonth","setMonth"],ms:["getMilliseconds","setMilliseconds"],sec:["getSeconds","setSeconds"],week:["getWeek","setWeek"],year:["getFullYear","setFullYear"]},kt=[St,gt,Et,ct,"hr",mt.substring(0,3),yt.substring(0,3),vt],Lt={},At={},Ot=[ct,ht,pt,gt,Et,St],Mt=[[St+"s",ut],[gt+"s",it],[Et+"s",ot],[ct+"s",tt],[dt+"s",nt],[mt+"s",rt],[yt+"s",st],[vt,1]],_t=Mt.map(function(e){return e[0]}),Dt={d:function(e){return a(e.getDate(),2)},D:function(e){return Y.days[e.getDay()].substring(0,3)},j:function(e){return e.getDate()},l:function(e){return Y.days[e.getDay()]},N:function(e){return N.call(e)},S:function(e){return Y.getOrdinal(e.getDate())},w:function(e){return e.getDay()},z:function(e){return e.getDayOfYear()},W:function(e){return L.call(e)},F:function(e){return Y.months[e.getMonth()]},m:function(e){return a(e.getMonth()+1,2)},M:function(e){return Y.months[e.getMonth()].substring(0,3)},n:function(e){return e.getMonth()+1},t:function(e){return Y.setLeapYear(e),Y.day_count[e.getMonth()]},L:function(e){return e.isLeapYear()?1:0},o:function(e){var t=e.getMonth(),n=L.call(e);return e.getFullYear()+(n==1&&t>0?1:n>=52&&t<11?-1:0)},Y:function(e){return e.getFullYear()},y:function(e){return String(e.getFullYear()).substring(2,4)},a:function(e){return r(e.getHours()<12?Y.AM:Y.PM)},A:function(e){return s(e.getHours()<12?Y.AM:Y.PM)},g:function(e){return e.getHours()%12||12},G:function(e){return e.getHours()},h:function(e){return a(Dt.g(e),2)},H:function(e){return a(Dt.G(e),2)},i:function(e){return a(e.getMinutes(),2)},s:function(e){return a(e.getSeconds(),2)},u:function(e){return a(e.getMilliseconds(),3)},O:function(e){return T.call(e)},P:function(e){return T.call(e,!0)},T:function(e){return H.call(e)},Z:function(e){return e.getTimezoneOffset()*-60},c:function(e){return j.call(e,Ht.ISO_8601)},r:function(e){return j.call(e,Ht.RFC_2822)},U:function(e){return e.getTime()}},Pt=Object.keys(Dt).sort().join(""),Ht=e.copy({ISO_8601:"Y-m-d<T>H:i:s.u<Z>",ISO_8601_SHORT:"Y-m-d",RFC_850:"l, d-M-y H:i:s T",RFC_2822:"D, d M Y H:i:s O",sortable:"Y-m-d H:i:sO"},Y.formats),Bt,jt="(am|pm)",Ft=/>/g,It=/</g,qt=new RegExp("([^"+Pt+"]*)(["+Pt+"])([^"+Pt+"]*)","g"),Rt="([0-9]{1,2})",Ut="([0-9]{2})",zt="([0-9]{4})",Wt=/[<>]/,Xt=/[^\(]*\(([^\)]+)\)/g,Vt=/[^A-Z]+/g,$t=/[\+-]?([0-9]{2}):?([0-9]{2})/,Jt={d:{k:ct,fn:Number,re:Ut},D:{k:ht,fn:n.bind(null,at),re:"("+at.join("|")+")"},j:{k:ct,fn:Number,re:Rt},l:{k:ht,fn:n.bind(null,Y.days),re:"("+Y.days.join("|")+")"},N:{k:ht,fn:g.bind(null,7),re:"([1-7])"},S:{re:"(?:"+Y.ordinal.join("|")+")"},w:{k:ht,fn:Number,re:"([0-6])"},z:{k:pt,fn:Number,re:"([0-9]{1,3})"},W:{k:Et,fn:Number,re:Ut},F:{k:gt,fn:n.bind(null,Y.months),re:"("+Y.months.join("|")+")"},m:{k:gt,fn:g,re:Ut},M:{k:gt,fn:n.bind(null,ft),re:"("+ft.join("|")+")"},n:{k:gt,fn:g,re:Rt},t:{re:"[0-9]{2}"},L:{re:"(?:0|1)"},o:{k:St,fn:Number,re:zt},Y:{k:St,fn:Number,re:zt},y:{k:St,fn:function(e){return e=Number(e),e+=e<30?2e3:1900},re:Ut},a:{k:lt,fn:e,re:jt},A:{k:lt,fn:r,re:s(jt)},g:{k:dt,fn:c,re:Rt},G:{k:dt,fn:Number,re:Rt},h:{k:dt,fn:c,re:Ut},H:{k:dt,fn:Number,re:Ut},i:{k:mt,fn:Number,re:Ut},s:{k:yt,fn:Number,re:Ut},u:{k:vt,fn:Number,re:"([0-9]{1,})"},O:{k:bt,fn:v,re:"([\\+-][0-9]{4})"},P:{k:bt,fn:v,re:"([\\+-][0-9]{2}:[0-9]{2})"},T:{re:"[A-Z]{1,4}"},Z:{k:bt,fn:Number,re:"([\\+-]?[0-9]{5})"},U:{k:wt,fn:Number,re:"(-?[0-9]{1,})"}};Ht.atom=Ht.ISO_8601,Ht.cookie=Ht.RFC_850,Ht.rss=Ht.RFC_2822,Jt.c={combo:[Jt.Y,Jt.m,Jt.d,Jt.H,Jt.i,Jt.s,Jt.u,Jt.P],re:[Jt.Y.re,"-",Jt.m.re,"-",Jt.d.re,"T",Jt.H.re,":",Jt.i.re,":",Jt.s.re,"(?:\\.",Jt.u.re,"){0,1}",Jt.P.re,"{0,1}"].join("")},Jt.r={combo:[Jt.D,Jt.d,Jt.M,Jt.Y,Jt.H,Jt.i,Jt.s,Jt.O],re:[Jt.D.re,", ",Jt.d.re," ",Jt.M.re," ",Jt.Y.re," ",Jt.H.re,":",Jt.i.re,":",Jt.s.re," ",Jt.O.re].join("")},e.defs(t.prototype,{adjust:y,between:b,clearTime:w,clone:E,diff:V,format:j,getDayOfYear:S,getFirstOfTheMonth:x,getGMTOffset:T,getISODay:N,getISODaysInYear:C,getISOFirstMondayOfYear:k,getISOWeek:L,getISOWeeksInYear:A,getLastOfTheMonth:O,getWeek:M,isDST:_,isLeapYear:D,setWeek:P,timezone:H},"r"),e.defs(t,{DAY:ct,HOUR:"hr",MINUTE:mt.substring(0,3),MILLISECOND:vt,MONTH:gt,SECOND:yt.substring(0,3),WEEK:Et,YEAR:St,MS_DAY:tt,MS_HOUR:nt,MS_MINUTE:rt,MS_MONTH:it,MS_SECOND:st,MS_WEEK:ot,MS_YEAR:ut,filters:{value:Dt},formats:{value:Ht},parsers:{value:Jt},getOrdinal:Y.getOrdinal,isLeapYear:Y.isLeapYear,setLeapYear:Y.setLeapYear,toDate:X},"r")}).x(Date)}(typeof m8!="undefined"?m8:typeof require!="undefined"?require("m8"):null) |
@@ -9,3 +9,3 @@ { | ||
"dependencies" : { | ||
"m8" : ">= 0.2.7" | ||
"m8" : ">= 0.3.1" | ||
}, | ||
@@ -18,3 +18,3 @@ "devDependencies" : { | ||
"engines" : { | ||
"node" : ">= 0.4.x" | ||
"node" : ">= 0.8.x" | ||
}, | ||
@@ -35,3 +35,3 @@ "keywords" : ["date"], | ||
}, | ||
"version" : "0.3.7" | ||
"version" : "0.3.8" | ||
} |
205
README.md
@@ -11,4 +11,4 @@ # d8.js [![build status](https://secure.travis-ci.org/constantology/d8.png)](http://travis-ci.org/constantology/d8) | ||
- en-GB (0.6kb deflated) | ||
- en-US (0.6kb deflated) | ||
- en-GB (0.9kb gzipped) | ||
- en-US (0.9kb gzipped) | ||
@@ -42,7 +42,7 @@ but feel free to create a locale for your specific nationality and submit a pull request! :D | ||
require( 'd8/locale/en-GB' ); // IMPORTANT: The correct locale must be loaded before d8!! | ||
require( 'd8' ); | ||
require( 'd8/locale/en-GB' ); // IMPORTANT: The correct locale must be loaded before d8!! | ||
require( 'd8' ); | ||
// if running in a sandboxed environment remember to: | ||
require( 'm8' ).x( Date ); // and/ or any other Types that require extending. | ||
// if running in a sandboxed environment remember to: | ||
require( 'm8' ).x( Date ); // and/ or any other Types that require extending. | ||
@@ -73,6 +73,6 @@ ``` | ||
Date.getOrdinal( 1 ); // returns => "st" | ||
Date.getOrdinal( 10 ); // returns => "th" | ||
Date.getOrdinal( 22 ); // returns => "nd" | ||
Date.getOrdinal( 33 ); // returns => "rd" | ||
Date.getOrdinal( 1 ); // returns => "st" | ||
Date.getOrdinal( 10 ); // returns => "th" | ||
Date.getOrdinal( 22 ); // returns => "nd" | ||
Date.getOrdinal( 33 ); // returns => "rd" | ||
@@ -93,4 +93,4 @@ ``` | ||
Date.toDate( 'Sunday, the 1st of January 2012', 'l, <the> jS <of> F Y' ); // returns => Date { Sun Jan 01 2012 00:00:00 GMT+0000 (GMT) } | ||
Date.toDate( '2012-01-01T00:00:00+00:00', Date.formats.ISO_8601 ); // returns => Date { Sun Jan 01 2012 00:00:00 GMT+0000 (GMT) } | ||
Date.toDate( 'Sunday, the 1st of January 2012', 'l, <the> jS <of> F Y' ); // returns => Date { Sun Jan 01 2012 00:00:00 GMT+0000 (GMT) } | ||
Date.toDate( '2012-01-01T00:00:00+00:00', Date.formats.ISO_8601 ); // returns => Date { Sun Jan 01 2012 00:00:00 GMT+0000 (GMT) } | ||
@@ -129,10 +129,10 @@ ``` | ||
var date = new Date( 2012, 0, 1 ); // Date {Sun Jan 01 2012 00:00:00 GMT+0000 (GMT)} | ||
var date = new Date( 2012, 0, 1 ); // Date {Sun Jan 01 2012 00:00:00 GMT+0000 (GMT)} | ||
date.adjust( Date.DAY, 1 ); // Date {Mon Jan 02 2012 00:00:00 GMT+0000 (GMT)} | ||
date.adjust( Date.HOUR, -1 ); // Date {Sun Jan 01 2012 23:00:00 GMT+0000 (GMT)} | ||
date.adjust( { | ||
year : -1, month : -1, day : 24, | ||
hr : 1, sec : -1 | ||
} ); // Date {Sat Dec 25 2010 23:59:59 GMT+0000 (GMT)} | ||
date.adjust( Date.DAY, 1 ); // Date {Mon Jan 02 2012 00:00:00 GMT+0000 (GMT)} | ||
date.adjust( Date.HOUR, -1 ); // Date {Sun Jan 01 2012 23:00:00 GMT+0000 (GMT)} | ||
date.adjust( { | ||
year : -1, month : -1, day : 24, | ||
hr : 1, sec : -1 | ||
} ); // Date {Sat Dec 25 2010 23:59:59 GMT+0000 (GMT)} | ||
@@ -144,2 +144,14 @@ ``` | ||
##### Example: | ||
```javascript | ||
var date = new Date( 2012, 0, 1 ); | ||
date.between( new Date( 2011, 0, 1 ), new Date( 2013, 0, 1 ) ); // returns => true; | ||
date.between( new Date( 2013, 0, 1 ), new Date( 2011, 0, 1 ) ); // returns => false; | ||
``` | ||
#### clearTime():Date | ||
@@ -151,5 +163,67 @@ Clears the time from the Date instance. | ||
#### diff( [date:Date, exclude:String] ):Object | ||
Returns an Object describing the difference between the Date instance and now — or the optionally passed Date. | ||
The Object will contain any or all of the following properties: | ||
<table border="0" cellpadding="0" cellspacing="0" width="100%"> | ||
<thead> | ||
<tr><th width="32">Prop</th><th width="48">Type</th><th>Description</th></tr> | ||
</thead> | ||
<tbody> | ||
<tr><td width="48"><code>tense</code></td><td width="48">Number</td><td>This will either be: | ||
<dl> | ||
<dt><code>-1</code></dt><dd>The Date instance is less than now or the passed Date, i.e. in the past</dd> | ||
<dt><code>0</code></dt><dd>The Date instance is euqal to now or the passed Date, i.e. in the present.<br /><strong>NOTE:</strong> If <code>tense</code> is <code>0</code> then the Object will most probably have no other properties.</dd> | ||
<dt><code>1</code></dt><dd>The Date instance is greater than now or the passed Date, i.e. in the future</dd> | ||
</dl> | ||
<strong>NOTE:</strong> All other properties Numbers will be positive Numbers as you will know if the <code>diff</code> is in the past, present or future by using this property. | ||
</td></tr> | ||
<tr><td width="48"><code>value</code></td><td width="48">Number</td><td>The — absolute — number of milliseconds difference between the two Dates.</td></tr> | ||
<tr><td width="48"><code>years</code></td><td width="48">Number</td><td>The number of years the Date instance is ahead or behind the passed Date.</td></tr> | ||
<tr><td width="48"><code>months</code></td><td width="48">Number</td><td>The months of years the Date instance is ahead or behind the passed Date.</td></tr> | ||
<tr><td width="48"><code>weeks</code></td><td width="48">Number</td><td>The weeks of years the Date instance is ahead or behind the passed Date.</td></tr> | ||
<tr><td width="48"><code>days</code></td><td width="48">Number</td><td>The days of years the Date instance is ahead or behind the passed Date.</td></tr> | ||
<tr><td width="48"><code>hours</code></td><td width="48">Number</td><td>The hours of years the Date instance is ahead or behind the passed Date.</td></tr> | ||
<tr><td width="48"><code>minutes</code></td><td width="48">Number</td><td>The minutes of years the Date instance is ahead or behind the passed Date.</td></tr> | ||
<tr><td width="48"><code>seconds</code></td><td width="48">Number</td><td>The seconds of years the Date instance is ahead or behind the passed Date.</td></tr> | ||
<tr><td width="48"><code>milliseconds</code></td><td width="48">Number</td><td>The milliseconds of years the Date instance is ahead or behind the passed Date.</td></tr> | ||
</tbody> | ||
</table> | ||
**NOTE:** If any of the properties — other than `tense` — is zero it will be removed from the `diff` Object. | ||
**NOTE:** You can supply a **space delimited** a String defining which properties you want to exclude from the result and `diff` will try and round off to the nearest time frame. | ||
##### Example: | ||
```javascript | ||
( new Date( 2012, 0, 1 ) ).diff( new Date( 2012, 0, 1 ) ) // returns => { tense : 0 } | ||
( new Date( 2012, 0, 1 ) ).diff( new Date( 2012, 0, 2 ) ) // returns => { tense : -1, days : 1 } | ||
( new Date( 2012, 0, 2 ) ).diff( new Date( 2012, 0, 1 ) ) // returns => { tense : 1, days : 1 } | ||
( new Date( 2012, 0, 1 ) ).diff( new Date( 2010, 9, 8, 7, 6, 5, 4 ) ) // returns => { tense : 1, years : 1, months : 9, weeks : 2, days : 1, hours : 17, minutes : 6, seconds : 54, ms : 4 } | ||
``` | ||
#### format( format:String ):String | ||
Returns a string representation of the Date instance, based on the passed format. See the **Date formatting and parsing options** below. | ||
Returns a string representation of the Date instance, based on the passed format. See the [Date formatting and parsing options](#date-formatting-and-parsing-options) below. | ||
##### Example: | ||
```javascript | ||
( new Date( 2012, 0, 1 ) ).format( 'c' ); // returns => "2012-01-01T00:00:00.000Z" | ||
// which is a short hand format for: | ||
( new Date( 2012, 0, 1 ) ).format( 'Y-m-d<T>H:i:s.u<Z>' ); // returns => "2012-01-01T00:00:00.000Z" | ||
( new Date( 2012, 0, 1 ) ).format( 'l, <the> nS <of> F Y' ) // returns => "Sunday, the 1st of January 2012" | ||
``` | ||
You can use predefined formats found in `Date.formats`. **Hint:** You can do: | ||
@@ -159,3 +233,3 @@ | ||
console.dir( Date.formats ); | ||
console.dir( Date.formats ); | ||
@@ -202,5 +276,5 @@ ``` | ||
( new Date( 2012, 0, 1 ) ).getWeek(); // returns => 0 | ||
( new Date( 2012, 2, 13 ) ).getWeek(); // returns => 10 | ||
( new Date( 2012, 11, 31 ) ).getWeek(); // returns => 52 | ||
( new Date( 2012, 0, 1 ) ).getWeek(); // returns => 0 | ||
( new Date( 2012, 2, 13 ) ).getWeek(); // returns => 10 | ||
( new Date( 2012, 11, 31 ) ).getWeek(); // returns => 52 | ||
@@ -222,6 +296,8 @@ ``` | ||
new Date( ( new Date( 2012, 0, 1 ) ).setWeek( 17 ) ); // returns => Date {Sun Apr 29 2012 00:00:00 GMT+0100 (BST)} | ||
( new Date( 2012, 2, 13 ) ).setWeek( 17 ); // returns => 1335654000000 same as above | ||
( new Date( 2012, 11, 31 ) ).setWeek( 17 ); // returns => 1335654000000 | ||
new Date( ( new Date( 2012, 0, 1 ) ).setWeek( 17 ) ); // returns => Date {Sun Apr 29 2012 00:00:00 GMT+0100 (BST)} | ||
( new Date( 2012, 2, 13 ) ).setWeek( 17 ); // returns => 1335654000000 same as above | ||
( new Date( 2012, 11, 31 ) ).setWeek( 17 ); // returns => 1335654000000 | ||
``` | ||
@@ -242,3 +318,3 @@ | ||
( new Date( 2012, 0, 1 ) ).format( 'l, <the> jS <of> F Y' ); // returns => "Sunday, the 1st of January 2012" | ||
( new Date( 2012, 0, 1 ) ).format( 'l, <the> jS <of> F Y' ); // returns => "Sunday, the 1st of January 2012" | ||
@@ -249,56 +325,61 @@ ``` | ||
<table border="0" cellpadding="0" cellspacing="0" width="100%"> | ||
<tr><td width="32">d</td><td>Day of the month, 2 digits with leading zeros</td> | ||
<tr><td width="32">D</td><td>A textual representation of a day, three letters</td> | ||
<tr><td width="32">j</td><td>Day of the month without leading zeros</td> | ||
<tr><td width="32">l</td><td>A full textual representation of the day of the week</td> | ||
<tr><td width="32">N</td><td>ISO-8601 numeric representation of the day of the week</td> | ||
<tr><td width="32">S</td><td>English ordinal suffix for the day of the month, 2 characters</td> | ||
<tr><td width="32">w</td><td>Numeric representation of the day of the week</td> | ||
<tr><td width="32">z</td><td>The day of the year (starting from 0)</td> | ||
<tr><td width="32">d</td><td>Day of the month, 2 digits with leading zeros</td></tr> | ||
<tr><td width="32">D</td><td>A textual representation of a day, three letters</td></tr> | ||
<tr><td width="32">j</td><td>Day of the month without leading zeros</td></tr> | ||
<tr><td width="32">l</td><td>A full textual representation of the day of the week</td></tr> | ||
<tr><td width="32">N</td><td>ISO-8601 numeric representation of the day of the week</td></tr> | ||
<tr><td width="32">S</td><td>English ordinal suffix for the day of the month, 2 characters</td></tr> | ||
<tr><td width="32">w</td><td>Numeric representation of the day of the week</td></tr> | ||
<tr><td width="32">z</td><td>The day of the year (starting from 0)</td></tr> | ||
</table> | ||
### week | ||
<table border="0" cellpadding="0" cellspacing="0" width="100%"> | ||
<tr><td width="32">W</td><td>ISO-8601 week number of year, weeks starting on Monday</td> | ||
<tr><td width="32">W</td><td>ISO-8601 week number of year, weeks starting on Monday</td></tr> | ||
</table> | ||
### month | ||
<table border="0" cellpadding="0" cellspacing="0" width="100%"> | ||
<tr><td width="32">F</td><td>A full textual representation of a month</td> | ||
<tr><td width="32">m</td><td>Numeric representation of a month, with leading zeros</td> | ||
<tr><td width="32">M</td><td>A short textual representation of a month, three letters</td> | ||
<tr><td width="32">n</td><td>Numeric representation of a month, without leading zeros</td> | ||
<tr><td width="32">t</td><td>Number of days in the given month</td> | ||
<tr><td width="32">F</td><td>A full textual representation of a month</td></tr> | ||
<tr><td width="32">m</td><td>Numeric representation of a month, with leading zeros</td></tr> | ||
<tr><td width="32">M</td><td>A short textual representation of a month, three letters</td></tr> | ||
<tr><td width="32">n</td><td>Numeric representation of a month, without leading zeros</td></tr> | ||
<tr><td width="32">t</td><td>Number of days in the given month</td></tr> | ||
</table> | ||
### year | ||
<table border="0" cellpadding="0" cellspacing="0" width="100%"> | ||
<tr><td width="32">L</td><td>Whether it's a leap year</td> | ||
<tr><td width="32">o</td><td>ISO-8601 year number. This has the same value as Y, except that if the ISO week number (W) belongs to the previous or next year, that year is used instead.</td> | ||
<tr><td width="32">Y</td><td>A full numeric representation of a year, 4 digits</td> | ||
<tr><td width="32">y</td><td>A two digit representation of a year</td> | ||
<tr><td width="32">L</td><td>Whether it's a leap year</td></tr> | ||
<tr><td width="32">o</td><td>ISO-8601 year number. This has the same value as Y, except that if the ISO week number (W) belongs to the previous or next year, that year is used instead.</td></tr> | ||
<tr><td width="32">Y</td><td>A full numeric representation of a year, 4 digits</td></tr> | ||
<tr><td width="32">y</td><td>A two digit representation of a year</td></tr> | ||
</table> | ||
### time | ||
<table border="0" cellpadding="0" cellspacing="0" width="100%"> | ||
<tr><td width="32">a</td><td>Lowercase Ante meridiem and Post meridiem</td> | ||
<tr><td width="32">A</td><td>Uppercase Ante meridiem and Post meridiem</td> | ||
<tr><td width="32">g</td><td>12-hour format of an hour without leading zeros</td> | ||
<tr><td width="32">G</td><td>24-hour format of an hour without leading zeros</td> | ||
<tr><td width="32">h</td><td>12-hour format of an hour with leading zeros</td> | ||
<tr><td width="32">H</td><td>24-hour format of an hour with leading zeros</td> | ||
<tr><td width="32">i</td><td>Minutes with leading zeros</td> | ||
<tr><td width="32">s</td><td>Seconds, with leading zeros</td> | ||
<tr><td width="32">u</td><td>Milliseconds</td> | ||
<tr><td width="32">a</td><td>Lowercase Ante meridiem and Post meridiem</td></tr> | ||
<tr><td width="32">A</td><td>Uppercase Ante meridiem and Post meridiem</td></tr> | ||
<tr><td width="32">g</td><td>12-hour format of an hour without leading zeros</td></tr> | ||
<tr><td width="32">G</td><td>24-hour format of an hour without leading zeros</td></tr> | ||
<tr><td width="32">h</td><td>12-hour format of an hour with leading zeros</td></tr> | ||
<tr><td width="32">H</td><td>24-hour format of an hour with leading zeros</td></tr> | ||
<tr><td width="32">i</td><td>Minutes with leading zeros</td></tr> | ||
<tr><td width="32">s</td><td>Seconds, with leading zeros</td></tr> | ||
<tr><td width="32">u</td><td>Milliseconds</td></tr> | ||
</table> | ||
### timezone | ||
<table border="0" cellpadding="0" cellspacing="0" width="100%"> | ||
<tr><td width="32">O</td><td>Difference to Greenwich time (GMT) in hours</td> | ||
<tr><td width="32">P</td><td>Difference to Greenwich time (GMT) with colon between hours and minutes</td> | ||
<tr><td width="32">T</td><td>Timezone abbreviation</td> | ||
<tr><td width="32">Z</td><td>Timezone offset in seconds. The offset for timezones west of UTC is always negative, and for those east of UTC is always positive.</td> | ||
<tr><td width="32">O</td><td>Difference to Greenwich time (GMT) in hours</td></tr> | ||
<tr><td width="32">P</td><td>Difference to Greenwich time (GMT) with colon between hours and minutes</td></tr> | ||
<tr><td width="32">T</td><td>Timezone abbreviation</td></tr> | ||
<tr><td width="32">Z</td><td>Timezone offset in seconds. The offset for timezones west of UTC is always negative, and for those east of UTC is always positive.</td></tr> | ||
</table> | ||
### full date/time | ||
<table border="0" cellpadding="0" cellspacing="0" width="100%"> | ||
<tr><td width="32">c</td><td>ISO 8601 date</td> | ||
<tr><td width="32">r</td><td>RFC 2822 formatted date</td> | ||
<tr><td width="32">U</td><td>Seconds since the Unix Epoch January 1 1970 00:00:00 GMT</td> | ||
<tr><td width="32">c</td><td>ISO 8601 date</td></tr> | ||
<tr><td width="32">r</td><td>RFC 2822 formatted date</td></tr> | ||
<tr><td width="32">U</td><td>Seconds since the Unix Epoch January 1 1970 00:00:00 GMT</td></tr> | ||
</table> | ||
## File size | ||
- d8.js ≅ 6.8kb (gzipped) | ||
- d8.min.js ≅ 3.9kb (minzipped) | ||
## License | ||
@@ -305,0 +386,0 @@ |
// instance methods | ||
util.defs( Type.prototype, { | ||
adjust : adjust, between : between, clearTime : clearTime, | ||
clone : clone, format : format, getDayOfYear : getDayOfYear, | ||
getFirstOfTheMonth : getFirstOfTheMonth, getGMTOffset : getGMTOffset, getISODay : getISODay, | ||
getISODaysInYear : getISODaysInYear, getISOFirstMondayOfYear : getISOFirstMondayOfYear, getISOWeek : getISOWeek, | ||
getISOWeeksInYear : getISOWeeksInYear, getLastOfTheMonth : getLastOfTheMonth, getWeek : getWeek, | ||
isDST : isDST, isLeapYear : isLeapYear, setWeek : setWeek, | ||
timezone : timezone | ||
adjust : adjust, between : between, clearTime : clearTime, | ||
clone : clone, diff : diff, format : format, | ||
getDayOfYear : getDayOfYear, getFirstOfTheMonth : getFirstOfTheMonth, getGMTOffset : getGMTOffset, | ||
getISODay : getISODay, getISODaysInYear : getISODaysInYear, getISOFirstMondayOfYear : getISOFirstMondayOfYear, | ||
getISOWeek : getISOWeek, getISOWeeksInYear : getISOWeeksInYear, getLastOfTheMonth : getLastOfTheMonth, | ||
getWeek : getWeek, isDST : isDST, isLeapYear : isLeapYear, | ||
setWeek : setWeek, timezone : timezone | ||
}, 'r' ); | ||
@@ -17,3 +17,3 @@ | ||
// constants defining milliseconds for different times | ||
MS_DAY : MS_DAY, MS_WEEK : MS_WEEK, MS_MONTH : 2592e6, MS_YEAR : 31536e6, | ||
MS_DAY : MS_DAY, MS_HOUR : MS_HOUR, MS_MINUTE : MS_MINUTE, MS_MONTH : MS_MONTH, MS_SECOND : MS_SECOND, MS_WEEK : MS_WEEK, MS_YEAR : MS_YEAR, | ||
// filters and formats | ||
@@ -20,0 +20,0 @@ filters : { value : filter }, formats : { value : formats }, parsers : { value : parser }, |
// private methods | ||
function _24hrTime( o, res ) { return ( o = Number( o ) ) < 12 && _lc( res.ampm ) == _lc( LOCALE.PM ) ? o += 12 : o; } | ||
function _adjust( d, v, k ) { return d.adjust( k, v ); } | ||
function _adjust_toobj( a ) { | ||
return adjust_order.reduce( function( v, k, i ) { | ||
var delta = parseFloat( a[i] ); | ||
if ( !isNaN( delta ) && delta !== 0 ) | ||
v[k] = delta; | ||
return v; | ||
}, util.obj() ); | ||
} | ||
function _dayOffset( d ) { return Math.floor( ( d - getISOFirstMondayOfYear.call( d ) ) / MS_DAY ); } | ||
@@ -17,17 +27,25 @@ function _timezoneOffset( o ) { | ||
function adjust( o, v ) { | ||
if ( util.nativeType( o ) == 'object' ) { | ||
Object.reduce( o, _adjust, this ); | ||
return this; | ||
var date = this, day, fn, weekday; // noinspection FallthroughInSwitchStatementJS | ||
switch ( util.ntype( o ) ) { | ||
case 'number' : o = _adjust_toobj( arguments ); // allow fall-through | ||
case 'object' : Object.reduce( o, _adjust, date ); break; | ||
case 'string' : | ||
fn = adjust_by[o.toLowerCase()]; | ||
if ( fn && v !== 0 ) { | ||
LOCALE.setLeapYear( date ); | ||
if ( fn == adjust_by.month ) { | ||
day = date.getDate(); | ||
day < 28 || date.setDate( Math.min( day, getLastOfTheMonth.call( getFirstOfTheMonth.call( date ).adjust( Type.MONTH, v ) ).getDate() ) ); | ||
} | ||
fn != adjust_by.week || ( weekday = date.getDay() ); | ||
date[fn[1]]( date[fn[0]]() + v ); | ||
!weekday || date.setDate( date.getDate() + weekday ); | ||
} | ||
} | ||
var day, fn = adjust_by[o.toLowerCase()], weekday; | ||
if ( !fn || v === 0 ) return this; | ||
LOCALE.setLeapYear( this ); | ||
if ( fn == adjust_by.month ) { | ||
day = this.getDate(); | ||
day < 28 || this.setDate( Math.min( day, getLastOfTheMonth.call( getFirstOfTheMonth.call( this ).adjust( Type.MONTH, v ) ) ).getDate() ); | ||
} | ||
fn != adjust_by.week || ( weekday = this.getDay() ); | ||
this[fn[1]]( this[fn[0]]() + v ); | ||
!weekday || this.setDate( this.getDate() + weekday ); | ||
return this; | ||
return date; | ||
} | ||
@@ -34,0 +52,0 @@ |
@@ -1,17 +0,19 @@ | ||
function buildTemplate( o ) { | ||
if ( cache_format[o] ) return cache_format[o]; | ||
function buildTemplate( date_format ) { | ||
if ( cache_format[date_format] ) return cache_format[date_format]; | ||
var fn = ['var out=[];'], i = -1, p, parts = o.replace( re_add_nr, NOREPLACE_RB ).replace( re_add_enr, NOREPLACE_RE ).split( re_split ), re_invalid = /^[^A-Za-z]*$/g, l = parts.length; | ||
var fn = ['var out=[];'], i = -1, part, | ||
parts = date_format.replace( re_add_nr, NOREPLACE_RB ).replace( re_add_enr, NOREPLACE_RE ).split( re_split ), | ||
re_invalid = /^[^A-Za-z]*$/g, l = parts.length; | ||
while( ++i < l ) { | ||
p = parts[i]; | ||
p == NOREPLACE ? ( fn.push( tplOut( parts[++i] ) ), ++i ) | ||
: re_invalid.test( p ) | ||
? fn.push( tplOut( p ) ) | ||
: fn.push( compileTplStr( p ) ); | ||
part = parts[i]; | ||
part == NOREPLACE ? ( fn.push( tplOut( parts[++i] ) ), ++i ) | ||
: re_invalid.test( part ) | ||
? fn.push( tplOut( part ) ) | ||
: fn.push( compileTplStr( part ) ); | ||
} | ||
fn.push( 'return out.join( "" );' ); | ||
fn.push( 'return out.join( "" );\n//@ sourceURL=d8/format/' + date_format ); | ||
return cache_format[o] = new Function( 'filter', 'date', fn.join( '\n' ) ); | ||
return cache_format[date_format] = new Function( 'filter', 'date', fn.join( '\n' ) ); | ||
} | ||
@@ -18,0 +20,0 @@ |
@@ -1,12 +0,14 @@ | ||
function buildParser( o ) { | ||
if ( cache_parse[o] ) return cache_parse[o]; | ||
var fn = {}, keys = [], i = -1, parts = o.replace( re_add_nr, NOREPLACE_RB ).replace( re_add_enr, NOREPLACE_RE ).split( re_split ), | ||
l = parts.length, p, re = []; | ||
function buildParser( date_format ) { | ||
if ( cache_parse[date_format] ) return cache_parse[date_format]; | ||
var parsers = {}, keys = [], i = -1, part, | ||
parts = date_format.replace( re_add_nr, NOREPLACE_RB ).replace( re_add_enr, NOREPLACE_RE ).split( re_split ), | ||
l = parts.length, re = []; | ||
while ( ++i < l ) { | ||
p = parts[i]; | ||
if ( p == NOREPLACE ) { | ||
re.push( parts[++i] ); ++i; continue; | ||
part = parts[i]; | ||
if ( part == NOREPLACE ) { | ||
re.push( parts[++i] ); ++i; | ||
continue; | ||
} | ||
p.replace( re_compile, function( m, p1, p2, p3 ) { | ||
part.replace( re_compile, function( m, p1, p2, p3 ) { | ||
var _fn, _k, _p; | ||
@@ -16,3 +18,3 @@ if ( !( _p = parser[p2] ) ) return; | ||
keys.push( _p.k ); | ||
if ( _p.fn ) fn[_p.k] = _p.fn; | ||
if ( _p.fn ) parsers[_p.k] = _p.fn; | ||
} | ||
@@ -23,3 +25,3 @@ if ( _p.combo ) { | ||
keys.push.apply( keys, _k ); | ||
util.copy( fn, _fn, true ); | ||
util.copy( parsers, _fn, true ); | ||
} | ||
@@ -29,45 +31,53 @@ if ( _p.re ) re.push( p1, _p.re, p3 ); | ||
} | ||
return cache_parse[o] = parse.bind( null, new RegExp( re.join( '' ) ), keys, fn ); | ||
return cache_parse[date_format] = parse.bind( null, new RegExp( re.join( '' ) ), keys, parsers ); | ||
} | ||
function parse( re, keys, fn, s ) { | ||
var d = new Type(), m = s.match( re ), o = associate( m.slice( 1 ), keys ); | ||
var date = new Type(), parts = s.match( re ), | ||
parsers = associate( parts.slice( 1 ), keys ); | ||
Object.reduce( o, function( n, v, k ) { if ( fn[k] ) o[k] = fn[k]( v, o ); return n; }, null ); | ||
Object.reduce( parsers, function( n, v, k ) { | ||
if ( typeof v == 'string' && fn[k] ) | ||
parsers[k] = fn[k]( v, parsers ); | ||
return n; | ||
}, null ); | ||
if ( !isNaN( o[UNIX] ) ) d.setTime( o[UNIX] ); | ||
if ( !isNaN( parsers[UNIX] ) ) date.setTime( parsers[UNIX] ); | ||
else { | ||
parse_setTime( d, o[HOUR], o[MINUTE], o[SECOND], o[MILLISECOND] ); | ||
parse_setDate( d, o ); | ||
parse_setTimezoneOffset( d, o[TIMEZONE] ); | ||
parse_setTime( date, parsers[HOUR], parsers[MINUTE], parsers[SECOND], parsers[MILLISECOND] ); | ||
parse_setDate( date, parsers ); | ||
parse_setTimezoneOffset( date, parsers[TIMEZONE] ); | ||
} | ||
return d; | ||
return date; | ||
} | ||
function parse_setDate( d, o ) { | ||
var dw, l, ly, odc, i = -1; | ||
function parse_setDate( date, parsers ) { | ||
var dayweek, i = -1, l, leapyr, ordinal; | ||
if ( date_members.every( util.has.bind( null, o ) ) ) return; // only set the date if there's one to set (i.e. the format is not just for time) | ||
if ( date_members.every( util.has.bind( null, parsers ) ) ) return; // only set the date if there's one to set (i.e. the format is not just for time) | ||
if ( isNaN( o[YEAR] ) ) o[YEAR] = d.getFullYear(); | ||
if ( isNaN( parsers[YEAR] ) ) parsers[YEAR] = date.getFullYear(); | ||
if ( isNaN( o[MONTH] ) ) { | ||
ly = LOCALE.isLeapYear( o[YEAR] ) ? 1 : 0; odc = LOCALE.ordinal_day_count[ly]; l = odc.length; o[MONTH] = 0; | ||
if ( isNaN( parsers[MONTH] ) ) { | ||
leapyr = LOCALE.isLeapYear( parsers[YEAR] ) ? 1 : 0; | ||
ordinal = LOCALE.ordinal_day_count[leapyr]; | ||
l = ordinal.length; | ||
parsers[MONTH] = 0; | ||
if ( o[WEEK] && !o[DAYYEAR] ) { // give precedence to the day of the year | ||
dw = o[DAYWEEK]; | ||
dw = isNaN( dw ) ? 0 : !dw ? 7 : dw; | ||
o[DAYYEAR] = ( o[WEEK] * 7 ) - ( 4 - dw ); | ||
if ( parsers[WEEK] && !parsers[DAYYEAR] ) { // give precedence to the day of the year | ||
dayweek = parsers[DAYWEEK]; | ||
dayweek = isNaN( dayweek ) ? 0 : !dayweek ? 7 : dayweek; | ||
parsers[DAYYEAR] = ( parsers[WEEK] * 7 ) - ( 4 - dayweek ); | ||
} | ||
if ( !isNaN( o[DAYYEAR] ) ) { | ||
if ( o[DAYYEAR] > odc[odc.length - 1] ) { | ||
o[DAYYEAR] -= odc[odc.length - 1]; | ||
++o[YEAR]; | ||
if ( !isNaN( parsers[DAYYEAR] ) ) { | ||
if ( parsers[DAYYEAR] > ordinal[ordinal.length - 1] ) { | ||
parsers[DAYYEAR] -= ordinal[ordinal.length - 1]; | ||
++parsers[YEAR]; | ||
} | ||
while( ++i < l ) { | ||
if ( between_equalto( o[DAYYEAR], odc[i], odc[i+1] ) ) { | ||
o[MONTH] = i; | ||
o[DAY] = odc[i] == 0 ? o[DAYYEAR] : ( o[DAYYEAR] - odc[i] ); | ||
if ( between_equalto( parsers[DAYYEAR], ordinal[i], ordinal[i+1] ) ) { | ||
parsers[MONTH] = i; | ||
parsers[DAY] = ordinal[i] == 0 ? parsers[DAYYEAR] : ( parsers[DAYYEAR] - ordinal[i] ); | ||
break; | ||
@@ -79,15 +89,17 @@ } | ||
if ( isNaN( o[DAY] ) ) o[DAY] = 1; | ||
if ( isNaN( parsers[DAY] ) ) parsers[DAY] = 1; | ||
d.setYear( o[YEAR] ); d.setMonth( o[MONTH] ); d.setDate( o[DAY] ); | ||
date.setYear( parsers[YEAR] ); date.setMonth( parsers[MONTH] ); date.setDate( parsers[DAY] ); | ||
} | ||
function parse_setTime( d, h, m, s, ms ) { | ||
d.setHours( h || 0 ); d.setMinutes( m || 0 ); | ||
d.setSeconds( s || 0 ); d.setMilliseconds( ms || 0 ); | ||
function parse_setTime( date, hr, min, sec, ms ) { | ||
date.setHours( hr || 0 ); date.setMinutes( min || 0 ); | ||
date.setSeconds( sec || 0 ); date.setMilliseconds( ms || 0 ); | ||
} | ||
function parse_setTimezoneOffset( d, tzo ) { | ||
!between_equalto( tzo, -43200, 50400 ) || d.adjust( Type.SECOND, ( -d.getTimezoneOffset() * 60 ) - tzo ); | ||
function parse_setTimezoneOffset( date, tzoffset ) { | ||
!between_equalto( tzoffset, -43200, 50400 ) || date.adjust( Type.SECOND, ( -date.getTimezoneOffset() * 60 ) - tzoffset ); | ||
} | ||
function toDate( s, f ) { return buildParser( f )( s ); } | ||
function toDate( date_str, date_format ) { | ||
return buildParser( date_format )( date_str ); | ||
} |
var LOCALE = Type.locale, U, | ||
// DAY_OFFSETS is the amount of days from the current day to the Monday of the week it belongs to | ||
DAY_OFFSETS = [9, 1, 0, -1, -2, 4, 3], MS_DAY = 864e5, MS_WEEK = 6048e5, | ||
DAY_OFFSETS = [9, 1, 0, -1, -2, 4, 3], MS_DAY = 864e5, MS_HOUR = 3600000, MS_MINUTE = 60000, | ||
MS_MONTH = 2592e6, MS_SECOND = 1000, MS_WEEK = 6048e5, MS_YEAR = 31536e6, | ||
SHORT_DAYS = LOCALE.days.map( _substr ), SHORT_MONTHS = LOCALE.months.map( _substr ), | ||
@@ -9,6 +10,18 @@ // parser keys | ||
// used by Date.prototype.format && Date.toDate to replace escaped chars | ||
NOREPLACE = 'NOREPLACE', NOREPLACE_RB = '<' + NOREPLACE + '<', NOREPLACE_RE = '>END' + NOREPLACE + '>', | ||
adjust_by = { day : ['getDate', 'setDate'], hr : ['getHours', 'setHours'], min : ['getMinutes', 'setMinutes'], month : ['getMonth', 'setMonth'], ms : ['getMilliseconds', 'setMilliseconds'], sec : ['getSeconds', 'setSeconds'], week : ['getWeek', 'setWeek'], year : ['getFullYear', 'setFullYear'] }, | ||
NOREPLACE = 'NOREPLACE', NOREPLACE_RB = '<' + NOREPLACE + '<', NOREPLACE_RE = '>END' + NOREPLACE + '>', | ||
adjust_by = { day : ['getDate', 'setDate'], hr : ['getHours', 'setHours'], min : ['getMinutes', 'setMinutes'], month : ['getMonth', 'setMonth'], ms : ['getMilliseconds', 'setMilliseconds'], sec : ['getSeconds', 'setSeconds'], week : ['getWeek', 'setWeek'], year : ['getFullYear', 'setFullYear'] }, | ||
adjust_order = [YEAR, MONTH, WEEK, DAY, 'hr', MINUTE.substring( 0, 3 ), SECOND.substring( 0, 3 ), MILLISECOND], | ||
// cache objects | ||
cache_format = {}, cache_parse = {}, date_members = [DAY, DAYWEEK, DAYYEAR, MONTH, WEEK, YEAR], | ||
diff_calc = [ // the order of this Array is important as it is the remainder of the larger | ||
[YEAR + 's', MS_YEAR], // time unit that gets passed to the following time unit — as such we want | ||
[MONTH + 's', MS_MONTH], // to keep the order in case we want to exclude time units from the diff | ||
[WEEK + 's', MS_WEEK], | ||
[DAY + 's', MS_DAY], | ||
[HOUR + 's', MS_HOUR], | ||
[MINUTE + 's', MS_MINUTE], | ||
[SECOND + 's', MS_SECOND], | ||
[MILLISECOND, 1] | ||
], | ||
diff_props = diff_calc.map( function( calc ) { return calc[0]; } ), | ||
filter = { | ||
@@ -33,3 +46,3 @@ // day | ||
// year | ||
L : function( d ) { return ( d.isLeapYear() ) ? 1 : 0; }, // Whether it's a leap year | ||
L : function( d ) { return d.isLeapYear() ? 1 : 0; }, // Whether it's a leap year | ||
o : function( d ) { // ISO-8601 year number. This has the same value as Y, except that if the ISO | ||
@@ -119,4 +132,4 @@ var m = d.getMonth(), w = getISOWeek.call( d ); // week number (W) belongs to the previous or next year, that year is used instead. | ||
parser.c = { | ||
combo : [parser.Y, parser.m, parser.d, parser.H, parser.i, parser.s, parser.P], | ||
re : [parser.Y.re, '-', parser.m.re, '-', parser.d.re, 'T', parser.H.re, ':', parser.i.re, ':', parser.s.re, parser.P.re].join( '' ) | ||
combo : [parser.Y, parser.m, parser.d, parser.H, parser.i, parser.s, parser.u, parser.P], | ||
re : [parser.Y.re, '-', parser.m.re, '-', parser.d.re, 'T', parser.H.re, ':', parser.i.re, ':', parser.s.re, '(?:\\.', parser.u.re, '){0,1}', parser.P.re, '{0,1}'].join( '' ) | ||
}; | ||
@@ -123,0 +136,0 @@ parser.r = { |
@@ -108,2 +108,7 @@ typeof m8 !== 'undefined' || ( m8 = require( 'm8' ) ); | ||
expect( Date.toDate( '2010-08-30T10:10:10-08:00', 'c' ) ).to.eql( new Date( 2010, 7, 30, 18 + offset, 10, 10 ) ); | ||
expect( Date.toDate( '2010-08-30T10:10:10.010+00:00Z', 'Y-m-d<T>H:i:s.uP<Z>' ) ).to.eql( new Date( 2010, 7, 30, ( 10 + offset ), 10, 10, 10 ) ); | ||
expect( Date.toDate( '2010-08-30T10:10:10.010+00:00Z', 'c' ) ).to.eql( new Date( 2010, 7, 30, 10 + offset, 10, 10, 10 ) ); | ||
expect( Date.toDate( '2010-08-30T10:10:10.010+04:00Z', 'c' ) ).to.eql( new Date( 2010, 7, 30, 6 + offset, 10, 10, 10 ) ); | ||
expect( Date.toDate( '2010-08-30T10:10:10.010-08:00Z', 'c' ) ).to.eql( new Date( 2010, 7, 30, 18 + offset, 10, 10, 10 ) ); | ||
@@ -132,3 +137,6 @@ done(); | ||
expect( r.adjust( { day : -1, hr : -1, min : -1, month : -1, ms : -1, sec : -1, year : -1 } ) ).to.eql( new Date( 2010, 0, 1 ) ); | ||
expect( new Date( 2012, 1, 29 ).adjust( Date.MONTH, 1 ) ).to.eql( new Date( 2012, 2, 29 ) ); | ||
expect( new Date( 2012, 1, 29 ).adjust( Date.MONTH, -1 ) ).to.eql( new Date( 2012, 0, 29 ) ); | ||
done(); | ||
@@ -169,2 +177,120 @@ } ); | ||
test( 'Date.prototype.diff with no exclusions', function( done ) { | ||
var date_1, date_2, diff, now = Date.now(); | ||
expect( new Date( now ).diff( new Date( now ) ) ).to.eql( { tense : 0 } ); | ||
expect( new Date( now ).diff( new Date( now ).adjust( Date.YEAR, 1 ) ) ).to.eql( { tense : -1, value : Date.MS_YEAR, years : 1 } ); | ||
expect( new Date( 2012, 0, 1 ).diff( new Date( 2011, 0, 1 ) ) ).to.eql( { tense : 1, value : Date.MS_YEAR, years : 1 } ); | ||
expect( new Date( now ).diff( new Date( now ).adjust( Date.MONTH, 1 ) ) ).to.eql( { tense : -1, value : Date.MS_MONTH, months : 1 } ); | ||
expect( new Date( 2012, 9, 1 ).diff( new Date( 2012, 8, 1 ) ) ).to.eql( { tense : 1, value : Date.MS_MONTH, months : 1 } ); | ||
expect( new Date( now ).diff( new Date( now ).adjust( Date.WEEK, 1 ) ) ).to.eql( { tense : -1, value : Date.MS_WEEK, weeks : 1 } ); | ||
expect( new Date( 2012, 0, 8 ).diff( new Date( 2012, 0, 1 ) ) ).to.eql( { tense : 1, value : Date.MS_WEEK, weeks : 1 } ); | ||
expect( new Date( now ).diff( new Date( now ).adjust( Date.DAY, 1 ) ) ).to.eql( { tense : -1, value : Date.MS_DAY, days : 1 } ); | ||
expect( new Date( 2012, 0, 2 ).diff( new Date( 2012, 0, 1 ) ) ).to.eql( { tense : 1, value : Date.MS_DAY, days : 1 } ); | ||
expect( new Date( now ).diff( new Date( now ).adjust( Date.HOUR, 1 ) ) ).to.eql( { tense : -1, value : Date.MS_HOUR, hours : 1 } ); | ||
expect( new Date( 2012, 0, 1, 1 ).diff( new Date( 2012, 0, 1 ) ) ).to.eql( { tense : 1, value : Date.MS_HOUR, hours : 1 } ); | ||
expect( new Date( now ).diff( new Date( now ).adjust( Date.MINUTE, 1 ) ) ).to.eql( { tense : -1, value : Date.MS_MINUTE, minutes : 1 } ); | ||
expect( new Date( 2012, 0, 1, 0, 1 ).diff( new Date( 2012, 0, 1 ) ) ).to.eql( { tense : 1, value : Date.MS_MINUTE, minutes : 1 } ); | ||
expect( new Date( now ).diff( new Date( now ).adjust( Date.SECOND, 1 ) ) ).to.eql( { tense : -1, value : Date.MS_SECOND, seconds : 1 } ); | ||
expect( new Date( 2012, 0, 1, 0, 0, 1 ).diff( new Date( 2012, 0, 1 ) ) ).to.eql( { tense : 1, value : Date.MS_SECOND, seconds : 1 } ); | ||
expect( new Date( now ).diff( new Date( now ).adjust( Date.MILLISECOND, 100 ) ) ).to.eql( { tense : -1, value : 100, ms : 100 } ); | ||
expect( new Date( 2012, 0, 1, 0, 0, 0, 100 ).diff( new Date( 2012, 0, 1 ) ) ).to.eql( { tense : 1, value : 100, ms : 100 } ); | ||
date_1 = new Date( 2012, 11, 10, 9, 8, 7, 600 ); | ||
date_2 = date_1.clone().adjust( { year : 1, month : 1, week : 1, day : 1, hr : 1, min : 1, sec : 1, ms : 100 } ); | ||
diff = date_1.diff( date_2 ); | ||
expect( diff.value ).to.eql( Math.abs( +date_1 - +date_2 ) ); | ||
expect( diff.tense ).to.eql( -1 ); | ||
expect( diff.years ).to.eql( 1 ); | ||
expect( diff.months ).to.eql( 1 ); | ||
expect( diff.weeks ).to.eql( 1 ); | ||
expect( diff.days ).to.eql( 5 ); | ||
expect( diff.hours ).to.eql( 1 ); | ||
expect( diff.minutes ).to.eql( 1 ); | ||
expect( diff.seconds ).to.eql( 1 ); | ||
expect( diff.ms ).to.eql( 99 ); | ||
diff = date_2.diff( date_1 ); | ||
expect( diff.tense ).to.eql( 1 ); | ||
expect( diff.years ).to.eql( 1 ); | ||
expect( diff.months ).to.eql( 1 ); | ||
expect( diff.weeks ).to.eql( 1 ); | ||
expect( diff.days ).to.eql( 5 ); | ||
expect( diff.hours ).to.eql( 1 ); | ||
expect( diff.minutes ).to.eql( 1 ); | ||
expect( diff.seconds ).to.eql( 1 ); | ||
expect( diff.ms ).to.eql( 99 ); | ||
done(); | ||
} ); | ||
test( 'Date.prototype.diff with exclusions', function( done ) { | ||
var date_1, date_2, diff, now = Date.now(); | ||
date_1 = new Date( 2012, 11, 10, 9, 8, 7, 600 ); | ||
date_2 = date_1.clone().adjust( { year : 1, month : 1, week : 1, day : 1, hr : 1, min : 1, sec : 1, ms : 100 } ); | ||
diff = date_1.diff( date_2, '-weeks >hours' ); | ||
expect( diff.value ).to.eql( Math.abs( +date_1 - +date_2 ) ); | ||
expect( diff.tense ).to.eql( -1 ); | ||
expect( diff.years ).to.eql( 1 ); | ||
expect( diff.months ).to.eql( 1 ); | ||
expect( diff.weeks ).to.be.undefined; | ||
expect( diff.days ).to.eql( 12 ); | ||
expect( diff.hours ).to.be.undefined; | ||
expect( diff.minutes ).to.be.undefined; | ||
expect( diff.seconds ).to.be.undefined; | ||
expect( diff.ms ).to.be.undefined; | ||
diff = date_2.diff( date_1, '-weeks >minutes' ); | ||
expect( diff.tense ).to.eql( 1 ); | ||
expect( diff.years ).to.eql( 1 ); | ||
expect( diff.months ).to.eql( 1 ); | ||
expect( diff.weeks ).to.be.undefined; | ||
expect( diff.days ).to.eql( 12 ); | ||
expect( diff.hours ).to.eql( 1 ); | ||
expect( diff.minutes ).to.be.undefined; | ||
expect( diff.seconds ).to.be.undefined; | ||
expect( diff.ms ).to.be.undefined; | ||
date_1 = new Date( 2012, 11, 10, 9, 8, 7, 600 ); | ||
date_2 = date_1.clone().adjust( 0, 11 ); | ||
diff = date_1.diff( date_2, '>months' ); | ||
expect( diff.value ).to.eql( Math.abs( +date_2 - +date_1 ) ); | ||
expect( diff.tense ).to.eql( -1 ); | ||
expect( diff.years ).to.eql( 1 ); | ||
diff = date_1.diff( date_2, '-years -months -weeks' ); | ||
expect( diff.tense ).to.eql( -1 ); | ||
expect( diff.days ).to.eql( 370 ); | ||
date_1 = new Date( 2012, 11, 10, 9, 8, 7, 600 ); | ||
date_2 = date_1.clone().adjust( 1, 11, 1, 1, 1, 1, 1, 10 ); | ||
diff = date_1.diff( date_2, '>months' ); | ||
expect( diff.value ).to.eql( Math.abs( +date_2 - +date_1 ) ); | ||
expect( diff.tense ).to.eql( -1 ); | ||
expect( diff.years ).to.eql( 2 ); | ||
diff = date_1.diff( date_2, '-years -months -weeks' ); | ||
expect( diff.tense ).to.eql( -1 ); | ||
expect( diff.days ).to.eql( 744 ); | ||
expect( diff.hours ).to.eql( 1 ); | ||
expect( diff.minutes ).to.eql( 1 ); | ||
expect( diff.seconds ).to.eql( 1 ); | ||
expect( diff.ms ).to.eql( 9 ); | ||
done(); | ||
} ); | ||
test( 'Date.prototype.format: takes a format String and returns a Date String representation of the Date instance', function( done ) { | ||
@@ -171,0 +297,0 @@ function format( s ) { return '{ ' + s.split( ' ' ).map( map ).join( ', ' ) + ' }'; } |
Sorry, the diff of this file is not supported yet
109416
22
1347
384
Updatedm8@>= 0.3.1