//! moment.js //! version : 2.8.4 //! authors : tim wood, iskren chernev, moment.js contributors //! license : mit //! momentjs.com (function (undefined) { /************************************ constants ************************************/ var moment, version = '2.8.4', // the global-scope this is not the global object in node.js globalscope = typeof global !== 'undefined' ? global : this, oldglobalmoment, round = math.round, hasownproperty = object.prototype.hasownproperty, i, year = 0, month = 1, date = 2, hour = 3, minute = 4, second = 5, millisecond = 6, // internal storage for locale config files locales = {}, // extra moment internal properties (plugins register props here) momentproperties = [], // check for nodejs hasmodule = (typeof module !== 'undefined' && module && module.exports), // asp.net json date format regex aspnetjsonregex = /^\/?date\((\-?\d+)/i, aspnettimespanjsonregex = /(\-)?(?:(\d*)\.)?(\d+)\:(\d+)(?:\:(\d+)\.?(\d{3})?)?/, // from http://docs.closure-library.googlecode.com/git/closure_goog_date_date.js.source.html // somewhat more in line with 4.4.3.2 2004 spec, but allows decimal anywhere isodurationregex = /^(-)?p(?:(?:([0-9,.]*)y)?(?:([0-9,.]*)m)?(?:([0-9,.]*)d)?(?:t(?:([0-9,.]*)h)?(?:([0-9,.]*)m)?(?:([0-9,.]*)s)?)?|([0-9,.]*)w)$/, // format tokens formattingtokens = /(\[[^\[]*\])|(\\)?(mo|mm?m?m?|do|dddo|dd?d?d?|ddd?d?|do?|w[o|w]?|w[o|w]?|q|yyyyyy|yyyyy|yyyy|yy|gg(ggg?)?|gg(ggg?)?|e|e|a|a|hh?|hh?|mm?|ss?|s{1,4}|x|x|zz?|zz?|.)/g, localformattingtokens = /(\[[^\[]*\])|(\\)?(lts|lt|ll?l?l?|l{1,4})/g, // parsing token regexes parsetokenoneortwodigits = /\d\d?/, // 0 - 99 parsetokenonetothreedigits = /\d{1,3}/, // 0 - 999 parsetokenonetofourdigits = /\d{1,4}/, // 0 - 9999 parsetokenonetosixdigits = /[+\-]?\d{1,6}/, // -999,999 - 999,999 parsetokendigits = /\d+/, // nonzero number of digits parsetokenword = /[0-9]*['a-z\u00a0-\u05ff\u0700-\ud7ff\uf900-\ufdcf\ufdf0-\uffef]+|[\u0600-\u06ff\/]+(\s*?[\u0600-\u06ff]+){1,2}/i, // any word (or two) characters or numbers including two/three word month in arabic. parsetokentimezone = /z|[\+\-]\d\d:?\d\d/gi, // +00:00 -00:00 +0000 -0000 or z parsetokent = /t/i, // t (iso separator) parsetokenoffsetms = /[\+\-]?\d+/, // 1234567890123 parsetokentimestampms = /[\+\-]?\d+(\.\d{1,3})?/, // 123456789 123456789.123 //strict parsing regexes parsetokenonedigit = /\d/, // 0 - 9 parsetokentwodigits = /\d\d/, // 00 - 99 parsetokenthreedigits = /\d{3}/, // 000 - 999 parsetokenfourdigits = /\d{4}/, // 0000 - 9999 parsetokensixdigits = /[+-]?\d{6}/, // -999,999 - 999,999 parsetokensignednumber = /[+-]?\d+/, // -inf - inf // iso 8601 regex // 0000-00-00 0000-w00 or 0000-w00-0 + t + 00 or 00:00 or 00:00:00 or 00:00:00.000 + +00:00 or +0000 or +00) isoregex = /^\s*(?:[+-]\d{6}|\d{4})-(?:(\d\d-\d\d)|(w\d\d$)|(w\d\d-\d)|(\d\d\d))((t| )(\d\d(:\d\d(:\d\d(\.\d+)?)?)?)?([\+\-]\d\d(?::?\d\d)?|\s*z)?)?$/, isoformat = 'yyyy-mm-ddthh:mm:ssz', isodates = [ ['yyyyyy-mm-dd', /[+-]\d{6}-\d{2}-\d{2}/], ['yyyy-mm-dd', /\d{4}-\d{2}-\d{2}/], ['gggg-[w]ww-e', /\d{4}-w\d{2}-\d/], ['gggg-[w]ww', /\d{4}-w\d{2}/], ['yyyy-ddd', /\d{4}-\d{3}/] ], // iso time formats and regexes isotimes = [ ['hh:mm:ss.ssss', /(t| )\d\d:\d\d:\d\d\.\d+/], ['hh:mm:ss', /(t| )\d\d:\d\d:\d\d/], ['hh:mm', /(t| )\d\d:\d\d/], ['hh', /(t| )\d\d/] ], // timezone chunker '+10:00' > ['10', '00'] or '-1530' > ['-15', '30'] parsetimezonechunker = /([\+\-]|\d\d)/gi, // getter and setter names proxygettersandsetters = 'date|hours|minutes|seconds|milliseconds'.split('|'), unitmillisecondfactors = { 'milliseconds' : 1, 'seconds' : 1e3, 'minutes' : 6e4, 'hours' : 36e5, 'days' : 864e5, 'months' : 2592e6, 'years' : 31536e6 }, unitaliases = { ms : 'millisecond', s : 'second', m : 'minute', h : 'hour', d : 'day', d : 'date', w : 'week', w : 'isoweek', m : 'month', q : 'quarter', y : 'year', ddd : 'dayofyear', e : 'weekday', e : 'isoweekday', gg: 'weekyear', gg: 'isoweekyear' }, camelfunctions = { dayofyear : 'dayofyear', isoweekday : 'isoweekday', isoweek : 'isoweek', weekyear : 'weekyear', isoweekyear : 'isoweekyear' }, // format function strings formatfunctions = {}, // default relative time thresholds relativetimethresholds = { s: 45, // seconds to minute m: 45, // minutes to hour h: 22, // hours to day d: 26, // days to month m: 11 // months to year }, // tokens to ordinalize and pad ordinalizetokens = 'ddd w w m d d'.split(' '), paddedtokens = 'm d h h m s w w'.split(' '), formattokenfunctions = { m : function () { return this.month() + 1; }, mmm : function (format) { return this.localedata().monthsshort(this, format); }, mmmm : function (format) { return this.localedata().months(this, format); }, d : function () { return this.date(); }, ddd : function () { return this.dayofyear(); }, d : function () { return this.day(); }, dd : function (format) { return this.localedata().weekdaysmin(this, format); }, ddd : function (format) { return this.localedata().weekdaysshort(this, format); }, dddd : function (format) { return this.localedata().weekdays(this, format); }, w : function () { return this.week(); }, w : function () { return this.isoweek(); }, yy : function () { return leftzerofill(this.year() % 100, 2); }, yyyy : function () { return leftzerofill(this.year(), 4); }, yyyyy : function () { return leftzerofill(this.year(), 5); }, yyyyyy : function () { var y = this.year(), sign = y >= 0 ? '+' : '-'; return sign + leftzerofill(math.abs(y), 6); }, gg : function () { return leftzerofill(this.weekyear() % 100, 2); }, gggg : function () { return leftzerofill(this.weekyear(), 4); }, ggggg : function () { return leftzerofill(this.weekyear(), 5); }, gg : function () { return leftzerofill(this.isoweekyear() % 100, 2); }, gggg : function () { return leftzerofill(this.isoweekyear(), 4); }, ggggg : function () { return leftzerofill(this.isoweekyear(), 5); }, e : function () { return this.weekday(); }, e : function () { return this.isoweekday(); }, a : function () { return this.localedata().meridiem(this.hours(), this.minutes(), true); }, a : function () { return this.localedata().meridiem(this.hours(), this.minutes(), false); }, h : function () { return this.hours(); }, h : function () { return this.hours() % 12 || 12; }, m : function () { return this.minutes(); }, s : function () { return this.seconds(); }, s : function () { return toint(this.milliseconds() / 100); }, ss : function () { return leftzerofill(toint(this.milliseconds() / 10), 2); }, sss : function () { return leftzerofill(this.milliseconds(), 3); }, ssss : function () { return leftzerofill(this.milliseconds(), 3); }, z : function () { var a = -this.zone(), b = '+'; if (a < 0) { a = -a; b = '-'; } return b + leftzerofill(toint(a / 60), 2) + ':' + leftzerofill(toint(a) % 60, 2); }, zz : function () { var a = -this.zone(), b = '+'; if (a < 0) { a = -a; b = '-'; } return b + leftzerofill(toint(a / 60), 2) + leftzerofill(toint(a) % 60, 2); }, z : function () { return this.zoneabbr(); }, zz : function () { return this.zonename(); }, x : function () { return this.valueof(); }, x : function () { return this.unix(); }, q : function () { return this.quarter(); } }, deprecations = {}, lists = ['months', 'monthsshort', 'weekdays', 'weekdaysshort', 'weekdaysmin']; // pick the first defined of two or three arguments. dfl comes from // default. function dfl(a, b, c) { switch (arguments.length) { case 2: return a != null ? a : b; case 3: return a != null ? a : b != null ? b : c; default: throw new error('implement me'); } } function hasownprop(a, b) { return hasownproperty.call(a, b); } function defaultparsingflags() { // we need to deep clone this object, and es5 standard is not very // helpful. return { empty : false, unusedtokens : [], unusedinput : [], overflow : -2, charsleftover : 0, nullinput : false, invalidmonth : null, invalidformat : false, userinvalidated : false, iso: false }; } function printmsg(msg) { if (moment.suppressdeprecationwarnings === false && typeof console !== 'undefined' && console.warn) { console.warn('deprecation warning: ' + msg); } } function deprecate(msg, fn) { var firsttime = true; return extend(function () { if (firsttime) { printmsg(msg); firsttime = false; } return fn.apply(this, arguments); }, fn); } function deprecatesimple(name, msg) { if (!deprecations[name]) { printmsg(msg); deprecations[name] = true; } } function padtoken(func, count) { return function (a) { return leftzerofill(func.call(this, a), count); }; } function ordinalizetoken(func, period) { return function (a) { return this.localedata().ordinal(func.call(this, a), period); }; } while (ordinalizetokens.length) { i = ordinalizetokens.pop(); formattokenfunctions[i + 'o'] = ordinalizetoken(formattokenfunctions[i], i); } while (paddedtokens.length) { i = paddedtokens.pop(); formattokenfunctions[i + i] = padtoken(formattokenfunctions[i], 2); } formattokenfunctions.dddd = padtoken(formattokenfunctions.ddd, 3); /************************************ constructors ************************************/ function locale() { } // moment prototype object function moment(config, skipoverflow) { if (skipoverflow !== false) { checkoverflow(config); } copyconfig(this, config); this._d = new date(+config._d); } // duration constructor function duration(duration) { var normalizedinput = normalizeobjectunits(duration), years = normalizedinput.year || 0, quarters = normalizedinput.quarter || 0, months = normalizedinput.month || 0, weeks = normalizedinput.week || 0, days = normalizedinput.day || 0, hours = normalizedinput.hour || 0, minutes = normalizedinput.minute || 0, seconds = normalizedinput.second || 0, milliseconds = normalizedinput.millisecond || 0; // representation for dateaddremove this._milliseconds = +milliseconds + seconds * 1e3 + // 1000 minutes * 6e4 + // 1000 * 60 hours * 36e5; // 1000 * 60 * 60 // because of dateaddremove treats 24 hours as different from a // day when working around dst, we need to store them separately this._days = +days + weeks * 7; // it is impossible translate months into days without knowing // which months you are are talking about, so we have to store // it separately. this._months = +months + quarters * 3 + years * 12; this._data = {}; this._locale = moment.localedata(); this._bubble(); } /************************************ helpers ************************************/ function extend(a, b) { for (var i in b) { if (hasownprop(b, i)) { a[i] = b[i]; } } if (hasownprop(b, 'tostring')) { a.tostring = b.tostring; } if (hasownprop(b, 'valueof')) { a.valueof = b.valueof; } return a; } function copyconfig(to, from) { var i, prop, val; if (typeof from._isamomentobject !== 'undefined') { to._isamomentobject = from._isamomentobject; } if (typeof from._i !== 'undefined') { to._i = from._i; } if (typeof from._f !== 'undefined') { to._f = from._f; } if (typeof from._l !== 'undefined') { to._l = from._l; } if (typeof from._strict !== 'undefined') { to._strict = from._strict; } if (typeof from._tzm !== 'undefined') { to._tzm = from._tzm; } if (typeof from._isutc !== 'undefined') { to._isutc = from._isutc; } if (typeof from._offset !== 'undefined') { to._offset = from._offset; } if (typeof from._pf !== 'undefined') { to._pf = from._pf; } if (typeof from._locale !== 'undefined') { to._locale = from._locale; } if (momentproperties.length > 0) { for (i in momentproperties) { prop = momentproperties[i]; val = from[prop]; if (typeof val !== 'undefined') { to[prop] = val; } } } return to; } function absround(number) { if (number < 0) { return math.ceil(number); } else { return math.floor(number); } } // left zero fill a number // see http://jsperf.com/left-zero-filling for performance comparison function leftzerofill(number, targetlength, forcesign) { var output = '' + math.abs(number), sign = number >= 0; while (output.length < targetlength) { output = '0' + output; } return (sign ? (forcesign ? '+' : '') : '-') + output; } function positivemomentsdifference(base, other) { var res = {milliseconds: 0, months: 0}; res.months = other.month() - base.month() + (other.year() - base.year()) * 12; if (base.clone().add(res.months, 'm').isafter(other)) { --res.months; } res.milliseconds = +other - +(base.clone().add(res.months, 'm')); return res; } function momentsdifference(base, other) { var res; other = makeas(other, base); if (base.isbefore(other)) { res = positivemomentsdifference(base, other); } else { res = positivemomentsdifference(other, base); res.milliseconds = -res.milliseconds; res.months = -res.months; } return res; } // todo: remove 'name' arg after deprecation is removed function createadder(direction, name) { return function (val, period) { var dur, tmp; //invert the arguments, but complain about it if (period !== null && !isnan(+period)) { deprecatesimple(name, 'moment().' + name + '(period, number) is deprecated. please use moment().' + name + '(number, period).'); tmp = val; val = period; period = tmp; } val = typeof val === 'string' ? +val : val; dur = moment.duration(val, period); addorsubtractdurationfrommoment(this, dur, direction); return this; }; } function addorsubtractdurationfrommoment(mom, duration, isadding, updateoffset) { var milliseconds = duration._milliseconds, days = duration._days, months = duration._months; updateoffset = updateoffset == null ? true : updateoffset; if (milliseconds) { mom._d.settime(+mom._d + milliseconds * isadding); } if (days) { rawsetter(mom, 'date', rawgetter(mom, 'date') + days * isadding); } if (months) { rawmonthsetter(mom, rawgetter(mom, 'month') + months * isadding); } if (updateoffset) { moment.updateoffset(mom, days || months); } } // check if is an array function isarray(input) { return object.prototype.tostring.call(input) === '[object array]'; } function isdate(input) { return object.prototype.tostring.call(input) === '[object date]' || input instanceof date; } // compare two arrays, return the number of differences function comparearrays(array1, array2, dontconvert) { var len = math.min(array1.length, array2.length), lengthdiff = math.abs(array1.length - array2.length), diffs = 0, i; for (i = 0; i < len; i++) { if ((dontconvert && array1[i] !== array2[i]) || (!dontconvert && toint(array1[i]) !== toint(array2[i]))) { diffs++; } } return diffs + lengthdiff; } function normalizeunits(units) { if (units) { var lowered = units.tolowercase().replace(/(.)s$/, '$1'); units = unitaliases[units] || camelfunctions[lowered] || lowered; } return units; } function normalizeobjectunits(inputobject) { var normalizedinput = {}, normalizedprop, prop; for (prop in inputobject) { if (hasownprop(inputobject, prop)) { normalizedprop = normalizeunits(prop); if (normalizedprop) { normalizedinput[normalizedprop] = inputobject[prop]; } } } return normalizedinput; } function makelist(field) { var count, setter; if (field.indexof('week') === 0) { count = 7; setter = 'day'; } else if (field.indexof('month') === 0) { count = 12; setter = 'month'; } else { return; } moment[field] = function (format, index) { var i, getter, method = moment._locale[field], results = []; if (typeof format === 'number') { index = format; format = undefined; } getter = function (i) { var m = moment().utc().set(setter, i); return method.call(moment._locale, m, format || ''); }; if (index != null) { return getter(index); } else { for (i = 0; i < count; i++) { results.push(getter(i)); } return results; } }; } function toint(argumentforcoercion) { var coercednumber = +argumentforcoercion, value = 0; if (coercednumber !== 0 && isfinite(coercednumber)) { if (coercednumber >= 0) { value = math.floor(coercednumber); } else { value = math.ceil(coercednumber); } } return value; } function daysinmonth(year, month) { return new date(date.utc(year, month + 1, 0)).getutcdate(); } function weeksinyear(year, dow, doy) { return weekofyear(moment([year, 11, 31 + dow - doy]), dow, doy).week; } function daysinyear(year) { return isleapyear(year) ? 366 : 365; } function isleapyear(year) { return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0; } function checkoverflow(m) { var overflow; if (m._a && m._pf.overflow === -2) { overflow = m._a[month] < 0 || m._a[month] > 11 ? month : m._a[date] < 1 || m._a[date] > daysinmonth(m._a[year], m._a[month]) ? date : m._a[hour] < 0 || m._a[hour] > 24 || (m._a[hour] === 24 && (m._a[minute] !== 0 || m._a[second] !== 0 || m._a[millisecond] !== 0)) ? hour : m._a[minute] < 0 || m._a[minute] > 59 ? minute : m._a[second] < 0 || m._a[second] > 59 ? second : m._a[millisecond] < 0 || m._a[millisecond] > 999 ? millisecond : -1; if (m._pf._overflowdayofyear && (overflow < year || overflow > date)) { overflow = date; } m._pf.overflow = overflow; } } function isvalid(m) { if (m._isvalid == null) { m._isvalid = !isnan(m._d.gettime()) && m._pf.overflow < 0 && !m._pf.empty && !m._pf.invalidmonth && !m._pf.nullinput && !m._pf.invalidformat && !m._pf.userinvalidated; if (m._strict) { m._isvalid = m._isvalid && m._pf.charsleftover === 0 && m._pf.unusedtokens.length === 0 && m._pf.bighour === undefined; } } return m._isvalid; } function normalizelocale(key) { return key ? key.tolowercase().replace('_', '-') : key; } // pick the locale from the array // try ['en-au', 'en-gb'] as 'en-au', 'en-gb', 'en', as in move through the list trying each // substring from most specific to least, but move to the next array item if it's a more specific variant than the current root function chooselocale(names) { var i = 0, j, next, locale, split; while (i < names.length) { split = normalizelocale(names[i]).split('-'); j = split.length; next = normalizelocale(names[i + 1]); next = next ? next.split('-') : null; while (j > 0) { locale = loadlocale(split.slice(0, j).join('-')); if (locale) { return locale; } if (next && next.length >= j && comparearrays(split, next, true) >= j - 1) { //the next array item is better than a shallower substring of this one break; } j--; } i++; } return null; } function loadlocale(name) { var oldlocale = null; if (!locales[name] && hasmodule) { try { oldlocale = moment.locale(); require('./locale/' + name); // because definelocale currently also sets the global locale, we want to undo that for lazy loaded locales moment.locale(oldlocale); } catch (e) { } } return locales[name]; } // return a moment from input, that is local/utc/zone equivalent to model. function makeas(input, model) { var res, diff; if (model._isutc) { res = model.clone(); diff = (moment.ismoment(input) || isdate(input) ? +input : +moment(input)) - (+res); // use low-level api, because this fn is low-level api. res._d.settime(+res._d + diff); moment.updateoffset(res, false); return res; } else { return moment(input).local(); } } /************************************ locale ************************************/ extend(locale.prototype, { set : function (config) { var prop, i; for (i in config) { prop = config[i]; if (typeof prop === 'function') { this[i] = prop; } else { this['_' + i] = prop; } } // lenient ordinal parsing accepts just a number in addition to // number + (possibly) stuff coming from _ordinalparselenient. this._ordinalparselenient = new regexp(this._ordinalparse.source + '|' + /\d{1,2}/.source); }, _months : 'january_february_march_april_may_june_july_august_september_october_november_december'.split('_'), months : function (m) { return this._months[m.month()]; }, _monthsshort : 'jan_feb_mar_apr_may_jun_jul_aug_sep_oct_nov_dec'.split('_'), monthsshort : function (m) { return this._monthsshort[m.month()]; }, monthsparse : function (monthname, format, strict) { var i, mom, regex; if (!this._monthsparse) { this._monthsparse = []; this._longmonthsparse = []; this._shortmonthsparse = []; } for (i = 0; i < 12; i++) { // make the regex if we don't have it already mom = moment.utc([2000, i]); if (strict && !this._longmonthsparse[i]) { this._longmonthsparse[i] = new regexp('^' + this.months(mom, '').replace('.', '') + '$', 'i'); this._shortmonthsparse[i] = new regexp('^' + this.monthsshort(mom, '').replace('.', '') + '$', 'i'); } if (!strict && !this._monthsparse[i]) { regex = '^' + this.months(mom, '') + '|^' + this.monthsshort(mom, ''); this._monthsparse[i] = new regexp(regex.replace('.', ''), 'i'); } // test the regex if (strict && format === 'mmmm' && this._longmonthsparse[i].test(monthname)) { return i; } else if (strict && format === 'mmm' && this._shortmonthsparse[i].test(monthname)) { return i; } else if (!strict && this._monthsparse[i].test(monthname)) { return i; } } }, _weekdays : 'sunday_monday_tuesday_wednesday_thursday_friday_saturday'.split('_'), weekdays : function (m) { return this._weekdays[m.day()]; }, _weekdaysshort : 'sun_mon_tue_wed_thu_fri_sat'.split('_'), weekdaysshort : function (m) { return this._weekdaysshort[m.day()]; }, _weekdaysmin : 'su_mo_tu_we_th_fr_sa'.split('_'), weekdaysmin : function (m) { return this._weekdaysmin[m.day()]; }, weekdaysparse : function (weekdayname) { var i, mom, regex; if (!this._weekdaysparse) { this._weekdaysparse = []; } for (i = 0; i < 7; i++) { // make the regex if we don't have it already if (!this._weekdaysparse[i]) { mom = moment([2000, 1]).day(i); regex = '^' + this.weekdays(mom, '') + '|^' + this.weekdaysshort(mom, '') + '|^' + this.weekdaysmin(mom, ''); this._weekdaysparse[i] = new regexp(regex.replace('.', ''), 'i'); } // test the regex if (this._weekdaysparse[i].test(weekdayname)) { return i; } } }, _longdateformat : { lts : 'h:mm:ss a', lt : 'h:mm a', l : 'mm/dd/yyyy', ll : 'mmmm d, yyyy', lll : 'mmmm d, yyyy lt', llll : 'dddd, mmmm d, yyyy lt' }, longdateformat : function (key) { var output = this._longdateformat[key]; if (!output && this._longdateformat[key.touppercase()]) { output = this._longdateformat[key.touppercase()].replace(/mmmm|mm|dd|dddd/g, function (val) { return val.slice(1); }); this._longdateformat[key] = output; } return output; }, ispm : function (input) { // ie8 quirks mode & ie7 standards mode do not allow accessing strings like arrays // using charat should be more compatible. return ((input + '').tolowercase().charat(0) === 'p'); }, _meridiemparse : /[ap]\.?m?\.?/i, meridiem : function (hours, minutes, islower) { if (hours > 11) { return islower ? 'pm' : 'pm'; } else { return islower ? 'am' : 'am'; } }, _calendar : { sameday : '[today at] lt', nextday : '[tomorrow at] lt', nextweek : 'dddd [at] lt', lastday : '[yesterday at] lt', lastweek : '[last] dddd [at] lt', sameelse : 'l' }, calendar : function (key, mom, now) { var output = this._calendar[key]; return typeof output === 'function' ? output.apply(mom, [now]) : output; }, _relativetime : { future : 'in %s', past : '%s ago', s : 'a few seconds', m : 'a minute', mm : '%d minutes', h : 'an hour', hh : '%d hours', d : 'a day', dd : '%d days', m : 'a month', mm : '%d months', y : 'a year', yy : '%d years' }, relativetime : function (number, withoutsuffix, string, isfuture) { var output = this._relativetime[string]; return (typeof output === 'function') ? output(number, withoutsuffix, string, isfuture) : output.replace(/%d/i, number); }, pastfuture : function (diff, output) { var format = this._relativetime[diff > 0 ? 'future' : 'past']; return typeof format === 'function' ? format(output) : format.replace(/%s/i, output); }, ordinal : function (number) { return this._ordinal.replace('%d', number); }, _ordinal : '%d', _ordinalparse : /\d{1,2}/, preparse : function (string) { return string; }, postformat : function (string) { return string; }, week : function (mom) { return weekofyear(mom, this._week.dow, this._week.doy).week; }, _week : { dow : 0, // sunday is the first day of the week. doy : 6 // the week that contains jan 1st is the first week of the year. }, _invaliddate: 'invalid date', invaliddate: function () { return this._invaliddate; } }); /************************************ formatting ************************************/ function removeformattingtokens(input) { if (input.match(/\[[\s\s]/)) { return input.replace(/^\[|\]$/g, ''); } return input.replace(/\\/g, ''); } function makeformatfunction(format) { var array = format.match(formattingtokens), i, length; for (i = 0, length = array.length; i < length; i++) { if (formattokenfunctions[array[i]]) { array[i] = formattokenfunctions[array[i]]; } else { array[i] = removeformattingtokens(array[i]); } } return function (mom) { var output = ''; for (i = 0; i < length; i++) { output += array[i] instanceof function ? array[i].call(mom, format) : array[i]; } return output; }; } // format date using native date object function formatmoment(m, format) { if (!m.isvalid()) { return m.localedata().invaliddate(); } format = expandformat(format, m.localedata()); if (!formatfunctions[format]) { formatfunctions[format] = makeformatfunction(format); } return formatfunctions[format](m); } function expandformat(format, locale) { var i = 5; function replacelongdateformattokens(input) { return locale.longdateformat(input) || input; } localformattingtokens.lastindex = 0; while (i >= 0 && localformattingtokens.test(format)) { format = format.replace(localformattingtokens, replacelongdateformattokens); localformattingtokens.lastindex = 0; i -= 1; } return format; } /************************************ parsing ************************************/ // get the regex to find the next token function getparseregexfortoken(token, config) { var a, strict = config._strict; switch (token) { case 'q': return parsetokenonedigit; case 'dddd': return parsetokenthreedigits; case 'yyyy': case 'gggg': case 'gggg': return strict ? parsetokenfourdigits : parsetokenonetofourdigits; case 'y': case 'g': case 'g': return parsetokensignednumber; case 'yyyyyy': case 'yyyyy': case 'ggggg': case 'ggggg': return strict ? parsetokensixdigits : parsetokenonetosixdigits; case 's': if (strict) { return parsetokenonedigit; } /* falls through */ case 'ss': if (strict) { return parsetokentwodigits; } /* falls through */ case 'sss': if (strict) { return parsetokenthreedigits; } /* falls through */ case 'ddd': return parsetokenonetothreedigits; case 'mmm': case 'mmmm': case 'dd': case 'ddd': case 'dddd': return parsetokenword; case 'a': case 'a': return config._locale._meridiemparse; case 'x': return parsetokenoffsetms; case 'x': return parsetokentimestampms; case 'z': case 'zz': return parsetokentimezone; case 't': return parsetokent; case 'ssss': return parsetokendigits; case 'mm': case 'dd': case 'yy': case 'gg': case 'gg': case 'hh': case 'hh': case 'mm': case 'ss': case 'ww': case 'ww': return strict ? parsetokentwodigits : parsetokenoneortwodigits; case 'm': case 'd': case 'd': case 'h': case 'h': case 'm': case 's': case 'w': case 'w': case 'e': case 'e': return parsetokenoneortwodigits; case 'do': return strict ? config._locale._ordinalparse : config._locale._ordinalparselenient; default : a = new regexp(regexpescape(unescapeformat(token.replace('\\', '')), 'i')); return a; } } function timezoneminutesfromstring(string) { string = string || ''; var possibletzmatches = (string.match(parsetokentimezone) || []), tzchunk = possibletzmatches[possibletzmatches.length - 1] || [], parts = (tzchunk + '').match(parsetimezonechunker) || ['-', 0, 0], minutes = +(parts[1] * 60) + toint(parts[2]); return parts[0] === '+' ? -minutes : minutes; } // function to convert string input to date function addtimetoarrayfromtoken(token, input, config) { var a, datepartarray = config._a; switch (token) { // quarter case 'q': if (input != null) { datepartarray[month] = (toint(input) - 1) * 3; } break; // month case 'm' : // fall through to mm case 'mm' : if (input != null) { datepartarray[month] = toint(input) - 1; } break; case 'mmm' : // fall through to mmmm case 'mmmm' : a = config._locale.monthsparse(input, token, config._strict); // if we didn't find a month name, mark the date as invalid. if (a != null) { datepartarray[month] = a; } else { config._pf.invalidmonth = input; } break; // day of month case 'd' : // fall through to dd case 'dd' : if (input != null) { datepartarray[date] = toint(input); } break; case 'do' : if (input != null) { datepartarray[date] = toint(parseint( input.match(/\d{1,2}/)[0], 10)); } break; // day of year case 'ddd' : // fall through to dddd case 'dddd' : if (input != null) { config._dayofyear = toint(input); } break; // year case 'yy' : datepartarray[year] = moment.parsetwodigityear(input); break; case 'yyyy' : case 'yyyyy' : case 'yyyyyy' : datepartarray[year] = toint(input); break; // am / pm case 'a' : // fall through to a case 'a' : config._ispm = config._locale.ispm(input); break; // hour case 'h' : // fall through to hh case 'hh' : config._pf.bighour = true; /* falls through */ case 'h' : // fall through to hh case 'hh' : datepartarray[hour] = toint(input); break; // minute case 'm' : // fall through to mm case 'mm' : datepartarray[minute] = toint(input); break; // second case 's' : // fall through to ss case 'ss' : datepartarray[second] = toint(input); break; // millisecond case 's' : case 'ss' : case 'sss' : case 'ssss' : datepartarray[millisecond] = toint(('0.' + input) * 1000); break; // unix offset (milliseconds) case 'x': config._d = new date(toint(input)); break; // unix timestamp with ms case 'x': config._d = new date(parsefloat(input) * 1000); break; // timezone case 'z' : // fall through to zz case 'zz' : config._useutc = true; config._tzm = timezoneminutesfromstring(input); break; // weekday - human case 'dd': case 'ddd': case 'dddd': a = config._locale.weekdaysparse(input); // if we didn't get a weekday name, mark the date as invalid if (a != null) { config._w = config._w || {}; config._w['d'] = a; } else { config._pf.invalidweekday = input; } break; // week, week day - numeric case 'w': case 'ww': case 'w': case 'ww': case 'd': case 'e': case 'e': token = token.substr(0, 1); /* falls through */ case 'gggg': case 'gggg': case 'ggggg': token = token.substr(0, 2); if (input) { config._w = config._w || {}; config._w[token] = toint(input); } break; case 'gg': case 'gg': config._w = config._w || {}; config._w[token] = moment.parsetwodigityear(input); } } function dayofyearfromweekinfo(config) { var w, weekyear, week, weekday, dow, doy, temp; w = config._w; if (w.gg != null || w.w != null || w.e != null) { dow = 1; doy = 4; // todo: we need to take the current isoweekyear, but that depends on // how we interpret now (local, utc, fixed offset). so create // a now version of current config (take local/utc/offset flags, and // create now). weekyear = dfl(w.gg, config._a[year], weekofyear(moment(), 1, 4).year); week = dfl(w.w, 1); weekday = dfl(w.e, 1); } else { dow = config._locale._week.dow; doy = config._locale._week.doy; weekyear = dfl(w.gg, config._a[year], weekofyear(moment(), dow, doy).year); week = dfl(w.w, 1); if (w.d != null) { // weekday -- low day numbers are considered next week weekday = w.d; if (weekday < dow) { ++week; } } else if (w.e != null) { // local weekday -- counting starts from begining of week weekday = w.e + dow; } else { // default to begining of week weekday = dow; } } temp = dayofyearfromweeks(weekyear, week, weekday, doy, dow); config._a[year] = temp.year; config._dayofyear = temp.dayofyear; } // convert an array to a date. // the array should mirror the parameters below // note: all values past the year are optional and will default to the lowest possible value. // [year, month, day , hour, minute, second, millisecond] function datefromconfig(config) { var i, date, input = [], currentdate, yeartouse; if (config._d) { return; } currentdate = currentdatearray(config); //compute day of the year from weeks and weekdays if (config._w && config._a[date] == null && config._a[month] == null) { dayofyearfromweekinfo(config); } //if the day of the year is set, figure out what it is if (config._dayofyear) { yeartouse = dfl(config._a[year], currentdate[year]); if (config._dayofyear > daysinyear(yeartouse)) { config._pf._overflowdayofyear = true; } date = makeutcdate(yeartouse, 0, config._dayofyear); config._a[month] = date.getutcmonth(); config._a[date] = date.getutcdate(); } // default to current date. // * if no year, month, day of month are given, default to today // * if day of month is given, default month and year // * if month is given, default only year // * if year is given, don't default anything for (i = 0; i < 3 && config._a[i] == null; ++i) { config._a[i] = input[i] = currentdate[i]; } // zero out whatever was not defaulted, including time for (; i < 7; i++) { config._a[i] = input[i] = (config._a[i] == null) ? (i === 2 ? 1 : 0) : config._a[i]; } // check for 24:00:00.000 if (config._a[hour] === 24 && config._a[minute] === 0 && config._a[second] === 0 && config._a[millisecond] === 0) { config._nextday = true; config._a[hour] = 0; } config._d = (config._useutc ? makeutcdate : makedate).apply(null, input); // apply timezone offset from input. the actual zone can be changed // with parsezone. if (config._tzm != null) { config._d.setutcminutes(config._d.getutcminutes() + config._tzm); } if (config._nextday) { config._a[hour] = 24; } } function datefromobject(config) { var normalizedinput; if (config._d) { return; } normalizedinput = normalizeobjectunits(config._i); config._a = [ normalizedinput.year, normalizedinput.month, normalizedinput.day || normalizedinput.date, normalizedinput.hour, normalizedinput.minute, normalizedinput.second, normalizedinput.millisecond ]; datefromconfig(config); } function currentdatearray(config) { var now = new date(); if (config._useutc) { return [ now.getutcfullyear(), now.getutcmonth(), now.getutcdate() ]; } else { return [now.getfullyear(), now.getmonth(), now.getdate()]; } } // date from string and format string function makedatefromstringandformat(config) { if (config._f === moment.iso_8601) { parseiso(config); return; } config._a = []; config._pf.empty = true; // this array is used to make a date, either with `new date` or `date.utc` var string = '' + config._i, i, parsedinput, tokens, token, skipped, stringlength = string.length, totalparsedinputlength = 0; tokens = expandformat(config._f, config._locale).match(formattingtokens) || []; for (i = 0; i < tokens.length; i++) { token = tokens[i]; parsedinput = (string.match(getparseregexfortoken(token, config)) || [])[0]; if (parsedinput) { skipped = string.substr(0, string.indexof(parsedinput)); if (skipped.length > 0) { config._pf.unusedinput.push(skipped); } string = string.slice(string.indexof(parsedinput) + parsedinput.length); totalparsedinputlength += parsedinput.length; } // don't parse if it's not a known token if (formattokenfunctions[token]) { if (parsedinput) { config._pf.empty = false; } else { config._pf.unusedtokens.push(token); } addtimetoarrayfromtoken(token, parsedinput, config); } else if (config._strict && !parsedinput) { config._pf.unusedtokens.push(token); } } // add remaining unparsed input length to the string config._pf.charsleftover = stringlength - totalparsedinputlength; if (string.length > 0) { config._pf.unusedinput.push(string); } // clear _12h flag if hour is <= 12 if (config._pf.bighour === true && config._a[hour] <= 12) { config._pf.bighour = undefined; } // handle am pm if (config._ispm && config._a[hour] < 12) { config._a[hour] += 12; } // if is 12 am, change hours to 0 if (config._ispm === false && config._a[hour] === 12) { config._a[hour] = 0; } datefromconfig(config); checkoverflow(config); } function unescapeformat(s) { return s.replace(/\\(\[)|\\(\])|\[([^\]\[]*)\]|\\(.)/g, function (matched, p1, p2, p3, p4) { return p1 || p2 || p3 || p4; }); } // code from http://stackoverflow.com/questions/3561493/is-there-a-regexp-escape-function-in-javascript function regexpescape(s) { return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'); } // date from string and array of format strings function makedatefromstringandarray(config) { var tempconfig, bestmoment, scoretobeat, i, currentscore; if (config._f.length === 0) { config._pf.invalidformat = true; config._d = new date(nan); return; } for (i = 0; i < config._f.length; i++) { currentscore = 0; tempconfig = copyconfig({}, config); if (config._useutc != null) { tempconfig._useutc = config._useutc; } tempconfig._pf = defaultparsingflags(); tempconfig._f = config._f[i]; makedatefromstringandformat(tempconfig); if (!isvalid(tempconfig)) { continue; } // if there is any input that was not parsed add a penalty for that format currentscore += tempconfig._pf.charsleftover; //or tokens currentscore += tempconfig._pf.unusedtokens.length * 10; tempconfig._pf.score = currentscore; if (scoretobeat == null || currentscore < scoretobeat) { scoretobeat = currentscore; bestmoment = tempconfig; } } extend(config, bestmoment || tempconfig); } // date from iso format function parseiso(config) { var i, l, string = config._i, match = isoregex.exec(string); if (match) { config._pf.iso = true; for (i = 0, l = isodates.length; i < l; i++) { if (isodates[i][1].exec(string)) { // match[5] should be 't' or undefined config._f = isodates[i][0] + (match[6] || ' '); break; } } for (i = 0, l = isotimes.length; i < l; i++) { if (isotimes[i][1].exec(string)) { config._f += isotimes[i][0]; break; } } if (string.match(parsetokentimezone)) { config._f += 'z'; } makedatefromstringandformat(config); } else { config._isvalid = false; } } // date from iso format or fallback function makedatefromstring(config) { parseiso(config); if (config._isvalid === false) { delete config._isvalid; moment.createfrominputfallback(config); } } function map(arr, fn) { var res = [], i; for (i = 0; i < arr.length; ++i) { res.push(fn(arr[i], i)); } return res; } function makedatefrominput(config) { var input = config._i, matched; if (input === undefined) { config._d = new date(); } else if (isdate(input)) { config._d = new date(+input); } else if ((matched = aspnetjsonregex.exec(input)) !== null) { config._d = new date(+matched[1]); } else if (typeof input === 'string') { makedatefromstring(config); } else if (isarray(input)) { config._a = map(input.slice(0), function (obj) { return parseint(obj, 10); }); datefromconfig(config); } else if (typeof(input) === 'object') { datefromobject(config); } else if (typeof(input) === 'number') { // from milliseconds config._d = new date(input); } else { moment.createfrominputfallback(config); } } function makedate(y, m, d, h, m, s, ms) { //can't just apply() to create a date: //http://stackoverflow.com/questions/181348/instantiating-a-javascript-object-by-calling-prototype-constructor-apply var date = new date(y, m, d, h, m, s, ms); //the date constructor doesn't accept years < 1970 if (y < 1970) { date.setfullyear(y); } return date; } function makeutcdate(y) { var date = new date(date.utc.apply(null, arguments)); if (y < 1970) { date.setutcfullyear(y); } return date; } function parseweekday(input, locale) { if (typeof input === 'string') { if (!isnan(input)) { input = parseint(input, 10); } else { input = locale.weekdaysparse(input); if (typeof input !== 'number') { return null; } } } return input; } /************************************ relative time ************************************/ // helper function for moment.fn.from, moment.fn.fromnow, and moment.duration.fn.humanize function substitutetimeago(string, number, withoutsuffix, isfuture, locale) { return locale.relativetime(number || 1, !!withoutsuffix, string, isfuture); } function relativetime(posnegduration, withoutsuffix, locale) { var duration = moment.duration(posnegduration).abs(), seconds = round(duration.as('s')), minutes = round(duration.as('m')), hours = round(duration.as('h')), days = round(duration.as('d')), months = round(duration.as('m')), years = round(duration.as('y')), args = seconds < relativetimethresholds.s && ['s', seconds] || minutes === 1 && ['m'] || minutes < relativetimethresholds.m && ['mm', minutes] || hours === 1 && ['h'] || hours < relativetimethresholds.h && ['hh', hours] || days === 1 && ['d'] || days < relativetimethresholds.d && ['dd', days] || months === 1 && ['m'] || months < relativetimethresholds.m && ['mm', months] || years === 1 && ['y'] || ['yy', years]; args[2] = withoutsuffix; args[3] = +posnegduration > 0; args[4] = locale; return substitutetimeago.apply({}, args); } /************************************ week of year ************************************/ // firstdayofweek 0 = sun, 6 = sat // the day of the week that starts the week // (usually sunday or monday) // firstdayofweekofyear 0 = sun, 6 = sat // the first week is the week that contains the first // of this day of the week // (eg. iso weeks use thursday (4)) function weekofyear(mom, firstdayofweek, firstdayofweekofyear) { var end = firstdayofweekofyear - firstdayofweek, daystodayofweek = firstdayofweekofyear - mom.day(), adjustedmoment; if (daystodayofweek > end) { daystodayofweek -= 7; } if (daystodayofweek < end - 7) { daystodayofweek += 7; } adjustedmoment = moment(mom).add(daystodayofweek, 'd'); return { week: math.ceil(adjustedmoment.dayofyear() / 7), year: adjustedmoment.year() }; } //http://en.wikipedia.org/wiki/iso_week_date#calculating_a_date_given_the_year.2c_week_number_and_weekday function dayofyearfromweeks(year, week, weekday, firstdayofweekofyear, firstdayofweek) { var d = makeutcdate(year, 0, 1).getutcday(), daystoadd, dayofyear; d = d === 0 ? 7 : d; weekday = weekday != null ? weekday : firstdayofweek; daystoadd = firstdayofweek - d + (d > firstdayofweekofyear ? 7 : 0) - (d < firstdayofweek ? 7 : 0); dayofyear = 7 * (week - 1) + (weekday - firstdayofweek) + daystoadd + 1; return { year: dayofyear > 0 ? year : year - 1, dayofyear: dayofyear > 0 ? dayofyear : daysinyear(year - 1) + dayofyear }; } /************************************ top level functions ************************************/ function makemoment(config) { var input = config._i, format = config._f, res; config._locale = config._locale || moment.localedata(config._l); if (input === null || (format === undefined && input === '')) { return moment.invalid({nullinput: true}); } if (typeof input === 'string') { config._i = input = config._locale.preparse(input); } if (moment.ismoment(input)) { return new moment(input, true); } else if (format) { if (isarray(format)) { makedatefromstringandarray(config); } else { makedatefromstringandformat(config); } } else { makedatefrominput(config); } res = new moment(config); if (res._nextday) { // adding is smart enough around dst res.add(1, 'd'); res._nextday = undefined; } return res; } moment = function (input, format, locale, strict) { var c; if (typeof(locale) === 'boolean') { strict = locale; locale = undefined; } // object construction must be done this way. // https://github.com/moment/moment/issues/1423 c = {}; c._isamomentobject = true; c._i = input; c._f = format; c._l = locale; c._strict = strict; c._isutc = false; c._pf = defaultparsingflags(); return makemoment(c); }; moment.suppressdeprecationwarnings = false; moment.createfrominputfallback = deprecate( 'moment construction falls back to js date. this is ' + 'discouraged and will be removed in upcoming major ' + 'release. please refer to ' + 'https://github.com/moment/moment/issues/1407 for more info.', function (config) { config._d = new date(config._i + (config._useutc ? ' utc' : '')); } ); // pick a moment m from moments so that m[fn](other) is true for all // other. this relies on the function fn to be transitive. // // moments should either be an array of moment objects or an array, whose // first element is an array of moment objects. function pickby(fn, moments) { var res, i; if (moments.length === 1 && isarray(moments[0])) { moments = moments[0]; } if (!moments.length) { return moment(); } res = moments[0]; for (i = 1; i < moments.length; ++i) { if (moments[i][fn](res)) { res = moments[i]; } } return res; } moment.min = function () { var args = [].slice.call(arguments, 0); return pickby('isbefore', args); }; moment.max = function () { var args = [].slice.call(arguments, 0); return pickby('isafter', args); }; // creating with utc moment.utc = function (input, format, locale, strict) { var c; if (typeof(locale) === 'boolean') { strict = locale; locale = undefined; } // object construction must be done this way. // https://github.com/moment/moment/issues/1423 c = {}; c._isamomentobject = true; c._useutc = true; c._isutc = true; c._l = locale; c._i = input; c._f = format; c._strict = strict; c._pf = defaultparsingflags(); return makemoment(c).utc(); }; // creating with unix timestamp (in seconds) moment.unix = function (input) { return moment(input * 1000); }; // duration moment.duration = function (input, key) { var duration = input, // matching against regexp is expensive, do it on demand match = null, sign, ret, parseiso, diffres; if (moment.isduration(input)) { duration = { ms: input._milliseconds, d: input._days, m: input._months }; } else if (typeof input === 'number') { duration = {}; if (key) { duration[key] = input; } else { duration.milliseconds = input; } } else if (!!(match = aspnettimespanjsonregex.exec(input))) { sign = (match[1] === '-') ? -1 : 1; duration = { y: 0, d: toint(match[date]) * sign, h: toint(match[hour]) * sign, m: toint(match[minute]) * sign, s: toint(match[second]) * sign, ms: toint(match[millisecond]) * sign }; } else if (!!(match = isodurationregex.exec(input))) { sign = (match[1] === '-') ? -1 : 1; parseiso = function (inp) { // we'd normally use ~~inp for this, but unfortunately it also // converts floats to ints. // inp may be undefined, so careful calling replace on it. var res = inp && parsefloat(inp.replace(',', '.')); // apply sign while we're at it return (isnan(res) ? 0 : res) * sign; }; duration = { y: parseiso(match[2]), m: parseiso(match[3]), d: parseiso(match[4]), h: parseiso(match[5]), m: parseiso(match[6]), s: parseiso(match[7]), w: parseiso(match[8]) }; } else if (typeof duration === 'object' && ('from' in duration || 'to' in duration)) { diffres = momentsdifference(moment(duration.from), moment(duration.to)); duration = {}; duration.ms = diffres.milliseconds; duration.m = diffres.months; } ret = new duration(duration); if (moment.isduration(input) && hasownprop(input, '_locale')) { ret._locale = input._locale; } return ret; }; // version number moment.version = version; // default format moment.defaultformat = isoformat; // constant that refers to the iso standard moment.iso_8601 = function () {}; // plugins that add properties should also add the key here (null value), // so we can properly clone ourselves. moment.momentproperties = momentproperties; // this function will be called whenever a moment is mutated. // it is intended to keep the offset in sync with the timezone. moment.updateoffset = function () {}; // this function allows you to set a threshold for relative time strings moment.relativetimethreshold = function (threshold, limit) { if (relativetimethresholds[threshold] === undefined) { return false; } if (limit === undefined) { return relativetimethresholds[threshold]; } relativetimethresholds[threshold] = limit; return true; }; moment.lang = deprecate( 'moment.lang is deprecated. use moment.locale instead.', function (key, value) { return moment.locale(key, value); } ); // this function will load locale and then set the global locale. if // no arguments are passed in, it will simply return the current global // locale key. moment.locale = function (key, values) { var data; if (key) { if (typeof(values) !== 'undefined') { data = moment.definelocale(key, values); } else { data = moment.localedata(key); } if (data) { moment.duration._locale = moment._locale = data; } } return moment._locale._abbr; }; moment.definelocale = function (name, values) { if (values !== null) { values.abbr = name; if (!locales[name]) { locales[name] = new locale(); } locales[name].set(values); // backwards compat for now: also set the locale moment.locale(name); return locales[name]; } else { // useful for testing delete locales[name]; return null; } }; moment.langdata = deprecate( 'moment.langdata is deprecated. use moment.localedata instead.', function (key) { return moment.localedata(key); } ); // returns locale data moment.localedata = function (key) { var locale; if (key && key._locale && key._locale._abbr) { key = key._locale._abbr; } if (!key) { return moment._locale; } if (!isarray(key)) { //short-circuit everything else locale = loadlocale(key); if (locale) { return locale; } key = [key]; } return chooselocale(key); }; // compare moment object moment.ismoment = function (obj) { return obj instanceof moment || (obj != null && hasownprop(obj, '_isamomentobject')); }; // for typechecking duration objects moment.isduration = function (obj) { return obj instanceof duration; }; for (i = lists.length - 1; i >= 0; --i) { makelist(lists[i]); } moment.normalizeunits = function (units) { return normalizeunits(units); }; moment.invalid = function (flags) { var m = moment.utc(nan); if (flags != null) { extend(m._pf, flags); } else { m._pf.userinvalidated = true; } return m; }; moment.parsezone = function () { return moment.apply(null, arguments).parsezone(); }; moment.parsetwodigityear = function (input) { return toint(input) + (toint(input) > 68 ? 1900 : 2000); }; /************************************ moment prototype ************************************/ extend(moment.fn = moment.prototype, { clone : function () { return moment(this); }, valueof : function () { return +this._d + ((this._offset || 0) * 60000); }, unix : function () { return math.floor(+this / 1000); }, tostring : function () { return this.clone().locale('en').format('ddd mmm dd yyyy hh:mm:ss [gmt]zz'); }, todate : function () { return this._offset ? new date(+this) : this._d; }, toisostring : function () { var m = moment(this).utc(); if (0 < m.year() && m.year() <= 9999) { if ('function' === typeof date.prototype.toisostring) { // native implementation is ~50x faster, use it when we can return this.todate().toisostring(); } else { return formatmoment(m, 'yyyy-mm-dd[t]hh:mm:ss.sss[z]'); } } else { return formatmoment(m, 'yyyyyy-mm-dd[t]hh:mm:ss.sss[z]'); } }, toarray : function () { var m = this; return [ m.year(), m.month(), m.date(), m.hours(), m.minutes(), m.seconds(), m.milliseconds() ]; }, isvalid : function () { return isvalid(this); }, isdstshifted : function () { if (this._a) { return this.isvalid() && comparearrays(this._a, (this._isutc ? moment.utc(this._a) : moment(this._a)).toarray()) > 0; } return false; }, parsingflags : function () { return extend({}, this._pf); }, invalidat: function () { return this._pf.overflow; }, utc : function (keeplocaltime) { return this.zone(0, keeplocaltime); }, local : function (keeplocaltime) { if (this._isutc) { this.zone(0, keeplocaltime); this._isutc = false; if (keeplocaltime) { this.add(this._datetzoffset(), 'm'); } } return this; }, format : function (inputstring) { var output = formatmoment(this, inputstring || moment.defaultformat); return this.localedata().postformat(output); }, add : createadder(1, 'add'), subtract : createadder(-1, 'subtract'), diff : function (input, units, asfloat) { var that = makeas(input, this), zonediff = (this.zone() - that.zone()) * 6e4, diff, output, daysadjust; units = normalizeunits(units); if (units === 'year' || units === 'month') { // average number of days in the months in the given dates diff = (this.daysinmonth() + that.daysinmonth()) * 432e5; // 24 * 60 * 60 * 1000 / 2 // difference in months output = ((this.year() - that.year()) * 12) + (this.month() - that.month()); // adjust by taking difference in days, average number of days // and dst in the given months. daysadjust = (this - moment(this).startof('month')) - (that - moment(that).startof('month')); // same as above but with zones, to negate all dst daysadjust -= ((this.zone() - moment(this).startof('month').zone()) - (that.zone() - moment(that).startof('month').zone())) * 6e4; output += daysadjust / diff; if (units === 'year') { output = output / 12; } } else { diff = (this - that); output = units === 'second' ? diff / 1e3 : // 1000 units === 'minute' ? diff / 6e4 : // 1000 * 60 units === 'hour' ? diff / 36e5 : // 1000 * 60 * 60 units === 'day' ? (diff - zonediff) / 864e5 : // 1000 * 60 * 60 * 24, negate dst units === 'week' ? (diff - zonediff) / 6048e5 : // 1000 * 60 * 60 * 24 * 7, negate dst diff; } return asfloat ? output : absround(output); }, from : function (time, withoutsuffix) { return moment.duration({to: this, from: time}).locale(this.locale()).humanize(!withoutsuffix); }, fromnow : function (withoutsuffix) { return this.from(moment(), withoutsuffix); }, calendar : function (time) { // we want to compare the start of today, vs this. // getting start-of-today depends on whether we're zone'd or not. var now = time || moment(), sod = makeas(now, this).startof('day'), diff = this.diff(sod, 'days', true), format = diff < -6 ? 'sameelse' : diff < -1 ? 'lastweek' : diff < 0 ? 'lastday' : diff < 1 ? 'sameday' : diff < 2 ? 'nextday' : diff < 7 ? 'nextweek' : 'sameelse'; return this.format(this.localedata().calendar(format, this, moment(now))); }, isleapyear : function () { return isleapyear(this.year()); }, isdst : function () { return (this.zone() < this.clone().month(0).zone() || this.zone() < this.clone().month(5).zone()); }, day : function (input) { var day = this._isutc ? this._d.getutcday() : this._d.getday(); if (input != null) { input = parseweekday(input, this.localedata()); return this.add(input - day, 'd'); } else { return day; } }, month : makeaccessor('month', true), startof : function (units) { units = normalizeunits(units); // the following switch intentionally omits break keywords // to utilize falling through the cases. switch (units) { case 'year': this.month(0); /* falls through */ case 'quarter': case 'month': this.date(1); /* falls through */ case 'week': case 'isoweek': case 'day': this.hours(0); /* falls through */ case 'hour': this.minutes(0); /* falls through */ case 'minute': this.seconds(0); /* falls through */ case 'second': this.milliseconds(0); /* falls through */ } // weeks are a special case if (units === 'week') { this.weekday(0); } else if (units === 'isoweek') { this.isoweekday(1); } // quarters are also special if (units === 'quarter') { this.month(math.floor(this.month() / 3) * 3); } return this; }, endof: function (units) { units = normalizeunits(units); if (units === undefined || units === 'millisecond') { return this; } return this.startof(units).add(1, (units === 'isoweek' ? 'week' : units)).subtract(1, 'ms'); }, isafter: function (input, units) { var inputms; units = normalizeunits(typeof units !== 'undefined' ? units : 'millisecond'); if (units === 'millisecond') { input = moment.ismoment(input) ? input : moment(input); return +this > +input; } else { inputms = moment.ismoment(input) ? +input : +moment(input); return inputms < +this.clone().startof(units); } }, isbefore: function (input, units) { var inputms; units = normalizeunits(typeof units !== 'undefined' ? units : 'millisecond'); if (units === 'millisecond') { input = moment.ismoment(input) ? input : moment(input); return +this < +input; } else { inputms = moment.ismoment(input) ? +input : +moment(input); return +this.clone().endof(units) < inputms; } }, issame: function (input, units) { var inputms; units = normalizeunits(units || 'millisecond'); if (units === 'millisecond') { input = moment.ismoment(input) ? input : moment(input); return +this === +input; } else { inputms = +moment(input); return +(this.clone().startof(units)) <= inputms && inputms <= +(this.clone().endof(units)); } }, min: deprecate( 'moment().min is deprecated, use moment.min instead. https://github.com/moment/moment/issues/1548', function (other) { other = moment.apply(null, arguments); return other < this ? this : other; } ), max: deprecate( 'moment().max is deprecated, use moment.max instead. https://github.com/moment/moment/issues/1548', function (other) { other = moment.apply(null, arguments); return other > this ? this : other; } ), // keeplocaltime = true means only change the timezone, without // affecting the local hour. so 5:31:26 +0300 --[zone(2, true)]--> // 5:31:26 +0200 it is possible that 5:31:26 doesn't exist int zone // +0200, so we adjust the time as needed, to be valid. // // keeping the time actually adds/subtracts (one hour) // from the actual represented time. that is why we call updateoffset // a second time. in case it wants us to change the offset again // _changeinprogress == true case, then we have to adjust, because // there is no such time in the given timezone. zone : function (input, keeplocaltime) { var offset = this._offset || 0, localadjust; if (input != null) { if (typeof input === 'string') { input = timezoneminutesfromstring(input); } if (math.abs(input) < 16) { input = input * 60; } if (!this._isutc && keeplocaltime) { localadjust = this._datetzoffset(); } this._offset = input; this._isutc = true; if (localadjust != null) { this.subtract(localadjust, 'm'); } if (offset !== input) { if (!keeplocaltime || this._changeinprogress) { addorsubtractdurationfrommoment(this, moment.duration(offset - input, 'm'), 1, false); } else if (!this._changeinprogress) { this._changeinprogress = true; moment.updateoffset(this, true); this._changeinprogress = null; } } } else { return this._isutc ? offset : this._datetzoffset(); } return this; }, zoneabbr : function () { return this._isutc ? 'utc' : ''; }, zonename : function () { return this._isutc ? 'coordinated universal time' : ''; }, parsezone : function () { if (this._tzm) { this.zone(this._tzm); } else if (typeof this._i === 'string') { this.zone(this._i); } return this; }, hasalignedhouroffset : function (input) { if (!input) { input = 0; } else { input = moment(input).zone(); } return (this.zone() - input) % 60 === 0; }, daysinmonth : function () { return daysinmonth(this.year(), this.month()); }, dayofyear : function (input) { var dayofyear = round((moment(this).startof('day') - moment(this).startof('year')) / 864e5) + 1; return input == null ? dayofyear : this.add((input - dayofyear), 'd'); }, quarter : function (input) { return input == null ? math.ceil((this.month() + 1) / 3) : this.month((input - 1) * 3 + this.month() % 3); }, weekyear : function (input) { var year = weekofyear(this, this.localedata()._week.dow, this.localedata()._week.doy).year; return input == null ? year : this.add((input - year), 'y'); }, isoweekyear : function (input) { var year = weekofyear(this, 1, 4).year; return input == null ? year : this.add((input - year), 'y'); }, week : function (input) { var week = this.localedata().week(this); return input == null ? week : this.add((input - week) * 7, 'd'); }, isoweek : function (input) { var week = weekofyear(this, 1, 4).week; return input == null ? week : this.add((input - week) * 7, 'd'); }, weekday : function (input) { var weekday = (this.day() + 7 - this.localedata()._week.dow) % 7; return input == null ? weekday : this.add(input - weekday, 'd'); }, isoweekday : function (input) { // behaves the same as moment#day except // as a getter, returns 7 instead of 0 (1-7 range instead of 0-6) // as a setter, sunday should belong to the previous week. return input == null ? this.day() || 7 : this.day(this.day() % 7 ? input : input - 7); }, isoweeksinyear : function () { return weeksinyear(this.year(), 1, 4); }, weeksinyear : function () { var weekinfo = this.localedata()._week; return weeksinyear(this.year(), weekinfo.dow, weekinfo.doy); }, get : function (units) { units = normalizeunits(units); return this[units](); }, set : function (units, value) { units = normalizeunits(units); if (typeof this[units] === 'function') { this[units](value); } return this; }, // if passed a locale key, it will set the locale for this // instance. otherwise, it will return the locale configuration // variables for this instance. locale : function (key) { var newlocaledata; if (key === undefined) { return this._locale._abbr; } else { newlocaledata = moment.localedata(key); if (newlocaledata != null) { this._locale = newlocaledata; } return this; } }, lang : deprecate( 'moment().lang() is deprecated. instead, use moment().localedata() to get the language configuration. use moment().locale() to change languages.', function (key) { if (key === undefined) { return this.localedata(); } else { return this.locale(key); } } ), localedata : function () { return this._locale; }, _datetzoffset : function () { // on firefox.24 date#gettimezoneoffset returns a floating point. // https://github.com/moment/moment/pull/1871 return math.round(this._d.gettimezoneoffset() / 15) * 15; } }); function rawmonthsetter(mom, value) { var dayofmonth; // todo: move this out of here! if (typeof value === 'string') { value = mom.localedata().monthsparse(value); // todo: another silent failure? if (typeof value !== 'number') { return mom; } } dayofmonth = math.min(mom.date(), daysinmonth(mom.year(), value)); mom._d['set' + (mom._isutc ? 'utc' : '') + 'month'](value, dayofmonth); return mom; } function rawgetter(mom, unit) { return mom._d['get' + (mom._isutc ? 'utc' : '') + unit](); } function rawsetter(mom, unit, value) { if (unit === 'month') { return rawmonthsetter(mom, value); } else { return mom._d['set' + (mom._isutc ? 'utc' : '') + unit](value); } } function makeaccessor(unit, keeptime) { return function (value) { if (value != null) { rawsetter(this, unit, value); moment.updateoffset(this, keeptime); return this; } else { return rawgetter(this, unit); } }; } moment.fn.millisecond = moment.fn.milliseconds = makeaccessor('milliseconds', false); moment.fn.second = moment.fn.seconds = makeaccessor('seconds', false); moment.fn.minute = moment.fn.minutes = makeaccessor('minutes', false); // setting the hour should keep the time, because the user explicitly // specified which hour he wants. so trying to maintain the same hour (in // a new timezone) makes sense. adding/subtracting hours does not follow // this rule. moment.fn.hour = moment.fn.hours = makeaccessor('hours', true); // moment.fn.month is defined separately moment.fn.date = makeaccessor('date', true); moment.fn.dates = deprecate('dates accessor is deprecated. use date instead.', makeaccessor('date', true)); moment.fn.year = makeaccessor('fullyear', true); moment.fn.years = deprecate('years accessor is deprecated. use year instead.', makeaccessor('fullyear', true)); // add plural methods moment.fn.days = moment.fn.day; moment.fn.months = moment.fn.month; moment.fn.weeks = moment.fn.week; moment.fn.isoweeks = moment.fn.isoweek; moment.fn.quarters = moment.fn.quarter; // add aliased format methods moment.fn.tojson = moment.fn.toisostring; /************************************ duration prototype ************************************/ function daystoyears (days) { // 400 years have 146097 days (taking into account leap year rules) return days * 400 / 146097; } function yearstodays (years) { // years * 365 + absround(years / 4) - // absround(years / 100) + absround(years / 400); return years * 146097 / 400; } extend(moment.duration.fn = duration.prototype, { _bubble : function () { var milliseconds = this._milliseconds, days = this._days, months = this._months, data = this._data, seconds, minutes, hours, years = 0; // the following code bubbles up values, see the tests for // examples of what that means. data.milliseconds = milliseconds % 1000; seconds = absround(milliseconds / 1000); data.seconds = seconds % 60; minutes = absround(seconds / 60); data.minutes = minutes % 60; hours = absround(minutes / 60); data.hours = hours % 24; days += absround(hours / 24); // accurately convert days to years, assume start from year 0. years = absround(daystoyears(days)); days -= absround(yearstodays(years)); // 30 days to a month // todo (iskren): use anchor date (like 1st jan) to compute this. months += absround(days / 30); days %= 30; // 12 months -> 1 year years += absround(months / 12); months %= 12; data.days = days; data.months = months; data.years = years; }, abs : function () { this._milliseconds = math.abs(this._milliseconds); this._days = math.abs(this._days); this._months = math.abs(this._months); this._data.milliseconds = math.abs(this._data.milliseconds); this._data.seconds = math.abs(this._data.seconds); this._data.minutes = math.abs(this._data.minutes); this._data.hours = math.abs(this._data.hours); this._data.months = math.abs(this._data.months); this._data.years = math.abs(this._data.years); return this; }, weeks : function () { return absround(this.days() / 7); }, valueof : function () { return this._milliseconds + this._days * 864e5 + (this._months % 12) * 2592e6 + toint(this._months / 12) * 31536e6; }, humanize : function (withsuffix) { var output = relativetime(this, !withsuffix, this.localedata()); if (withsuffix) { output = this.localedata().pastfuture(+this, output); } return this.localedata().postformat(output); }, add : function (input, val) { // supports only 2.0-style add(1, 's') or add(moment) var dur = moment.duration(input, val); this._milliseconds += dur._milliseconds; this._days += dur._days; this._months += dur._months; this._bubble(); return this; }, subtract : function (input, val) { var dur = moment.duration(input, val); this._milliseconds -= dur._milliseconds; this._days -= dur._days; this._months -= dur._months; this._bubble(); return this; }, get : function (units) { units = normalizeunits(units); return this[units.tolowercase() + 's'](); }, as : function (units) { var days, months; units = normalizeunits(units); if (units === 'month' || units === 'year') { days = this._days + this._milliseconds / 864e5; months = this._months + daystoyears(days) * 12; return units === 'month' ? months : months / 12; } else { // handle milliseconds separately because of floating point math errors (issue #1867) days = this._days + math.round(yearstodays(this._months / 12)); switch (units) { case 'week': return days / 7 + this._milliseconds / 6048e5; case 'day': return days + this._milliseconds / 864e5; case 'hour': return days * 24 + this._milliseconds / 36e5; case 'minute': return days * 24 * 60 + this._milliseconds / 6e4; case 'second': return days * 24 * 60 * 60 + this._milliseconds / 1000; // math.floor prevents floating point math errors here case 'millisecond': return math.floor(days * 24 * 60 * 60 * 1000) + this._milliseconds; default: throw new error('unknown unit ' + units); } } }, lang : moment.fn.lang, locale : moment.fn.locale, toisostring : deprecate( 'toisostring() is deprecated. please use toisostring() instead ' + '(notice the capitals)', function () { return this.toisostring(); } ), toisostring : function () { // inspired by https://github.com/dordille/moment-isoduration/blob/master/moment.isoduration.js var years = math.abs(this.years()), months = math.abs(this.months()), days = math.abs(this.days()), hours = math.abs(this.hours()), minutes = math.abs(this.minutes()), seconds = math.abs(this.seconds() + this.milliseconds() / 1000); if (!this.asseconds()) { // this is the same as c#'s (noda) and python (isodate)... // but not other js (goog.date) return 'p0d'; } return (this.asseconds() < 0 ? '-' : '') + 'p' + (years ? years + 'y' : '') + (months ? months + 'm' : '') + (days ? days + 'd' : '') + ((hours || minutes || seconds) ? 't' : '') + (hours ? hours + 'h' : '') + (minutes ? minutes + 'm' : '') + (seconds ? seconds + 's' : ''); }, localedata : function () { return this._locale; } }); moment.duration.fn.tostring = moment.duration.fn.toisostring; function makedurationgetter(name) { moment.duration.fn[name] = function () { return this._data[name]; }; } for (i in unitmillisecondfactors) { if (hasownprop(unitmillisecondfactors, i)) { makedurationgetter(i.tolowercase()); } } moment.duration.fn.asmilliseconds = function () { return this.as('ms'); }; moment.duration.fn.asseconds = function () { return this.as('s'); }; moment.duration.fn.asminutes = function () { return this.as('m'); }; moment.duration.fn.ashours = function () { return this.as('h'); }; moment.duration.fn.asdays = function () { return this.as('d'); }; moment.duration.fn.asweeks = function () { return this.as('weeks'); }; moment.duration.fn.asmonths = function () { return this.as('m'); }; moment.duration.fn.asyears = function () { return this.as('y'); }; /************************************ default locale ************************************/ // set default locale, other locale will inherit from english. moment.locale('en', { ordinalparse: /\d{1,2}(th|st|nd|rd)/, ordinal : function (number) { var b = number % 10, output = (toint(number % 100 / 10) === 1) ? 'th' : (b === 1) ? 'st' : (b === 2) ? 'nd' : (b === 3) ? 'rd' : 'th'; return number + output; } }); /* embed_locales */ /************************************ exposing moment ************************************/ function makeglobal(shoulddeprecate) { /*global ender:false */ if (typeof ender !== 'undefined') { return; } oldglobalmoment = globalscope.moment; if (shoulddeprecate) { globalscope.moment = deprecate( 'accessing moment through the global scope is ' + 'deprecated, and will be removed in an upcoming ' + 'release.', moment); } else { globalscope.moment = moment; } } // commonjs module is defined if (hasmodule) { module.exports = moment; } else if (typeof define === 'function' && define.amd) { define('moment', function (require, exports, module) { if (module.config && module.config() && module.config().noglobal === true) { // release the global variable globalscope.moment = oldglobalmoment; } return moment; }); makeglobal(true); } else { makeglobal(); } }).call(this);