diff --git a/demo/bundle.js b/demo/bundle.js index ae858be..e44d67e 100644 --- a/demo/bundle.js +++ b/demo/bundle.js @@ -354,7 +354,7 @@ process.umask = function() { return 0; }; },{}],7:[function(require,module,exports){ //! moment.js -//! version : 2.10.3 +//! version : 2.10.6 //! authors : Tim Wood, Iskren Chernev, Moment.js contributors //! license : MIT //! momentjs.com @@ -449,6 +449,7 @@ process.umask = function() { return 0; }; flags.overflow < 0 && !flags.empty && !flags.invalidMonth && + !flags.invalidWeekday && !flags.nullInput && !flags.invalidFormat && !flags.userInvalidated; @@ -529,7 +530,7 @@ process.umask = function() { return 0; }; // Moment prototype object function Moment(config) { copyConfig(this, config); - this._d = new Date(+config._d); + this._d = new Date(config._d != null ? config._d.getTime() : NaN); // Prevent infinite loop in case updateOffset creates new moment // objects. if (updateInProgress === false) { @@ -543,16 +544,20 @@ process.umask = function() { return 0; }; return obj instanceof Moment || (obj != null && obj._isAMomentObject != null); } + function absFloor (number) { + if (number < 0) { + return Math.ceil(number); + } else { + return Math.floor(number); + } + } + 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); - } + value = absFloor(coercedNumber); } return value; @@ -650,9 +655,7 @@ process.umask = function() { return 0; }; function defineLocale (name, values) { if (values !== null) { values.abbr = name; - if (!locales[name]) { - locales[name] = new Locale(); - } + locales[name] = locales[name] || new Locale(); locales[name].set(values); // backwards compat for now: also set the locale @@ -756,16 +759,14 @@ process.umask = function() { return 0; }; } function zeroFill(number, targetLength, forceSign) { - var output = '' + Math.abs(number), + var absNumber = '' + Math.abs(number), + zerosToFill = targetLength - absNumber.length, sign = number >= 0; - - while (output.length < targetLength) { - output = '0' + output; - } - return (sign ? (forceSign ? '+' : '') : '-') + output; + return (sign ? (forceSign ? '+' : '') : '-') + + Math.pow(10, Math.max(0, zerosToFill)).toString().substr(1) + absNumber; } - var 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; + var 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,9}|x|X|zz?|ZZ?|.)/g; var localFormattingTokens = /(\[[^\[]*\])|(\\)?(LTS|LT|LL?L?L?|l{1,4})/g; @@ -833,10 +834,7 @@ process.umask = function() { return 0; }; } format = expandFormat(format, m.localeData()); - - if (!formatFunctions[format]) { - formatFunctions[format] = makeFormatFunction(format); - } + formatFunctions[format] = formatFunctions[format] || makeFormatFunction(format); return formatFunctions[format](m); } @@ -880,8 +878,15 @@ process.umask = function() { return 0; }; var regexes = {}; + function isFunction (sth) { + // https://github.com/moment/moment/issues/2325 + return typeof sth === 'function' && + Object.prototype.toString.call(sth) === '[object Function]'; + } + + function addRegexToken (token, regex, strictRegex) { - regexes[token] = typeof regex === 'function' ? regex : function (isStrict) { + regexes[token] = isFunction(regex) ? regex : function (isStrict) { return (isStrict && strictRegex) ? strictRegex : regex; }; } @@ -1089,12 +1094,11 @@ process.umask = function() { return 0; }; } function deprecate(msg, fn) { - var firstTime = true, - msgWithStack = msg + '\n' + (new Error()).stack; + var firstTime = true; return extend(function () { if (firstTime) { - warn(msgWithStack); + warn(msg + '\n' + (new Error()).stack); firstTime = false; } return fn.apply(this, arguments); @@ -1142,14 +1146,14 @@ process.umask = function() { return 0; }; getParsingFlags(config).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] || ' '); + config._f = isoDates[i][0]; break; } } for (i = 0, l = isoTimes.length; i < l; i++) { if (isoTimes[i][1].exec(string)) { - config._f += isoTimes[i][0]; + // match[6] should be 'T' or space + config._f += (match[6] || ' ') + isoTimes[i][0]; break; } } @@ -1228,7 +1232,10 @@ process.umask = function() { return 0; }; addRegexToken('YYYYY', match1to6, match6); addRegexToken('YYYYYY', match1to6, match6); - addParseToken(['YYYY', 'YYYYY', 'YYYYYY'], YEAR); + addParseToken(['YYYYY', 'YYYYYY'], YEAR); + addParseToken('YYYY', function (input, array) { + array[YEAR] = input.length === 2 ? utils_hooks__hooks.parseTwoDigitYear(input) : toInt(input); + }); addParseToken('YY', function (input, array) { array[YEAR] = utils_hooks__hooks.parseTwoDigitYear(input); }); @@ -1355,18 +1362,18 @@ process.umask = function() { return 0; }; //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 = createUTCDate(year, 0, 1).getUTCDay(); - var daysToAdd; - var dayOfYear; + var week1Jan = 6 + firstDayOfWeek - firstDayOfWeekOfYear, janX = createUTCDate(year, 0, 1 + week1Jan), d = janX.getUTCDay(), dayOfYear; + if (d < firstDayOfWeek) { + d += 7; + } + + weekday = weekday != null ? 1 * weekday : firstDayOfWeek; - 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; + dayOfYear = 1 + week1Jan + 7 * (week - 1) - d + weekday; return { - year : dayOfYear > 0 ? year : year - 1, - dayOfYear : dayOfYear > 0 ? dayOfYear : daysInYear(year - 1) + dayOfYear + year: dayOfYear > 0 ? year : year - 1, + dayOfYear: dayOfYear > 0 ? dayOfYear : daysInYear(year - 1) + dayOfYear }; } @@ -1652,9 +1659,19 @@ process.umask = function() { return 0; }; } function createFromConfig (config) { + var res = new Moment(checkOverflow(prepareConfig(config))); + if (res._nextDay) { + // Adding is smart enough around DST + res.add(1, 'd'); + res._nextDay = undefined; + } + + return res; + } + + function prepareConfig (config) { var input = config._i, - format = config._f, - res; + format = config._f; config._locale = config._locale || locale_locales__getLocale(config._l); @@ -1678,14 +1695,7 @@ process.umask = function() { return 0; }; configFromInput(config); } - res = new Moment(checkOverflow(config)); - if (res._nextDay) { - // Adding is smart enough around DST - res.add(1, 'd'); - res._nextDay = undefined; - } - - return res; + return config; } function configFromInput(config) { @@ -1765,7 +1775,7 @@ process.umask = function() { return 0; }; } res = moments[0]; for (i = 1; i < moments.length; ++i) { - if (moments[i][fn](res)) { + if (!moments[i].isValid() || moments[i][fn](res)) { res = moments[i]; } } @@ -1877,7 +1887,6 @@ process.umask = function() { return 0; }; } else { return local__createLocal(input).local(); } - return model._isUTC ? local__createLocal(input).zone(model._offset || 0) : local__createLocal(input).local(); } function getDateOffset (m) { @@ -1977,12 +1986,7 @@ process.umask = function() { return 0; }; } function hasAlignedHourOffset (input) { - if (!input) { - input = 0; - } - else { - input = local__createLocal(input).utcOffset(); - } + input = input ? local__createLocal(input).utcOffset() : 0; return (this.utcOffset() - input) % 60 === 0; } @@ -1995,12 +1999,24 @@ process.umask = function() { return 0; }; } function isDaylightSavingTimeShifted () { - if (this._a) { - var other = this._isUTC ? create_utc__createUTC(this._a) : local__createLocal(this._a); - return this.isValid() && compareArrays(this._a, other.toArray()) > 0; + if (typeof this._isDSTShifted !== 'undefined') { + return this._isDSTShifted; } - return false; + var c = {}; + + copyConfig(c, this); + c = prepareConfig(c); + + if (c._a) { + var other = c._isUTC ? create_utc__createUTC(c._a) : local__createLocal(c._a); + this._isDSTShifted = this.isValid() && + compareArrays(c._a, other.toArray()) > 0; + } else { + this._isDSTShifted = false; + } + + return this._isDSTShifted; } function isLocal () { @@ -2160,7 +2176,7 @@ process.umask = function() { return 0; }; var add_subtract__add = createAdder(1, 'add'); var add_subtract__subtract = createAdder(-1, 'subtract'); - function moment_calendar__calendar (time) { + function moment_calendar__calendar (time, formats) { // We want to compare the start of today, vs this. // Getting start-of-today depends on whether we're local/utc/offset or not. var now = time || local__createLocal(), @@ -2172,7 +2188,7 @@ process.umask = function() { return 0; }; diff < 1 ? 'sameDay' : diff < 2 ? 'nextDay' : diff < 7 ? 'nextWeek' : 'sameElse'; - return this.format(this.localeData().calendar(format, this, local__createLocal(now))); + return this.format(formats && formats[format] || this.localeData().calendar(format, this, local__createLocal(now))); } function clone () { @@ -2219,14 +2235,6 @@ process.umask = function() { return 0; }; } } - function absFloor (number) { - if (number < 0) { - return Math.ceil(number); - } else { - return Math.floor(number); - } - } - function diff (input, units, asFloat) { var that = cloneWithOffset(input, this), zoneDelta = (that.utcOffset() - this.utcOffset()) * 6e4, @@ -2417,6 +2425,19 @@ process.umask = function() { return 0; }; return [m.year(), m.month(), m.date(), m.hour(), m.minute(), m.second(), m.millisecond()]; } + function toObject () { + var m = this; + return { + years: m.year(), + months: m.month(), + date: m.date(), + hours: m.hours(), + minutes: m.minutes(), + seconds: m.seconds(), + milliseconds: m.milliseconds() + }; + } + function moment_valid__isValid () { return valid__isValid(this); } @@ -2588,18 +2609,20 @@ process.umask = function() { return 0; }; // HELPERS 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; - } - } + if (typeof input !== 'string') { + return input; + } + + if (!isNaN(input)) { + return parseInt(input, 10); } - return input; + + input = locale.weekdaysParse(input); + if (typeof input === 'number') { + return input; + } + + return null; } // LOCALES @@ -2622,9 +2645,7 @@ process.umask = function() { return 0; }; function localeWeekdaysParse (weekdayName) { var i, mom, regex; - if (!this._weekdaysParse) { - this._weekdaysParse = []; - } + this._weekdaysParse = this._weekdaysParse || []; for (i = 0; i < 7; i++) { // make the regex if we don't have it already @@ -2771,12 +2792,26 @@ process.umask = function() { return 0; }; return ~~(this.millisecond() / 10); }); - function millisecond__milliseconds (token) { - addFormatToken(0, [token, 3], 0, 'millisecond'); - } + addFormatToken(0, ['SSS', 3], 0, 'millisecond'); + addFormatToken(0, ['SSSS', 4], 0, function () { + return this.millisecond() * 10; + }); + addFormatToken(0, ['SSSSS', 5], 0, function () { + return this.millisecond() * 100; + }); + addFormatToken(0, ['SSSSSS', 6], 0, function () { + return this.millisecond() * 1000; + }); + addFormatToken(0, ['SSSSSSS', 7], 0, function () { + return this.millisecond() * 10000; + }); + addFormatToken(0, ['SSSSSSSS', 8], 0, function () { + return this.millisecond() * 100000; + }); + addFormatToken(0, ['SSSSSSSSS', 9], 0, function () { + return this.millisecond() * 1000000; + }); - millisecond__milliseconds('SSS'); - millisecond__milliseconds('SSSS'); // ALIASES @@ -2787,11 +2822,19 @@ process.umask = function() { return 0; }; addRegexToken('S', match1to3, match1); addRegexToken('SS', match1to3, match2); addRegexToken('SSS', match1to3, match3); - addRegexToken('SSSS', matchUnsigned); - addParseToken(['S', 'SS', 'SSS', 'SSSS'], function (input, array) { + + var token; + for (token = 'SSSS'; token.length <= 9; token += 'S') { + addRegexToken(token, matchUnsigned); + } + + function parseMs(input, array) { array[MILLISECOND] = toInt(('0.' + input) * 1000); - }); + } + for (token = 'S'; token.length <= 9; token += 'S') { + addParseToken(token, parseMs); + } // MOMENTS var getSetMillisecond = makeGetSet('Milliseconds', false); @@ -2838,6 +2881,7 @@ process.umask = function() { return 0; }; momentPrototype__proto.startOf = startOf; momentPrototype__proto.subtract = add_subtract__subtract; momentPrototype__proto.toArray = toArray; + momentPrototype__proto.toObject = toObject; momentPrototype__proto.toDate = toDate; momentPrototype__proto.toISOString = moment_format__toISOString; momentPrototype__proto.toJSON = moment_format__toISOString; @@ -2937,19 +2981,23 @@ process.umask = function() { return 0; }; LT : 'h:mm A', L : 'MM/DD/YYYY', LL : 'MMMM D, YYYY', - LLL : 'MMMM D, YYYY LT', - LLLL : 'dddd, MMMM D, YYYY LT' + LLL : 'MMMM D, YYYY h:mm A', + LLLL : 'dddd, MMMM D, YYYY h:mm A' }; function longDateFormat (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; + var format = this._longDateFormat[key], + formatUpper = this._longDateFormat[key.toUpperCase()]; + + if (format || !formatUpper) { + return format; } - return output; + + this._longDateFormat[key] = formatUpper.replace(/MMMM|MM|DD|dddd/g, function (val) { + return val.slice(1); + }); + + return this._longDateFormat[key]; } var defaultInvalidDate = 'Invalid date'; @@ -3158,12 +3206,29 @@ process.umask = function() { return 0; }; return duration_add_subtract__addSubtract(this, input, value, -1); } + function absCeil (number) { + if (number < 0) { + return Math.floor(number); + } else { + return Math.ceil(number); + } + } + function bubble () { var milliseconds = this._milliseconds; var days = this._days; var months = this._months; var data = this._data; - var seconds, minutes, hours, years = 0; + var seconds, minutes, hours, years, monthsFromDays; + + // if we have a mix of positive and negative values, bubble down first + // check: https://github.com/moment/moment/issues/2166 + if (!((milliseconds >= 0 && days >= 0 && months >= 0) || + (milliseconds <= 0 && days <= 0 && months <= 0))) { + milliseconds += absCeil(monthsToDays(months) + days) * 864e5; + days = 0; + months = 0; + } // The following code bubbles up values, see the tests for // examples of what that means. @@ -3180,17 +3245,13 @@ process.umask = function() { return 0; }; days += absFloor(hours / 24); - // Accurately convert days to years, assume start from year 0. - years = absFloor(daysToYears(days)); - days -= absFloor(yearsToDays(years)); - - // 30 days to a month - // TODO (iskren): Use anchor date (like 1st Jan) to compute this. - months += absFloor(days / 30); - days %= 30; + // convert days to months + monthsFromDays = absFloor(daysToMonths(days)); + months += monthsFromDays; + days -= absCeil(monthsToDays(monthsFromDays)); // 12 months -> 1 year - years += absFloor(months / 12); + years = absFloor(months / 12); months %= 12; data.days = days; @@ -3200,15 +3261,15 @@ process.umask = function() { return 0; }; return this; } - function daysToYears (days) { + function daysToMonths (days) { // 400 years have 146097 days (taking into account leap year rules) - return days * 400 / 146097; + // 400 years have 12 months === 4800 + return days * 4800 / 146097; } - function yearsToDays (years) { - // years * 365 + absFloor(years / 4) - - // absFloor(years / 100) + absFloor(years / 400); - return years * 146097 / 400; + function monthsToDays (months) { + // the reverse of daysToMonths + return months * 146097 / 4800; } function as (units) { @@ -3220,11 +3281,11 @@ process.umask = function() { return 0; }; if (units === 'month' || units === 'year') { days = this._days + milliseconds / 864e5; - months = this._months + daysToYears(days) * 12; + months = this._months + daysToMonths(days); 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)); + days = this._days + Math.round(monthsToDays(this._months)); switch (units) { case 'week' : return days / 7 + milliseconds / 6048e5; case 'day' : return days + milliseconds / 864e5; @@ -3274,7 +3335,7 @@ process.umask = function() { return 0; }; }; } - var duration_get__milliseconds = makeGetter('milliseconds'); + var milliseconds = makeGetter('milliseconds'); var seconds = makeGetter('seconds'); var minutes = makeGetter('minutes'); var hours = makeGetter('hours'); @@ -3352,13 +3413,36 @@ process.umask = function() { return 0; }; var iso_string__abs = Math.abs; function iso_string__toISOString() { + // for ISO strings we do not use the normal bubbling rules: + // * milliseconds bubble up until they become hours + // * days do not bubble at all + // * months bubble up until they become years + // This is because there is no context-free conversion between hours and days + // (think of clock changes) + // and also not between days and months (28-31 days per month) + var seconds = iso_string__abs(this._milliseconds) / 1000; + var days = iso_string__abs(this._days); + var months = iso_string__abs(this._months); + var minutes, hours, years; + + // 3600 seconds -> 60 minutes -> 1 hour + minutes = absFloor(seconds / 60); + hours = absFloor(minutes / 60); + seconds %= 60; + minutes %= 60; + + // 12 months -> 1 year + years = absFloor(months / 12); + months %= 12; + + // inspired by https://github.com/dordille/moment-isoduration/blob/master/moment.isoduration.js - var Y = iso_string__abs(this.years()); - var M = iso_string__abs(this.months()); - var D = iso_string__abs(this.days()); - var h = iso_string__abs(this.hours()); - var m = iso_string__abs(this.minutes()); - var s = iso_string__abs(this.seconds() + this.milliseconds() / 1000); + var Y = years; + var M = months; + var D = days; + var h = hours; + var m = minutes; + var s = seconds; var total = this.asSeconds(); if (!total) { @@ -3395,7 +3479,7 @@ process.umask = function() { return 0; }; duration_prototype__proto.valueOf = duration_as__valueOf; duration_prototype__proto._bubble = bubble; duration_prototype__proto.get = duration_get__get; - duration_prototype__proto.milliseconds = duration_get__milliseconds; + duration_prototype__proto.milliseconds = milliseconds; duration_prototype__proto.seconds = seconds; duration_prototype__proto.minutes = minutes; duration_prototype__proto.hours = hours; @@ -3433,7 +3517,7 @@ process.umask = function() { return 0; }; // Side effect imports - utils_hooks__hooks.version = '2.10.3'; + utils_hooks__hooks.version = '2.10.6'; setHookCallback(local__createLocal); diff --git a/package.json b/package.json index 7637bfb..eede013 100644 --- a/package.json +++ b/package.json @@ -25,16 +25,16 @@ "es6" ], "dependencies": { - "moment": "^2.10.3", + "moment": "^2.10.6", "react": "^0.13.3" }, "devDependencies": { - "babel": "^5.6.14", - "babelify": "^6.1.2", - "browserify": "^10.2.4", - "chai": "^3.0.0", - "coveralls": "^2.11.2", - "mochify": "^2.10.0", + "babel": "^5.8.20", + "babelify": "^6.1.3", + "browserify": "^11.0.1", + "chai": "^3.2.0", + "coveralls": "^2.11.3", + "mochify": "^2.12.0", "mochify-istanbul": "^2.3.0", "react-tools": "^0.13.3" },