import getParsingFlags from '../create/parsing-flags';
export default function checkOverflow (m) {
- var overflow;
- var a = m._a;
+ var overflow,
+ a = m._a;
if (a && getParsingFlags(m).overflow === -2) {
overflow =
}
export function createUTCDate (y) {
- var date;
+ var date, args;
// the Date.UTC function remaps years 0-99 to 1900-1999
if (y < 100 && y >= 0) {
- var args = Array.prototype.slice.call(arguments);
+ args = Array.prototype.slice.call(arguments);
// preserve leap years using a full 400 year cycle, then reset
args[0] = y + 400;
date = new Date(Date.UTC.apply(null, args));
}
function dayOfYearFromWeekInfo(config) {
- var w, weekYear, week, weekday, dow, doy, temp, weekdayOverflow;
+ var w, weekYear, week, weekday, dow, doy, temp, weekdayOverflow, curWeek;
w = config._w;
if (w.GG != null || w.W != null || w.E != null) {
dow = config._locale._week.dow;
doy = config._locale._week.doy;
- var curWeek = weekOfYear(createLocal(), dow, doy);
+ curWeek = weekOfYear(createLocal(), dow, doy);
weekYear = defaults(w.gg, config._a[YEAR], curWeek.year);
return;
}
- var i = normalizeObjectUnits(config._i);
+ var i = normalizeObjectUnits(config._i),
- var dayOrDate = i.day === undefined ? i.date : i.day;
+ dayOrDate = i.day === undefined ? i.date : i.day;
config._a = map([i.year, i.month, dayOrDate, i.hour, i.minute, i.second, i.millisecond], function (obj) {
return obj && parseInt(obj, 10);
});
// 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)
-var extendedIsoRegex = /^\s*((?:[+-]\d{6}|\d{4})-(?:\d\d-\d\d|W\d\d-\d|W\d\d|\d\d\d|\d\d))(?:(T| )(\d\d(?::\d\d(?::\d\d(?:[.,]\d+)?)?)?)([\+\-]\d\d(?::?\d\d)?|\s*Z)?)?$/;
-var basicIsoRegex = /^\s*((?:[+-]\d{6}|\d{4})(?:\d\d\d\d|W\d\d\d|W\d\d|\d\d\d|\d\d|))(?:(T| )(\d\d(?:\d\d(?:\d\d(?:[.,]\d+)?)?)?)([\+\-]\d\d(?::?\d\d)?|\s*Z)?)?$/;
-
-var tzRegex = /Z|[+-]\d\d(?::?\d\d)?/;
-
-var isoDates = [
- ['YYYYYY-MM-DD', /[+-]\d{6}-\d\d-\d\d/],
- ['YYYY-MM-DD', /\d{4}-\d\d-\d\d/],
- ['GGGG-[W]WW-E', /\d{4}-W\d\d-\d/],
- ['GGGG-[W]WW', /\d{4}-W\d\d/, false],
- ['YYYY-DDD', /\d{4}-\d{3}/],
- ['YYYY-MM', /\d{4}-\d\d/, false],
- ['YYYYYYMMDD', /[+-]\d{10}/],
- ['YYYYMMDD', /\d{8}/],
- ['GGGG[W]WWE', /\d{4}W\d{3}/],
- ['GGGG[W]WW', /\d{4}W\d{2}/, false],
- ['YYYYDDD', /\d{7}/],
- ['YYYYMM', /\d{6}/, false],
- ['YYYY', /\d{4}/, false]
-];
-
-// iso time formats and regexes
-var isoTimes = [
- ['HH:mm:ss.SSSS', /\d\d:\d\d:\d\d\.\d+/],
- ['HH:mm:ss,SSSS', /\d\d:\d\d:\d\d,\d+/],
- ['HH:mm:ss', /\d\d:\d\d:\d\d/],
- ['HH:mm', /\d\d:\d\d/],
- ['HHmmss.SSSS', /\d\d\d\d\d\d\.\d+/],
- ['HHmmss,SSSS', /\d\d\d\d\d\d,\d+/],
- ['HHmmss', /\d\d\d\d\d\d/],
- ['HHmm', /\d\d\d\d/],
- ['HH', /\d\d/]
-];
-
-var aspNetJsonRegex = /^\/?Date\((\-?\d+)/i;
+var extendedIsoRegex = /^\s*((?:[+-]\d{6}|\d{4})-(?:\d\d-\d\d|W\d\d-\d|W\d\d|\d\d\d|\d\d))(?:(T| )(\d\d(?::\d\d(?::\d\d(?:[.,]\d+)?)?)?)([+-]\d\d(?::?\d\d)?|\s*Z)?)?$/,
+ basicIsoRegex = /^\s*((?:[+-]\d{6}|\d{4})(?:\d\d\d\d|W\d\d\d|W\d\d|\d\d\d|\d\d|))(?:(T| )(\d\d(?:\d\d(?:\d\d(?:[.,]\d+)?)?)?)([+-]\d\d(?::?\d\d)?|\s*Z)?)?$/,
+
+ tzRegex = /Z|[+-]\d\d(?::?\d\d)?/,
+
+ isoDates = [
+ ['YYYYYY-MM-DD', /[+-]\d{6}-\d\d-\d\d/],
+ ['YYYY-MM-DD', /\d{4}-\d\d-\d\d/],
+ ['GGGG-[W]WW-E', /\d{4}-W\d\d-\d/],
+ ['GGGG-[W]WW', /\d{4}-W\d\d/, false],
+ ['YYYY-DDD', /\d{4}-\d{3}/],
+ ['YYYY-MM', /\d{4}-\d\d/, false],
+ ['YYYYYYMMDD', /[+-]\d{10}/],
+ ['YYYYMMDD', /\d{8}/],
+ ['GGGG[W]WWE', /\d{4}W\d{3}/],
+ ['GGGG[W]WW', /\d{4}W\d{2}/, false],
+ ['YYYYDDD', /\d{7}/],
+ ['YYYYMM', /\d{6}/, false],
+ ['YYYY', /\d{4}/, false]
+ ],
+
+ // iso time formats and regexes
+ isoTimes = [
+ ['HH:mm:ss.SSSS', /\d\d:\d\d:\d\d\.\d+/],
+ ['HH:mm:ss,SSSS', /\d\d:\d\d:\d\d,\d+/],
+ ['HH:mm:ss', /\d\d:\d\d:\d\d/],
+ ['HH:mm', /\d\d:\d\d/],
+ ['HHmmss.SSSS', /\d\d\d\d\d\d\.\d+/],
+ ['HHmmss,SSSS', /\d\d\d\d\d\d,\d+/],
+ ['HHmmss', /\d\d\d\d\d\d/],
+ ['HHmm', /\d\d\d\d/],
+ ['HH', /\d\d/]
+ ],
+
+ aspNetJsonRegex = /^\/?Date\((-?\d+)/i,
+ // RFC 2822 regex: For details see https://tools.ietf.org/html/rfc2822#section-3.3
+ rfc2822 = /^(?:(Mon|Tue|Wed|Thu|Fri|Sat|Sun),?\s)?(\d{1,2})\s(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s(\d{2,4})\s(\d\d):(\d\d)(?::(\d\d))?\s(?:(UT|GMT|[ECMP][SD]T)|([Zz])|([+-]\d{4}))$/,
+ obsOffsets = {
+ UT: 0,
+ GMT: 0,
+ EDT: -4 * 60,
+ EST: -5 * 60,
+ CDT: -5 * 60,
+ CST: -6 * 60,
+ MDT: -6 * 60,
+ MST: -7 * 60,
+ PDT: -7 * 60,
+ PST: -8 * 60
+ };
+
// date from iso format
export function configFromISO(config) {
}
}
-// RFC 2822 regex: For details see https://tools.ietf.org/html/rfc2822#section-3.3
-var rfc2822 = /^(?:(Mon|Tue|Wed|Thu|Fri|Sat|Sun),?\s)?(\d{1,2})\s(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s(\d{2,4})\s(\d\d):(\d\d)(?::(\d\d))?\s(?:(UT|GMT|[ECMP][SD]T)|([Zz])|([+-]\d{4}))$/;
function extractFromRFC2822Strings(yearStr, monthStr, dayStr, hourStr, minuteStr, secondStr) {
var result = [
return true;
}
-var obsOffsets = {
- UT: 0,
- GMT: 0,
- EDT: -4 * 60,
- EST: -5 * 60,
- CDT: -5 * 60,
- CST: -6 * 60,
- MDT: -6 * 60,
- MST: -7 * 60,
- PDT: -7 * 60,
- PST: -8 * 60
-};
-
function calculateOffset(obsOffset, militaryOffset, numOffset) {
if (obsOffset) {
return obsOffsets[obsOffset];
// the only allowed military tz is Z
return 0;
} else {
- var hm = parseInt(numOffset, 10);
- var m = hm % 100, h = (hm - m) / 100;
+ var hm = parseInt(numOffset, 10),
+ m = hm % 100, h = (hm - m) / 100;
return h * 60 + m;
}
}
// date and time from ref 2822 format
export function configFromRFC2822(config) {
- var match = rfc2822.exec(preprocessRFC2822(config._i));
+ var match = rfc2822.exec(preprocessRFC2822(config._i)), parsedArray;
if (match) {
- var parsedArray = extractFromRFC2822Strings(match[4], match[3], match[2], match[5], match[6], match[7]);
+ parsedArray = extractFromRFC2822Strings(match[4], match[3], match[2], match[5], match[6], match[7]);
if (!checkWeekday(match[1], parsedArray, config)) {
return;
}
export function isValid(m) {
if (m._isValid == null) {
- var flags = getParsingFlags(m);
- var parsedParts = some.call(flags.parsedDateParts, function (i) {
+ var flags = getParsingFlags(m),
+ parsedParts = some.call(flags.parsedDateParts, function (i) {
return i != null;
- });
- var isNowValid = !isNaN(m._d.getTime()) &&
+ }),
+ isNowValid = !isNaN(m._d.getTime()) &&
flags.overflow < 0 &&
!flags.empty &&
!flags.invalidMonth &&
if (!this.isValid()) {
return NaN;
}
- var days;
- var months;
- var milliseconds = this._milliseconds;
+ var days,
+ months,
+ milliseconds = this._milliseconds;
units = normalizeUnits(units);
};
}
-export var asMilliseconds = makeAs('ms');
-export var asSeconds = makeAs('s');
-export var asMinutes = makeAs('m');
-export var asHours = makeAs('h');
-export var asDays = makeAs('d');
-export var asWeeks = makeAs('w');
-export var asMonths = makeAs('M');
-export var asQuarters = makeAs('Q');
-export var asYears = makeAs('y');
+var asMilliseconds = makeAs('ms'),
+ asSeconds = makeAs('s'),
+ asMinutes = makeAs('m'),
+ asHours = makeAs('h'),
+ asDays = makeAs('d'),
+ asWeeks = makeAs('w'),
+ asMonths = makeAs('M'),
+ asQuarters = makeAs('Q'),
+ asYears = makeAs('y');
+
+export {
+ asMilliseconds,
+ asSeconds,
+ asMinutes,
+ asHours,
+ asDays,
+ asWeeks,
+ asMonths,
+ asQuarters,
+ asYears
+}
import absCeil from '../utils/abs-ceil';
export function bubble () {
- var milliseconds = this._milliseconds;
- var days = this._days;
- var months = this._months;
- var data = this._data;
- var seconds, minutes, hours, years, monthsFromDays;
+ var milliseconds = this._milliseconds,
+ days = this._days,
+ months = this._months,
+ data = this._data,
+ 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
import { createInvalid as invalid } from './valid';
// ASP.NET json date format regex
-var aspNetRegex = /^(\-|\+)?(?:(\d*)[. ])?(\d+)\:(\d+)(?:\:(\d+)(\.\d*)?)?$/;
+var aspNetRegex = /^(-|\+)?(?:(\d*)[. ])?(\d+):(\d+)(?::(\d+)(\.\d*)?)?$/,
// 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
// and further modified to allow for strings containing both week and day
-var isoRegex = /^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/;
+ isoRegex = /^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/;
export function createDuration (input, key) {
var duration = input,
} else {
duration.milliseconds = +input;
}
- } else if (!!(match = aspNetRegex.exec(input))) {
+ } else if ((match = aspNetRegex.exec(input))) {
sign = (match[1] === '-') ? -1 : 1;
duration = {
y : 0,
s : toInt(match[SECOND]) * sign,
ms : toInt(absRound(match[MILLISECOND] * 1000)) * sign // the millisecond decimal point is included in the match
};
- } else if (!!(match = isoRegex.exec(input))) {
+ } else if ((match = isoRegex.exec(input))) {
sign = (match[1] === '-') ? -1 : 1;
duration = {
y : parseIso(match[2], sign),
};
}
-export var milliseconds = makeGetter('milliseconds');
-export var seconds = makeGetter('seconds');
-export var minutes = makeGetter('minutes');
-export var hours = makeGetter('hours');
-export var days = makeGetter('days');
-export var months = makeGetter('months');
-export var years = makeGetter('years');
+var milliseconds = makeGetter('milliseconds'),
+ seconds = makeGetter('seconds'),
+ minutes = makeGetter('minutes'),
+ hours = makeGetter('hours'),
+ days = makeGetter('days'),
+ months = makeGetter('months'),
+ years = makeGetter('years');
+
+export {
+ milliseconds,
+ seconds,
+ minutes,
+ hours,
+ days,
+ months,
+ years
+}
export function weeks () {
return absFloor(this.days() / 7);
import { createDuration } from './create';
-var round = Math.round;
-var thresholds = {
+var round = Math.round,
+ thresholds = {
ss: 44, // a few seconds to seconds
s : 45, // seconds to minute
m : 45, // minutes to hour
}
function relativeTime (posNegDuration, withoutSuffix, thresholds, locale) {
- var duration = createDuration(posNegDuration).abs();
- var seconds = round(duration.as('s'));
- var minutes = round(duration.as('m'));
- var hours = round(duration.as('h'));
- var days = round(duration.as('d'));
- var months = round(duration.as('M'));
- var weeks = round(duration.as('w'));
- var years = round(duration.as('y'));
+ var duration = createDuration(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')),
+ weeks = round(duration.as('w')),
+ years = round(duration.as('y')),
- var a = seconds <= thresholds.ss && ['s', seconds] ||
+ a = seconds <= thresholds.ss && ['s', seconds] ||
seconds < thresholds.s && ['ss', seconds] ||
minutes <= 1 && ['m'] ||
minutes < thresholds.m && ['mm', minutes] ||
return this.localeData().invalidDate();
}
- var withSuffix = false;
- var th = thresholds;
+ var withSuffix = false,
+ th = thresholds,
+ ws, t, locale, output;
if (typeof withSuffixOrOptions === 'boolean') {
withSuffix = withSuffixOrOptions;
}
else if (typeof withSuffixOrOptions === 'object') {
- var ws = withSuffixOrOptions.withSuffix;
+ ws = withSuffixOrOptions.withSuffix;
if (typeof ws === 'boolean') {
withSuffix = ws;
}
- var t = withSuffixOrOptions.thresholds;
+ t = withSuffixOrOptions.thresholds;
if (typeof t === 'object') {
// Fill in missing keys with the current values
th = Object.assign({}, thresholds, t);
}
}
- var locale = this.localeData();
- var output = relativeTime(this, !withSuffix, th, locale);
+ locale = this.localeData();
+ output = relativeTime(this, !withSuffix, th, locale);
if (withSuffix) {
output = locale.pastFuture(+this, output);
return this.localeData().invalidDate();
}
- var seconds = abs(this._milliseconds) / 1000;
- var days = abs(this._days);
- var months = abs(this._months);
- var minutes, hours, years;
+ var seconds = abs(this._milliseconds) / 1000,
+ days = abs(this._days),
+ months = abs(this._months),
+ minutes, hours, years, s, total = this.asSeconds(),
+ totalSign, ymSign, daysSign, hmsSign;
+
+ if (!total) {
+ // this is the same as C#'s (Noda) and python (isodate)...
+ // but not other JS (goog.date)
+ return 'P0D';
+ }
// 3600 seconds -> 60 minutes -> 1 hour
minutes = absFloor(seconds / 60);
// inspired by https://github.com/dordille/moment-isoduration/blob/master/moment.isoduration.js
- var Y = years;
- var M = months;
- var D = days;
- var h = hours;
- var m = minutes;
- var s = seconds ? seconds.toFixed(3).replace(/\.?0+$/, '') : '';
- var total = this.asSeconds();
-
- if (!total) {
- // this is the same as C#'s (Noda) and python (isodate)...
- // but not other JS (goog.date)
- return 'P0D';
- }
+ s = seconds ? seconds.toFixed(3).replace(/\.?0+$/, '') : '';
- var totalSign = total < 0 ? '-' : '';
- var ymSign = sign(this._months) !== sign(total) ? '-' : '';
- var daysSign = sign(this._days) !== sign(total) ? '-' : '';
- var hmsSign = sign(this._milliseconds) !== sign(total) ? '-' : '';
+ totalSign = total < 0 ? '-' : '';
+ ymSign = sign(this._months) !== sign(total) ? '-' : '';
+ daysSign = sign(this._days) !== sign(total) ? '-' : '';
+ hmsSign = sign(this._milliseconds) !== sign(total) ? '-' : '';
return totalSign + 'P' +
- (Y ? ymSign + Y + 'Y' : '') +
- (M ? ymSign + M + 'M' : '') +
- (D ? daysSign + D + 'D' : '') +
- ((h || m || s) ? 'T' : '') +
- (h ? hmsSign + h + 'H' : '') +
- (m ? hmsSign + m + 'M' : '') +
- (s ? hmsSign + s + 'S' : '');
+ (years ? ymSign + years + 'Y' : '') +
+ (months ? ymSign + months + 'M' : '') +
+ (days ? daysSign + days + 'D' : '') +
+ ((hours || minutes || seconds) ? 'T' : '') +
+ (hours ? hmsSign + hours + 'H' : '') +
+ (minutes ? hmsSign + minutes + 'M' : '') +
+ (seconds ? hmsSign + s + 'S' : '');
}
import hasOwnProp from '../utils/has-own-prop';
import toInt from '../utils/to-int';
import indexOf from '../utils/index-of';
-import {Duration} from './constructor';
import {createDuration} from './create';
var ordering = ['year', 'quarter', 'month', 'week', 'day', 'hour', 'minute', 'second', 'millisecond'];
export default function isDurationValid(m) {
- for (var key in m) {
+ var key, unitHasDecimal = false, i;
+ for (key in m) {
if (hasOwnProp(m, key) && !(indexOf.call(ordering, key) !== -1 && (m[key] == null || !isNaN(m[key])))) {
return false;
}
}
- var unitHasDecimal = false;
- for (var i = 0; i < ordering.length; ++i) {
+ for (i = 0; i < ordering.length; ++i) {
if (m[ordering[i]]) {
if (unitHasDecimal) {
return false; // only allow non-integers for smallest unit
import zeroFill from '../utils/zero-fill';
import isFunction from '../utils/is-function';
-export var formattingTokens = /(\[[^\[]*\])|(\\)?([Hh]mm(ss)?|Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|Qo?|YYYYYY|YYYYY|YYYY|YY|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|kk?|mm?|ss?|S{1,9}|x|X|zz?|ZZ?|.)/g;
-
-var localFormattingTokens = /(\[[^\[]*\])|(\\)?(LTS|LT|LL?L?L?|l{1,4})/g;
-
-var formatFunctions = {};
-
-export var formatTokenFunctions = {};
+var formattingTokens = /(\[[^\[]*\])|(\\)?([Hh]mm(ss)?|Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|Qo?|YYYYYY|YYYYY|YYYY|YY|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|kk?|mm?|ss?|S{1,9}|x|X|zz?|ZZ?|.)/g,
+ localFormattingTokens = /(\[[^\[]*\])|(\\)?(LTS|LT|LL?L?L?|l{1,4})/g,
+ formatFunctions = {},
+ formatTokenFunctions = {};
+
+export {
+ formattingTokens,
+ formatTokenFunctions
+}
// token: 'M'
// padded: ['MM', 2]
import { createUTC } from '../create/utc';
function get (format, index, field, setter) {
- var locale = getLocale();
- var utc = createUTC().set(setter, index);
+ var locale = getLocale(),
+ utc = createUTC().set(setter, index);
return locale[field](utc, format);
}
return get(format, index, field, 'month');
}
- var i;
- var out = [];
+ var i,
+ out = [];
for (i = 0; i < 12; i++) {
out[i] = get(format, i, field, 'month');
}
}
var locale = getLocale(),
- shift = localeSorted ? locale._week.dow : 0;
+ shift = localeSorted ? locale._week.dow : 0,
+ i, out = [];
if (index != null) {
return get(format, (index + shift) % 7, field, 'day');
}
- var i;
- var out = [];
for (i = 0; i < 7; i++) {
out[i] = get(format, (i + shift) % 7, field, 'day');
}
import { baseConfig } from './base-config';
// internal storage for locale config files
-var locales = {};
-var localeFamilies = {};
-var globalLocale;
+var locales = {},
+ localeFamilies = {},
+ globalLocale;
function commonPrefix(arr1, arr2) {
var i, minl = Math.min(arr1.length, arr2.length);
}
function loadLocale(name) {
- var oldLocale = null;
+ var oldLocale = null, aliasedRequire;
// TODO: Find a better way to register and load all the locales in Node
if (locales[name] === undefined && (typeof module !== 'undefined') &&
module && module.exports) {
try {
oldLocale = globalLocale._abbr;
- var aliasedRequire = require;
+ aliasedRequire = require;
aliasedRequire((typeof __dirname !== undefined ? __dirname : '.') + '/locale/' + name);
getSetGlobalLocale(oldLocale);
} catch (e) {
-export var defaultOrdinal = '%d';
-export var defaultDayOfMonthOrdinalParse = /\d{1,2}/;
+var defaultOrdinal = '%d',
+ defaultDayOfMonthOrdinalParse = /\d{1,2}/;
+
+export {
+ defaultOrdinal,
+ defaultDayOfMonthOrdinalParse
+}
export function ordinal (number) {
return this._ordinal.replace('%d', number);
}
}
-export var add = createAdder(1, 'add');
-export var subtract = createAdder(-1, 'subtract');
+export var add = createAdder(1, 'add'),
+ subtract = createAdder(-1, 'subtract');
// Getting start-of-today depends on whether we're local/utc/offset or not.
var now = time || createLocal(),
sod = cloneWithOffset(now, this).startOf('day'),
- format = hooks.calendarFormat(this, sod) || 'sameElse';
+ format = hooks.calendarFormat(this, sod) || 'sameElse',
- var output = formats && (isFunction(formats[format]) ? formats[format].call(this, now) : formats[format]);
+ output = formats && (isFunction(formats[format]) ? formats[format].call(this, now) : formats[format]);
return this.format(output || this.localeData().calendar(format, this, createLocal(now)));
}
// Plugins that add properties should also add the key here (null value),
// so we can properly clone ourselves.
-var momentProperties = hooks.momentProperties = [];
+var momentProperties = hooks.momentProperties = [],
+ updateInProgress = false;
export function copyConfig(to, from) {
var i, prop, val;
return to;
}
-var updateInProgress = false;
-
// Moment prototype object
export function Moment(config) {
copyConfig(this, config);
export function diff (input, units, asFloat) {
var that,
zoneDelta,
- delta, output;
+ output;
if (!this.isValid()) {
return NaN;
if (!this.isValid()) {
return null;
}
- var utc = keepOffset !== true;
- var m = utc ? this.clone().utc() : this;
+ var utc = keepOffset !== true,
+ m = utc ? this.clone().utc() : this;
if (m.year() < 0 || m.year() > 9999) {
return formatMoment(m, utc ? 'YYYYYY-MM-DD[T]HH:mm:ss.SSS[Z]' : 'YYYYYY-MM-DD[T]HH:mm:ss.SSSZ');
}
if (!this.isValid()) {
return 'moment.invalid(/* ' + this._i + ' */)';
}
- var func = 'moment';
- var zone = '';
+ var func = 'moment',
+ zone = '', prefix, year, datetime, suffix;
if (!this.isLocal()) {
func = this.utcOffset() === 0 ? 'moment.utc' : 'moment.parseZone';
zone = 'Z';
}
- var prefix = '[' + func + '("]';
- var year = (0 <= this.year() && this.year() <= 9999) ? 'YYYY' : 'YYYYYY';
- var datetime = '-MM-DD[T]HH:mm:ss.SSS';
- var suffix = zone + '[")]';
+ prefix = '[' + func + '("]';
+ year = (0 <= this.year() && this.year() <= 9999) ? 'YYYY' : 'YYYYYY';
+ datetime = '-MM-DD[T]HH:mm:ss.SSS';
+ suffix = zone + '[")]';
return this.format(prefix + year + datetime + suffix);
}
export function stringSet (units, value) {
if (typeof units === 'object') {
units = normalizeObjectUnits(units);
- var prioritized = getPrioritizedUnits(units);
- for (var i = 0; i < prioritized.length; i++) {
+ var prioritized = getPrioritizedUnits(units), i;
+ for (i = 0; i < prioritized.length; i++) {
this[prioritized[i].unit](units[prioritized[i].unit]);
}
} else {
return createInvalid();
}
}
-);
-
-export var prototypeMax = deprecate(
- 'moment().max is deprecated, use moment.min instead. http://momentjs.com/guides/#/warnings/min-max/',
- function () {
- var other = createLocal.apply(null, arguments);
- if (this.isValid() && other.isValid()) {
- return other > this ? this : other;
- } else {
- return createInvalid();
+),
+ prototypeMax = deprecate(
+ 'moment().max is deprecated, use moment.min instead. http://momentjs.com/guides/#/warnings/min-max/',
+ function () {
+ var other = createLocal.apply(null, arguments);
+ if (this.isValid() && other.isValid()) {
+ return other > this ? this : other;
+ } else {
+ return createInvalid();
+ }
}
- }
-);
+ );
// 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.
var proto = Moment.prototype;
import { add, subtract } from './add-subtract';
-import { calendar, getCalendarFormat } from './calendar';
+import { calendar } from './calendar';
import { clone } from './clone';
import { isBefore, isBetween, isSame, isAfter, isSameOrAfter, isSameOrBefore } from './compare';
import { diff } from './diff';
import { normalizeUnits } from '../units/aliases';
import { hooks } from '../utils/hooks';
-var MS_PER_SECOND = 1000;
-var MS_PER_MINUTE = 60 * MS_PER_SECOND;
-var MS_PER_HOUR = 60 * MS_PER_MINUTE;
-var MS_PER_400_YEARS = (365 * 400 + 97) * 24 * MS_PER_HOUR;
+var MS_PER_SECOND = 1000,
+ MS_PER_MINUTE = 60 * MS_PER_SECOND,
+ MS_PER_HOUR = 60 * MS_PER_MINUTE,
+ MS_PER_400_YEARS = (365 * 400 + 97) * 24 * MS_PER_HOUR;
// actual modulo - handles negative numbers (for dates before 1970):
function mod(dividend, divisor) {
}
export function startOf (units) {
- var time;
+ var time, startOfDate;
units = normalizeUnits(units);
if (units === undefined || units === 'millisecond' || !this.isValid()) {
return this;
}
- var startOfDate = this._isUTC ? utcStartOfDate : localStartOfDate;
+ startOfDate = this._isUTC ? utcStartOfDate : localStartOfDate;
switch (units) {
case 'year':
}
export function endOf (units) {
- var time;
+ var time, startOfDate;
units = normalizeUnits(units);
if (units === undefined || units === 'millisecond' || !this.isValid()) {
return this;
}
- var startOfDate = this._isUTC ? utcStartOfDate : localStartOfDate;
+ startOfDate = this._isUTC ? utcStartOfDate : localStartOfDate;
switch (units) {
case 'year':
-export var match1 = /\d/; // 0 - 9
-export var match2 = /\d\d/; // 00 - 99
-export var match3 = /\d{3}/; // 000 - 999
-export var match4 = /\d{4}/; // 0000 - 9999
-export var match6 = /[+-]?\d{6}/; // -999999 - 999999
-export var match1to2 = /\d\d?/; // 0 - 99
-export var match3to4 = /\d\d\d\d?/; // 999 - 9999
-export var match5to6 = /\d\d\d\d\d\d?/; // 99999 - 999999
-export var match1to3 = /\d{1,3}/; // 0 - 999
-export var match1to4 = /\d{1,4}/; // 0 - 9999
-export var match1to6 = /[+-]?\d{1,6}/; // -999999 - 999999
-
-export var matchUnsigned = /\d+/; // 0 - inf
-export var matchSigned = /[+-]?\d+/; // -inf - inf
-
-export var matchOffset = /Z|[+-]\d\d:?\d\d/gi; // +00:00 -00:00 +0000 -0000 or Z
-export var matchShortOffset = /Z|[+-]\d\d(?::?\d\d)?/gi; // +00 -00 +00:00 -00:00 +0000 -0000 or Z
-
-export var matchTimestamp = /[+-]?\d+(\.\d{1,3})?/; // 123456789 123456789.123
-
-// any word (or two) characters or numbers including two/three word month in arabic.
-// includes scottish gaelic two word and hyphenated months
-export var matchWord = /[0-9]{0,256}['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFF07\uFF10-\uFFEF]{1,256}|[\u0600-\u06FF\/]{1,256}(\s*?[\u0600-\u06FF]{1,256}){1,2}/i;
-
+var match1 = /\d/, // 0 - 9
+ match2 = /\d\d/, // 00 - 99
+ match3 = /\d{3}/, // 000 - 999
+ match4 = /\d{4}/, // 0000 - 9999
+ match6 = /[+-]?\d{6}/, // -999999 - 999999
+ match1to2 = /\d\d?/, // 0 - 99
+ match3to4 = /\d\d\d\d?/, // 999 - 9999
+ match5to6 = /\d\d\d\d\d\d?/, // 99999 - 999999
+ match1to3 = /\d{1,3}/, // 0 - 999
+ match1to4 = /\d{1,4}/, // 0 - 9999
+ match1to6 = /[+-]?\d{1,6}/, // -999999 - 999999
+
+ matchUnsigned = /\d+/, // 0 - inf
+ matchSigned = /[+-]?\d+/, // -inf - inf
+
+ matchOffset = /Z|[+-]\d\d:?\d\d/gi, // +00:00 -00:00 +0000 -0000 or Z
+ matchShortOffset = /Z|[+-]\d\d(?::?\d\d)?/gi, // +00 -00 +00:00 -00:00 +0000 -0000 or Z
+
+ matchTimestamp = /[+-]?\d+(\.\d{1,3})?/, // 123456789 123456789.123
+
+ // any word (or two) characters or numbers including two/three word month in arabic.
+ // includes scottish gaelic two word and hyphenated months
+ matchWord = /[0-9]{0,256}['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFF07\uFF10-\uFFEF]{1,256}|[\u0600-\u06FF\/]{1,256}(\s*?[\u0600-\u06FF]{1,256}){1,2}/i,
+ regexes
+
+export {
+ match1, match2, match3, match4, match6, match1to2, match3to4, match5to6,
+ match1to3, match1to4, match1to6, matchUnsigned, matchSigned, matchOffset,
+ matchShortOffset, matchTimestamp, matchWord
+}
import hasOwnProp from '../utils/has-own-prop';
import isFunction from '../utils/is-function';
-var regexes = {};
+regexes = {};
export function addRegexToken (token, regex, strictRegex) {
regexes[token] = isFunction(regex) ? regex : function (isStrict, localeData) {
-export var YEAR = 0;
-export var MONTH = 1;
-export var DATE = 2;
-export var HOUR = 3;
-export var MINUTE = 4;
-export var SECOND = 5;
-export var MILLISECOND = 6;
-export var WEEK = 7;
-export var WEEKDAY = 8;
+export var YEAR = 0,
+ MONTH = 1,
+ DATE = 2,
+ HOUR = 3,
+ MINUTE = 4,
+ SECOND = 5,
+ MILLISECOND = 6,
+ WEEK = 7,
+ WEEKDAY = 8;
return ws.slice(n, 7).concat(ws.slice(0, n));
}
-export var defaultLocaleWeekdays = 'Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday'.split('_');
+var defaultLocaleWeekdays = 'Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday'.split('_'),
+ defaultLocaleWeekdaysShort = 'Sun_Mon_Tue_Wed_Thu_Fri_Sat'.split('_'),
+ defaultLocaleWeekdaysMin = 'Su_Mo_Tu_We_Th_Fr_Sa'.split('_'),
+ defaultWeekdaysRegex = matchWord,
+ defaultWeekdaysShortRegex = matchWord,
+ defaultWeekdaysMinRegex = matchWord;
+
+export {
+ defaultLocaleWeekdays,
+ defaultLocaleWeekdaysShort,
+ defaultLocaleWeekdaysMin
+}
+
export function localeWeekdays (m, format) {
var weekdays = isArray(this._weekdays) ? this._weekdays :
this._weekdays[(m && m !== true && this._weekdays.isFormat.test(format)) ? 'format' : 'standalone'];
: (m) ? weekdays[m.day()] : weekdays;
}
-export var defaultLocaleWeekdaysShort = 'Sun_Mon_Tue_Wed_Thu_Fri_Sat'.split('_');
export function localeWeekdaysShort (m) {
return (m === true) ? shiftWeekdays(this._weekdaysShort, this._week.dow)
: (m) ? this._weekdaysShort[m.day()] : this._weekdaysShort;
}
-export var defaultLocaleWeekdaysMin = 'Su_Mo_Tu_We_Th_Fr_Sa'.split('_');
export function localeWeekdaysMin (m) {
return (m === true) ? shiftWeekdays(this._weekdaysMin, this._week.dow)
: (m) ? this._weekdaysMin[m.day()] : this._weekdaysMin;
}
}
-var defaultWeekdaysRegex = matchWord;
export function weekdaysRegex (isStrict) {
if (this._weekdaysParseExact) {
if (!hasOwnProp(this, '_weekdaysRegex')) {
}
}
-var defaultWeekdaysShortRegex = matchWord;
export function weekdaysShortRegex (isStrict) {
if (this._weekdaysParseExact) {
if (!hasOwnProp(this, '_weekdaysRegex')) {
}
}
-var defaultWeekdaysMinRegex = matchWord;
export function weekdaysMinRegex (isStrict) {
if (this._weekdaysParseExact) {
if (!hasOwnProp(this, '_weekdaysRegex')) {
getParsingFlags(config).bigHour = true;
});
addParseToken('hmmss', function (input, array, config) {
- var pos1 = input.length - 4;
- var pos2 = input.length - 2;
+ var pos1 = input.length - 4,
+ pos2 = input.length - 2;
array[HOUR] = toInt(input.substr(0, pos1));
array[MINUTE] = toInt(input.substr(pos1, 2));
array[SECOND] = toInt(input.substr(pos2));
array[MINUTE] = toInt(input.substr(pos));
});
addParseToken('Hmmss', function (input, array, config) {
- var pos1 = input.length - 4;
- var pos2 = input.length - 2;
+ var pos1 = input.length - 4,
+ pos2 = input.length - 2;
array[HOUR] = toInt(input.substr(0, pos1));
array[MINUTE] = toInt(input.substr(pos1, 2));
array[SECOND] = toInt(input.substr(pos2));
return ((input + '').toLowerCase().charAt(0) === 'p');
}
-export var defaultLocaleMeridiemParse = /[ap]\.?m?\.?/i;
+export var defaultLocaleMeridiemParse = /[ap]\.?m?\.?/i,
+ // Setting the hour should keep the time, because the user explicitly
+ // specified which hour they want. So trying to maintain the same hour (in
+ // a new timezone) makes sense. Adding/subtracting hours does not follow
+ // this rule.
+ getSetHour = makeGetSet('Hours', true);
+
export function localeMeridiem (hours, minutes, isLower) {
if (hours > 11) {
return isLower ? 'pm' : 'PM';
return isLower ? 'am' : 'AM';
}
}
-
-
-// MOMENTS
-
-// Setting the hour should keep the time, because the user explicitly
-// specified which hour they want. So trying to maintain the same hour (in
-// a new timezone) makes sense. Adding/subtracting hours does not follow
-// this rule.
-export var getSetHour = makeGetSet('Hours', true);
addRegexToken('SS', match1to3, match2);
addRegexToken('SSS', match1to3, match3);
-var token;
+var token, getSetMillisecond;
for (token = 'SSSS'; token.length <= 9; token += 'S') {
addRegexToken(token, matchUnsigned);
}
for (token = 'S'; token.length <= 9; token += 'S') {
addParseToken(token, parseMs);
}
-// MOMENTS
-export var getSetMillisecond = makeGetSet('Milliseconds', false);
+getSetMillisecond = makeGetSet('Milliseconds', false);
+
+export {
+ getSetMillisecond
+}
// LOCALES
-var MONTHS_IN_FORMAT = /D[oD]?(\[[^\[\]]*\]|\s)+MMMM?/;
-export var defaultLocaleMonths = 'January_February_March_April_May_June_July_August_September_October_November_December'.split('_');
+var defaultLocaleMonths = 'January_February_March_April_May_June_July_August_September_October_November_December'.split('_'),
+ defaultLocaleMonthsShort = 'Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec'.split('_'),
+ MONTHS_IN_FORMAT = /D[oD]?(\[[^\[\]]*\]|\s)+MMMM?/,
+ defaultMonthsShortRegex = matchWord,
+ defaultMonthsRegex = matchWord;
+
+export {
+ defaultLocaleMonths,
+ defaultLocaleMonthsShort
+}
+
export function localeMonths (m, format) {
if (!m) {
return isArray(this._months) ? this._months :
this._months[(this._months.isFormat || MONTHS_IN_FORMAT).test(format) ? 'format' : 'standalone'][m.month()];
}
-export var defaultLocaleMonthsShort = 'Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec'.split('_');
export function localeMonthsShort (m, format) {
if (!m) {
return isArray(this._monthsShort) ? this._monthsShort :
return daysInMonth(this.year(), this.month());
}
-var defaultMonthsShortRegex = matchWord;
export function monthsShortRegex (isStrict) {
if (this._monthsParseExact) {
if (!hasOwnProp(this, '_monthsRegex')) {
}
}
-var defaultMonthsRegex = matchWord;
export function monthsRegex (isStrict) {
if (this._monthsParseExact) {
if (!hasOwnProp(this, '_monthsRegex')) {
function offset (token, separator) {
addFormatToken(token, 0, 0, function () {
- var offset = this.utcOffset();
- var sign = '+';
+ var offset = this.utcOffset(),
+ sign = '+';
if (offset < 0) {
offset = -offset;
sign = '-';
var chunkOffset = /([\+\-]|\d\d)/gi;
function offsetFromString(matcher, string) {
- var matches = (string || '').match(matcher);
+ var matches = (string || '').match(matcher), chunk, parts, minutes;
if (matches === null) {
return null;
}
- var chunk = matches[matches.length - 1] || [];
- var parts = (chunk + '').match(chunkOffset) || ['-', 0, 0];
- var minutes = +(parts[1] * 60) + toInt(parts[2]);
+ chunk = matches[matches.length - 1] || [];
+ parts = (chunk + '').match(chunkOffset) || ['-', 0, 0];
+ minutes = +(parts[1] * 60) + toInt(parts[2]);
return minutes === 0 ?
- 0 :
- parts[0] === '+' ? minutes : -minutes;
+ 0 :
+ parts[0] === '+' ? minutes : -minutes;
}
// Return a moment from input, that is local/utc/zone equivalent to model.
return this._isDSTShifted;
}
- var c = {};
+ var c = {}, other;
copyConfig(c, this);
c = prepareConfig(c);
if (c._a) {
- var other = c._isUTC ? createUTC(c._a) : createLocal(c._a);
+ other = c._isUTC ? createUTC(c._a) : createLocal(c._a);
this._isDSTShifted = this.isValid() &&
compareArrays(c._a, other.toArray()) > 0;
} else {
}
export function getPrioritizedUnits(unitsObj) {
- var units = [];
- for (var u in unitsObj) {
+ var units = [], u;
+ for (u in unitsObj) {
if (hasOwnProp(unitsObj, u)) {
units.push({unit: u, priority: priorities[u]});
}
hooks.deprecationHandler(null, msg);
}
if (firstTime) {
- var args = [];
- var arg;
- for (var i = 0; i < arguments.length; i++) {
+ var args = [],
+ arg, i, key;
+ for (i = 0; i < arguments.length; i++) {
arg = '';
if (typeof arguments[i] === 'object') {
arg += '\n[' + i + '] ';
- for (var key in arguments[0]) {
+ for (key in arguments[0]) {
if (hasOwnProp(arguments[0], key)) {
arg += key + ': ' + arguments[0][key] + ', ';
}
import isObject from './is-object';
export default function isCalendarSpec(input) {
- var objectTest = isObject(input) && !isObjectEmpty(input);
+ var objectTest = isObject(input) && !isObjectEmpty(input),
- var propertyTest = false,
+ propertyTest = false,
properties = [
'sameDay',
'nextDay',
'nextWeek',
'lastWeek',
'sameElse'
- ];
+ ],
+ property;
- for (var property of properties) {
+
+ for (property of properties) {
propertyTest = propertyTest || hasOwnProp(input, property);
}
}
export function isMomentInputObject(input) {
- var objectTest = isObject(input) && !isObjectEmpty(input);
+ var objectTest = isObject(input) && !isObjectEmpty(input),
- var propertyTest = false,
+ propertyTest = false,
properties = [
'years',
'year',
'milliseconds',
'millisecond',
'ms'
- ];
+ ],
+ property;
- for (var property of properties) {
+ for (property of properties) {
propertyTest = propertyTest || hasOwnProp(input, property);
}
+import hasOwnProp from './has-own-prop';
+
export default function isObjectEmpty(obj) {
if (Object.getOwnPropertyNames) {
return (Object.getOwnPropertyNames(obj).length === 0);
} else {
var k;
for (k in obj) {
- if (obj.hasOwnProperty(k)) {
+ if (hasOwnProp(obj, k)) {
return false;
}
}
some = Array.prototype.some;
} else {
some = function (fun) {
- var t = Object(this);
- var len = t.length >>> 0;
+ var t = Object(this),
+ len = t.length >>> 0,
+ i;
- for (var i = 0; i < len; i++) {
+ for (i = 0; i < len; i++) {
if (i in t && fun.call(this, t[i], i, t)) {
return true;
}
import moment from '../moment';
var months = 'leden_únor_březen_duben_květen_červen_červenec_srpen_září_říjen_listopad_prosinec'.split('_'),
- monthsShort = 'led_úno_bře_dub_kvě_čvn_čvc_srp_zář_říj_lis_pro'.split('_');
+ monthsShort = 'led_úno_bře_dub_kvě_čvn_čvc_srp_zář_říj_lis_pro'.split('_'),
-var monthsParse = [/^led/i, /^úno/i, /^bře/i, /^dub/i, /^kvě/i, /^(čvn|červen$|června)/i, /^(čvc|červenec|července)/i, /^srp/i, /^zář/i, /^říj/i, /^lis/i, /^pro/i];
+ monthsParse = [/^led/i, /^úno/i, /^bře/i, /^dub/i, /^kvě/i, /^(čvn|červen$|června)/i, /^(čvc|červenec|července)/i, /^srp/i, /^zář/i, /^říj/i, /^lis/i, /^pro/i],
// NOTE: 'červen' is substring of 'červenec'; therefore 'červenec' must precede 'červen' in the regex to be fully matched.
// Otherwise parser matches '1. červenec' as '1. červen' + 'ec'.
-var monthsRegex = /^(leden|únor|březen|duben|květen|červenec|července|červen|června|srpen|září|říjen|listopad|prosinec|led|úno|bře|dub|kvě|čvn|čvc|srp|zář|říj|lis|pro)/i;
+ monthsRegex = /^(leden|únor|březen|duben|květen|červenec|července|červen|června|srpen|září|říjen|listopad|prosinec|led|úno|bře|dub|kvě|čvn|čvc|srp|zář|říj|lis|pro)/i;
function plural(n) {
return (n > 1) && (n < 5) && (~~(n / 10) !== 1);
} else {
return result + 'sekundami';
}
- break;
case 'm': // a minute / in a minute / a minute ago
return withoutSuffix ? 'minuta' : (isFuture ? 'minutu' : 'minutou');
case 'mm': // 9 minutes / in 9 minutes / 9 minutes ago
} else {
return result + 'minutami';
}
- break;
case 'h': // an hour / in an hour / an hour ago
return withoutSuffix ? 'hodina' : (isFuture ? 'hodinu' : 'hodinou');
case 'hh': // 9 hours / in 9 hours / 9 hours ago
} else {
return result + 'hodinami';
}
- break;
case 'd': // a day / in a day / a day ago
return (withoutSuffix || isFuture) ? 'den' : 'dnem';
case 'dd': // 9 days / in 9 days / 9 days ago
} else {
return result + 'dny';
}
- break;
case 'M': // a month / in a month / a month ago
return (withoutSuffix || isFuture) ? 'měsíc' : 'měsícem';
case 'MM': // 9 months / in 9 months / 9 months ago
} else {
return result + 'měsíci';
}
- break;
case 'y': // a year / in a year / a year ago
return (withoutSuffix || isFuture) ? 'rok' : 'rokem';
case 'yy': // 9 years / in 9 years / 9 years ago
} else {
return result + 'lety';
}
- break;
}
}
import moment from '../moment';
var monthsShortDot = 'ene._feb._mar._abr._may._jun._jul._ago._sep._oct._nov._dic.'.split('_'),
- monthsShort = 'ene_feb_mar_abr_may_jun_jul_ago_sep_oct_nov_dic'.split('_');
+ monthsShort = 'ene_feb_mar_abr_may_jun_jul_ago_sep_oct_nov_dic'.split('_'),
-var monthsParse = [/^ene/i, /^feb/i, /^mar/i, /^abr/i, /^may/i, /^jun/i, /^jul/i, /^ago/i, /^sep/i, /^oct/i, /^nov/i, /^dic/i];
-var monthsRegex = /^(enero|febrero|marzo|abril|mayo|junio|julio|agosto|septiembre|octubre|noviembre|diciembre|ene\.?|feb\.?|mar\.?|abr\.?|may\.?|jun\.?|jul\.?|ago\.?|sep\.?|oct\.?|nov\.?|dic\.?)/i;
+ monthsParse = [/^ene/i, /^feb/i, /^mar/i, /^abr/i, /^may/i, /^jun/i, /^jul/i, /^ago/i, /^sep/i, /^oct/i, /^nov/i, /^dic/i],
+ monthsRegex = /^(enero|febrero|marzo|abril|mayo|junio|julio|agosto|septiembre|octubre|noviembre|diciembre|ene\.?|feb\.?|mar\.?|abr\.?|may\.?|jun\.?|jul\.?|ago\.?|sep\.?|oct\.?|nov\.?|dic\.?)/i;
export default moment.defineLocale('es-do', {
months : 'enero_febrero_marzo_abril_mayo_junio_julio_agosto_septiembre_octubre_noviembre_diciembre'.split('_'),
import moment from '../moment';
var monthsShortDot = 'ene._feb._mar._abr._may._jun._jul._ago._sep._oct._nov._dic.'.split('_'),
- monthsShort = 'ene_feb_mar_abr_may_jun_jul_ago_sep_oct_nov_dic'.split('_');
+ monthsShort = 'ene_feb_mar_abr_may_jun_jul_ago_sep_oct_nov_dic'.split('_'),
-var monthsParse = [/^ene/i, /^feb/i, /^mar/i, /^abr/i, /^may/i, /^jun/i, /^jul/i, /^ago/i, /^sep/i, /^oct/i, /^nov/i, /^dic/i];
-var monthsRegex = /^(enero|febrero|marzo|abril|mayo|junio|julio|agosto|septiembre|octubre|noviembre|diciembre|ene\.?|feb\.?|mar\.?|abr\.?|may\.?|jun\.?|jul\.?|ago\.?|sep\.?|oct\.?|nov\.?|dic\.?)/i;
+ monthsParse = [/^ene/i, /^feb/i, /^mar/i, /^abr/i, /^may/i, /^jun/i, /^jul/i, /^ago/i, /^sep/i, /^oct/i, /^nov/i, /^dic/i],
+ monthsRegex = /^(enero|febrero|marzo|abril|mayo|junio|julio|agosto|septiembre|octubre|noviembre|diciembre|ene\.?|feb\.?|mar\.?|abr\.?|may\.?|jun\.?|jul\.?|ago\.?|sep\.?|oct\.?|nov\.?|dic\.?)/i;
export default moment.defineLocale('es-us', {
months : 'enero_febrero_marzo_abril_mayo_junio_julio_agosto_septiembre_octubre_noviembre_diciembre'.split('_'),
import moment from '../moment';
var monthsShortDot = 'ene._feb._mar._abr._may._jun._jul._ago._sep._oct._nov._dic.'.split('_'),
- monthsShort = 'ene_feb_mar_abr_may_jun_jul_ago_sep_oct_nov_dic'.split('_');
+ monthsShort = 'ene_feb_mar_abr_may_jun_jul_ago_sep_oct_nov_dic'.split('_'),
-var monthsParse = [/^ene/i, /^feb/i, /^mar/i, /^abr/i, /^may/i, /^jun/i, /^jul/i, /^ago/i, /^sep/i, /^oct/i, /^nov/i, /^dic/i];
-var monthsRegex = /^(enero|febrero|marzo|abril|mayo|junio|julio|agosto|septiembre|octubre|noviembre|diciembre|ene\.?|feb\.?|mar\.?|abr\.?|may\.?|jun\.?|jul\.?|ago\.?|sep\.?|oct\.?|nov\.?|dic\.?)/i;
+ monthsParse = [/^ene/i, /^feb/i, /^mar/i, /^abr/i, /^may/i, /^jun/i, /^jul/i, /^ago/i, /^sep/i, /^oct/i, /^nov/i, /^dic/i],
+ monthsRegex = /^(enero|febrero|marzo|abril|mayo|junio|julio|agosto|septiembre|octubre|noviembre|diciembre|ene\.?|feb\.?|mar\.?|abr\.?|may\.?|jun\.?|jul\.?|ago\.?|sep\.?|oct\.?|nov\.?|dic\.?)/i;
export default moment.defineLocale('es', {
months : 'enero_febrero_marzo_abril_mayo_junio_julio_agosto_septiembre_octubre_noviembre_diciembre'.split('_'),
var months = [
'Eanáir', 'Feabhra', 'Márta', 'Aibreán', 'Bealtaine', 'Meitheamh', 'Iúil', 'Lúnasa', 'Meán Fómhair', 'Deireadh Fómhair', 'Samhain', 'Nollaig'
-];
-var monthsShort = ['Ean', 'Feabh', 'Márt', 'Aib', 'Beal', 'Meith', 'Iúil', 'Lún', 'M.F.', 'D.F.', 'Samh', 'Noll'];
-var weekdays = ['Dé Domhnaigh', 'Dé Luain', 'Dé Máirt', 'Dé Céadaoin', 'Déardaoin', 'Dé hAoine', 'Dé Sathairn'];
-var weekdaysShort = ['Domh', 'Luan', 'Máirt', 'Céad', 'Déar', 'Aoine', 'Sath'];
-var weekdaysMin = ['Do', 'Lu', 'Má', 'Cé', 'Dé', 'A', 'Sa'];
+],
+ monthsShort = ['Ean', 'Feabh', 'Márt', 'Aib', 'Beal', 'Meith', 'Iúil', 'Lún', 'M.F.', 'D.F.', 'Samh', 'Noll'],
+ weekdays = ['Dé Domhnaigh', 'Dé Luain', 'Dé Máirt', 'Dé Céadaoin', 'Déardaoin', 'Dé hAoine', 'Dé Sathairn'],
+ weekdaysShort = ['Domh', 'Luan', 'Máirt', 'Céad', 'Déar', 'Aoine', 'Sath'],
+ weekdaysMin = ['Do', 'Lu', 'Má', 'Cé', 'Dé', 'A', 'Sa'];
export default moment.defineLocale('ga', {
months: months,
var months = [
'Am Faoilleach', 'An Gearran', 'Am Màrt', 'An Giblean', 'An Cèitean', 'An t-Ògmhios', 'An t-Iuchar', 'An Lùnastal', 'An t-Sultain', 'An Dàmhair', 'An t-Samhain', 'An Dùbhlachd'
-];
+],
-var monthsShort = ['Faoi', 'Gear', 'Màrt', 'Gibl', 'Cèit', 'Ògmh', 'Iuch', 'Lùn', 'Sult', 'Dàmh', 'Samh', 'Dùbh'];
+ monthsShort = ['Faoi', 'Gear', 'Màrt', 'Gibl', 'Cèit', 'Ògmh', 'Iuch', 'Lùn', 'Sult', 'Dàmh', 'Samh', 'Dùbh'],
-var weekdays = ['Didòmhnaich', 'Diluain', 'Dimàirt', 'Diciadain', 'Diardaoin', 'Dihaoine', 'Disathairne'];
+ weekdays = ['Didòmhnaich', 'Diluain', 'Dimàirt', 'Diciadain', 'Diardaoin', 'Dihaoine', 'Disathairne'],
-var weekdaysShort = ['Did', 'Dil', 'Dim', 'Dic', 'Dia', 'Dih', 'Dis'];
+ weekdaysShort = ['Did', 'Dil', 'Dim', 'Dic', 'Dia', 'Dih', 'Dis'],
-var weekdaysMin = ['Dò', 'Lu', 'Mà', 'Ci', 'Ar', 'Ha', 'Sa'];
+ weekdaysMin = ['Dò', 'Lu', 'Mà', 'Ci', 'Ar', 'Ha', 'Sa'];
export default moment.defineLocale('gd', {
months : months,
var weekEndings = 'vasárnap hétfőn kedden szerdán csütörtökön pénteken szombaton'.split(' ');
function translate(number, withoutSuffix, key, isFuture) {
- var num = number,
- suffix;
+ var num = number;
switch (key) {
case 's':
return (isFuture || withoutSuffix) ? 'néhány másodperc' : 'néhány másodperce';
import moment from '../moment';
var monthsShortWithDots = 'jan._feb._mrt._apr._mei_jun._jul._aug._sep._okt._nov._dec.'.split('_'),
- monthsShortWithoutDots = 'jan_feb_mrt_apr_mei_jun_jul_aug_sep_okt_nov_dec'.split('_');
+ monthsShortWithoutDots = 'jan_feb_mrt_apr_mei_jun_jul_aug_sep_okt_nov_dec'.split('_'),
-var monthsParse = [/^jan/i, /^feb/i, /^maart|mrt.?$/i, /^apr/i, /^mei$/i, /^jun[i.]?$/i, /^jul[i.]?$/i, /^aug/i, /^sep/i, /^okt/i, /^nov/i, /^dec/i];
-var monthsRegex = /^(januari|februari|maart|april|mei|ju[nl]i|augustus|september|oktober|november|december|jan\.?|feb\.?|mrt\.?|apr\.?|ju[nl]\.?|aug\.?|sep\.?|okt\.?|nov\.?|dec\.?)/i;
+ monthsParse = [/^jan/i, /^feb/i, /^maart|mrt.?$/i, /^apr/i, /^mei$/i, /^jun[i.]?$/i, /^jul[i.]?$/i, /^aug/i, /^sep/i, /^okt/i, /^nov/i, /^dec/i],
+ monthsRegex = /^(januari|februari|maart|april|mei|ju[nl]i|augustus|september|oktober|november|december|jan\.?|feb\.?|mrt\.?|apr\.?|ju[nl]\.?|aug\.?|sep\.?|okt\.?|nov\.?|dec\.?)/i;
export default moment.defineLocale('nl-be', {
months : 'januari_februari_maart_april_mei_juni_juli_augustus_september_oktober_november_december'.split('_'),
import moment from '../moment';
var monthsShortWithDots = 'jan._feb._mrt._apr._mei_jun._jul._aug._sep._okt._nov._dec.'.split('_'),
- monthsShortWithoutDots = 'jan_feb_mrt_apr_mei_jun_jul_aug_sep_okt_nov_dec'.split('_');
+ monthsShortWithoutDots = 'jan_feb_mrt_apr_mei_jun_jul_aug_sep_okt_nov_dec'.split('_'),
-var monthsParse = [/^jan/i, /^feb/i, /^maart|mrt.?$/i, /^apr/i, /^mei$/i, /^jun[i.]?$/i, /^jul[i.]?$/i, /^aug/i, /^sep/i, /^okt/i, /^nov/i, /^dec/i];
-var monthsRegex = /^(januari|februari|maart|april|mei|ju[nl]i|augustus|september|oktober|november|december|jan\.?|feb\.?|mrt\.?|apr\.?|ju[nl]\.?|aug\.?|sep\.?|okt\.?|nov\.?|dec\.?)/i;
+ monthsParse = [/^jan/i, /^feb/i, /^maart|mrt.?$/i, /^apr/i, /^mei$/i, /^jun[i.]?$/i, /^jul[i.]?$/i, /^aug/i, /^sep/i, /^okt/i, /^nov/i, /^dec/i],
+ monthsRegex = /^(januari|februari|maart|april|mei|ju[nl]i|augustus|september|oktober|november|december|jan\.?|feb\.?|mrt\.?|apr\.?|ju[nl]\.?|aug\.?|sep\.?|okt\.?|nov\.?|dec\.?)/i;
export default moment.defineLocale('nl', {
months : 'januari_februari_maart_april_mei_juni_juli_augustus_september_oktober_november_december'.split('_'),
'آڪٽوبر',
'نومبر',
'ڊسمبر'
-];
-var days = [
+],
+ days = [
'آچر',
'سومر',
'اڱارو',
} else {
return result + 'sekundami';
}
- break;
case 'm': // a minute / in a minute / a minute ago
return withoutSuffix ? 'minúta' : (isFuture ? 'minútu' : 'minútou');
case 'mm': // 9 minutes / in 9 minutes / 9 minutes ago
} else {
return result + 'minútami';
}
- break;
case 'h': // an hour / in an hour / an hour ago
return withoutSuffix ? 'hodina' : (isFuture ? 'hodinu' : 'hodinou');
case 'hh': // 9 hours / in 9 hours / 9 hours ago
} else {
return result + 'hodinami';
}
- break;
case 'd': // a day / in a day / a day ago
return (withoutSuffix || isFuture) ? 'deň' : 'dňom';
case 'dd': // 9 days / in 9 days / 9 days ago
} else {
return result + 'dňami';
}
- break;
case 'M': // a month / in a month / a month ago
return (withoutSuffix || isFuture) ? 'mesiac' : 'mesiacom';
case 'MM': // 9 months / in 9 months / 9 months ago
} else {
return result + 'mesiacmi';
}
- break;
case 'y': // a year / in a year / a year ago
return (withoutSuffix || isFuture) ? 'rok' : 'rokom';
case 'yy': // 9 years / in 9 years / 9 years ago
} else {
return result + 'rokmi';
}
- break;
}
}
'nominative': 'неділя_понеділок_вівторок_середа_четвер_п’ятниця_субота'.split('_'),
'accusative': 'неділю_понеділок_вівторок_середу_четвер_п’ятницю_суботу'.split('_'),
'genitive': 'неділі_понеділка_вівторка_середи_четверга_п’ятниці_суботи'.split('_')
- };
+ }, nounCase;
if (m === true) {
return weekdays['nominative'].slice(1, 7).concat(weekdays['nominative'].slice(0, 1));
return weekdays['nominative'];
}
- var nounCase = (/(\[[ВвУу]\]) ?dddd/).test(format) ?
+ nounCase = (/(\[[ВвУу]\]) ?dddd/).test(format) ?
'accusative' :
((/\[?(?:минулої|наступної)? ?\] ?dddd/).test(format) ?
'genitive' :
'اکتوبر',
'نومبر',
'دسمبر'
-];
-var days = [
+],
+ days = [
'اتوار',
'پیر',
'منگل',
});
test('localeData weekdays can localeSort', function (assert) {
- var weekdays = moment().localeData().weekdays();
- var weekdaysShort = moment().localeData().weekdaysShort();
- var weekdaysMin = moment().localeData().weekdaysMin();
- var shift = moment().localeData()._week.dow;
+ var weekdays = moment().localeData().weekdays(),
+ weekdaysShort = moment().localeData().weekdaysShort(),
+ weekdaysMin = moment().localeData().weekdaysMin(),
+ shift = moment().localeData()._week.dow;
assert.deepEqual(
moment().localeData().weekdays(true),
weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
--- /dev/null
+export default function hasOwnProp(a, b) {
+ return Object.prototype.hasOwnProperty.call(a, b);
+}
+import hasOwnProp from './has-own-prop';
+
export default function objectKeys(obj) {
if (Object.keys) {
return Object.keys(obj);
// IE8
var res = [], i;
for (i in obj) {
- if (obj.hasOwnProperty(i)) {
+ if (hasOwnProp(obj, i)) {
res.push(i);
}
}
test('weekdays strict parsing', function (assert) {
var m = moment('2015-01-01T12', moment.ISO_8601, true),
- enLocale = moment.localeData('en');
+ enLocale = moment.localeData('en'), i;
- for (var i = 0; i < 7; ++i) {
+ for (i = 0; i < 7; ++i) {
assert.equal(moment(enLocale.weekdays(m.day(i), ''), 'dddd', true).isValid(), true, 'parse weekday ' + i);
assert.equal(moment(enLocale.weekdaysShort(m.day(i), ''), 'ddd', true).isValid(), true, 'parse short weekday ' + i);
assert.equal(moment(enLocale.weekdaysMin(m.day(i), ''), 'dd', true).isValid(), true, 'parse min weekday ' + i);
});
test('from', function (assert) {
- var start = moment([2007, 1, 28]);
+ var start = moment([2007, 1, 28]), s, ss;
assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'چند ثانیه', '44 seconds = a few seconds');
assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'یک دقیقه', '45 seconds = a minute');
assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'یک دقیقه', '89 seconds = a minute');
assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '۲ سال', '548 days = 2 years');
assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'یک سال', '1 year = a year');
assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '۵ سال', '5 years = 5 years');
- var s = moment.relativeTimeThreshold('s');
- var ss = moment.relativeTimeThreshold('ss');
+
+ s = moment.relativeTimeThreshold('s');
+ ss = moment.relativeTimeThreshold('ss');
+
moment.relativeTimeThreshold('s', 60);
moment.relativeTimeThreshold('ss', 0);
assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), '۴۴ ثانیه', '44 seconds = 44 seconds');
assert.equal(moment(monthName, monthFormat).month(), monthNum, monthName + ' should be month ' + (monthNum + 1));
}
- for (var i = 0; i < 12; i++) {
- var testMonth = months[i].split(',');
+ var i, testMonth;
+ for (i = 0; i < 12; i++) {
+ testMonth = months[i].split(',');
+
equalTest(testMonth[0], 'MMM', i);
equalTest(testMonth[1], 'MMM', i);
equalTest(testMonth[0], 'MMMM', i);
});
test('format month', function (assert) {
- var expected = months;
- for (var i = 0; i < expected.length; i++) {
+ var expected = months, i;
+ for (i = 0; i < expected.length; i++) {
assert.equal(moment([2011, i, 1]).format('MMMM,MMM'), expected[i], expected[i]);
}
});
test('format week', function (assert) {
- var expected = ['Dé Domhnaigh Domh Do', 'Dé Luain Luan Lu', 'Dé Máirt Máirt Má', 'Dé Céadaoin Céad Cé', 'Déardaoin Déar Dé', 'Dé hAoine Aoine A', 'Dé Sathairn Sath Sa'];
- for (var i = 0; i < expected.length; i++) {
+ var expected = ['Dé Domhnaigh Domh Do', 'Dé Luain Luan Lu', 'Dé Máirt Máirt Má', 'Dé Céadaoin Céad Cé', 'Déardaoin Déar Dé', 'Dé hAoine Aoine A', 'Dé Sathairn Sath Sa'],
+ i;
+ for (i = 0; i < expected.length; i++) {
assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
}
});
assert.equal(moment(monthName, monthFormat).month(), monthNum, monthName + ' should be month ' + (monthNum + 1));
}
- for (var i = 0; i < 12; i++) {
- var testMonth = months[i].split(',');
+ var i, testMonth;
+ for (i = 0; i < 12; i++) {
+ testMonth = months[i].split(',');
+
equalTest(testMonth[0], 'MMM', i);
equalTest(testMonth[1], 'MMM', i);
equalTest(testMonth[0], 'MMMM', i);
});
test('format month', function (assert) {
- var expected = months;
- for (var i = 0; i < expected.length; i++) {
+ var expected = months, i;
+ for (i = 0; i < expected.length; i++) {
assert.equal(moment([2011, i, 1]).format('MMMM,MMM'), expected[i], expected[i]);
}
});
test('format week', function (assert) {
- var expected = ['Didòmhnaich Did Dò', 'Diluain Dil Lu', 'Dimàirt Dim Mà', 'Diciadain Dic Ci', 'Diardaoin Dia Ar', 'Dihaoine Dih Ha', 'Disathairne Dis Sa'];
- for (var i = 0; i < expected.length; i++) {
+ var expected = ['Didòmhnaich Did Dò', 'Diluain Dil Lu', 'Dimàirt Dim Mà', 'Diciadain Dic Ci', 'Diardaoin Dia Ar', 'Dihaoine Dih Ha', 'Disathairne Dis Sa'],
+ i;
+ for (i = 0; i < expected.length; i++) {
assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
}
});
});
test('calendar next week', function (assert) {
- var i, m;
- var dow = moment().day();
+ var i, m,
+ dow = moment().day();
for (i = 2; i < 7; i++) {
m = moment().add({d: i});
if (dow + i < 7) {
});
test('calendar last week', function (assert) {
- var i, m;
- var dow = moment().day();
+ var i, m,
+ dow = moment().day();
for (i = 2; i < 7; i++) {
m = moment().subtract({d: i});
if (dow < i) {
'آڪٽوبر',
'نومبر',
'ڊسمبر'
-];
-var days = [
+],
+ days = [
'آچر',
'سومر',
'اڱارو',
'اکتوبر',
'نومبر',
'دسمبر'
-];
-var days = [
+],
+ days = [
'اتوار',
'پیر',
'منگل',
});
test('extending calendar options', function (assert) {
- var calendarFormat = moment.calendarFormat;
+ var calendarFormat = moment.calendarFormat, a, b;
moment.calendarFormat = function (myMoment, now) {
- var diff = myMoment.diff(now, 'days', true);
- var nextMonth = now.clone().add(1, 'month');
+ var diff = myMoment.diff(now, 'days', true),
+ nextMonth = now.clone().add(1, 'month'),
- var retVal = diff < -6 ? 'sameElse' :
+ retVal = diff < -6 ? 'sameElse' :
diff < -1 ? 'lastWeek' :
diff < 0 ? 'lastDay' :
diff < 1 ? 'sameDay' :
sameElse : 'L'
}
});
- var a = moment('2016-01-01').add(28, 'days');
- var b = moment('2016-01-01').add(1, 'month');
+
+ a = moment('2016-01-01').add(28, 'days');
+ b = moment('2016-01-01').add(1, 'month');
+
try {
assert.equal(a.calendar('2016-01-01'), 'This month on the 29th', 'Ad hoc calendar format for this month');
assert.equal(b.calendar('2016-01-01'), 'Next month on the 1st', 'Ad hoc calendar format for next month');
});
test('calendar overload time - passing one parameter - a Moment', function (assert) {
- var a = moment().hours(13).minutes(23).seconds(45);
- var b = moment().add(1, 'd');
+ var a = moment().hours(13).minutes(23).seconds(45),
+ b = moment().add(1, 'd');
assert.equal(
a.calendar(b),
'Yesterday at 1:23 PM',
});
test('calendar overload time - passing one parameter - a Date', function (assert) {
- var a = moment().hours(13).minutes(23).seconds(45).subtract(1, 'd');
- var d = new Date();
+ var a = moment().hours(13).minutes(23).seconds(45).subtract(1, 'd'),
+ d = new Date();
assert.equal(
a.calendar(d),
'Yesterday at 1:23 PM',
});
test('calendar overload time - passing one parameter - a moment input object', function (assert) {
- var a = moment();
+ var a = moment(),
- var todayTime = new Date(),
+ todayTime = new Date(),
month = todayTime.getMonth() + 1,
day = todayTime.getDate(),
- year = todayTime.getFullYear();
+ year = todayTime.getFullYear(), expectedString;
month = month < 10 ? '0' + month.toString() : month;
day = day < 10 ? '0' + day.toString() : day;
- var expectedString = month + '/' + day + '/' + year;
+ expectedString = month + '/' + day + '/' + year;
assert.equal(
a.calendar({
import { module, test } from '../qunit';
import eachOwnProp from '../helpers/each-own-prop';
+import hasOwnProp from '../helpers/has-own-prop';
import moment from '../../moment';
module('create');
});
test('cloning moment should only copy own properties', function (assert) {
- assert.ok(!moment().clone().hasOwnProperty('month'), 'Should not clone prototype methods');
+ assert.ok(!hasOwnProp(moment().clone(), 'month'), 'Should not clone prototype methods');
});
test('cloning moment works with weird clones', function (assert) {
}
test('parsing week and weekday information', function (assert) {
- var ver = getVerifier(assert);
- var currentWeekOfYear = moment().weeks();
- var expectedDate2012 = moment([2012, 0, 1])
+ var ver = getVerifier(assert),
+ currentWeekOfYear = moment().weeks(),
+ expectedDate2012 = moment([2012, 0, 1])
.day(0)
.add((currentWeekOfYear - 1), 'weeks')
- .format('YYYY MM DD');
- var expectedDate1999 = moment([1999, 0, 1])
+ .format('YYYY MM DD'),
+ expectedDate1999 = moment([1999, 0, 1])
.day(0)
.add((currentWeekOfYear - 1), 'weeks')
.format('YYYY MM DD');
});
test('parsing flags retain parsed date parts', function (assert) {
- var a = moment('10 p', 'hh:mm a');
+ var a = moment('10 p', 'hh:mm a'), b;
assert.equal(a.parsingFlags().parsedDateParts[3], 10, 'parsed 10 as the hour');
assert.equal(a.parsingFlags().parsedDateParts[0], undefined, 'year was not parsed');
assert.equal(a.parsingFlags().meridiem, 'p', 'meridiem flag was added');
- var b = moment('10:30', ['MMDDYY', 'HH:mm']);
+ b = moment('10:30', ['MMDDYY', 'HH:mm']);
assert.equal(b.parsingFlags().parsedDateParts[3], 10, 'multiple format parshing matched hour');
assert.equal(b.parsingFlags().parsedDateParts[0], undefined, 'array is properly copied, no residual data from first token parse');
});
});
test('k, kk', function (assert) {
- for (var i = -1; i <= 24; i++) {
- var kVal = i + ':15:59';
- var kkVal = (i < 10 ? '0' : '') + i + ':15:59';
+ var i, kVal, kkVal;
+ for (i = -1; i <= 24; i++) {
+ kVal = i + ':15:59';
+ kkVal = (i < 10 ? '0' : '') + i + ':15:59';
if (i !== 24) {
assert.ok(moment(kVal, 'k:mm:ss').isSame(moment(kVal, 'H:mm:ss')), kVal + ' k parsing');
assert.ok(moment(kkVal, 'kk:mm:ss').isSame(moment(kkVal, 'HH:mm:ss')), kkVal + ' kk parsing');
module('creation data');
test('valid date', function (assert) {
- var dat = moment('1992-10-22');
- var orig = dat.creationData();
+ var dat = moment('1992-10-22'),
+ orig = dat.creationData();
assert.equal(dat.isValid(), true, '1992-10-22 is valid');
assert.equal(orig.input, '1992-10-22', 'original input is not correct.');
});
test('valid date at fr locale', function (assert) {
- var dat = moment('1992-10-22', 'YYYY-MM-DD', 'fr');
- var orig = dat.creationData();
+ var dat = moment('1992-10-22', 'YYYY-MM-DD', 'fr'),
+ orig = dat.creationData();
assert.equal(orig.locale._abbr, 'fr', 'locale is fr');
});
test('valid date with formats', function (assert) {
- var dat = moment('29-06-1995', ['MM-DD-YYYY', 'DD-MM', 'DD-MM-YYYY']);
- var orig = dat.creationData();
+ var dat = moment('29-06-1995', ['MM-DD-YYYY', 'DD-MM', 'DD-MM-YYYY']),
+ orig = dat.creationData();
assert.equal(orig.format, 'DD-MM-YYYY', 'DD-MM-YYYY format is defined.');
});
import { module, test } from '../qunit';
import { deprecate } from '../../lib/utils/deprecate';
-import moment from '../../moment';
module('deprecate');
test('deprecate', function (assert) {
// NOTE: hooks inside deprecate.js and moment are different, so this is can
// not be test.expectedDeprecations(...)
- var fn = function () {};
- var deprecatedFn = deprecate('testing deprecation', fn);
+ var fn = function () {},
+ deprecatedFn = deprecate('testing deprecation', fn);
deprecatedFn();
assert.expect(0);
});
test('diff across DST', function (assert) {
- var dst = dstForYear(2012), a, b, daysInMonth;
+ var dst = dstForYear(2012), a, b;
if (!dst) {
assert.equal(42, 42, 'at least one assertion');
return;
a = dst.moment;
b = a.clone().utc().add(12, 'hours').local();
- daysInMonth = (a.daysInMonth() + b.daysInMonth()) / 2;
assert.equal(b.diff(a, 'milliseconds', true), 12 * 60 * 60 * 1000,
'ms diff across DST');
assert.equal(b.diff(a, 'seconds', true), 12 * 60 * 60,
a = dst.moment;
b = a.clone().utc().add(12 + dst.diff, 'hours').local();
- daysInMonth = (a.daysInMonth() + b.daysInMonth()) / 2;
assert.equal(b.diff(a, 'milliseconds', true),
(12 + dst.diff) * 60 * 60 * 1000,
});
test('explicit cloning', function (assert) {
- var durationA = moment.duration(5, 'milliseconds');
- var durationB = durationA.clone();
+ var durationA = moment.duration(5, 'milliseconds'),
+ durationB = durationA.clone();
durationA.add(5, 'milliseconds');
assert.notEqual(durationA.milliseconds(), durationB.milliseconds(), 'Calling duration.clone() on a duration will create a clone');
});
});
test('add to moment', function (assert) {
- var d = moment.duration({months: 1, seconds: -1});
- var m = moment('2017-03-01').add(d);
+ var d = moment.duration({months: 1, seconds: -1}),
+ m = moment('2017-03-01').add(d);
assert.equal(m.month(), 2, 'Adds months before time');
assert.equal(m.date(), 31, 'Adds time after months');
});
moment.duration.invalid()
],
i,
- invalid,
- valid = moment.duration();
+ invalid;
for (i = 0; i < invalids.length; ++i) {
invalid = invalids[i];
import { module, test } from '../qunit';
-import each from '../helpers/each';
import eachOwnProp from '../helpers/each-own-prop';
import moment from '../../moment';
});
test('setter with multiple unit values', function (assert) {
- var a = moment();
+ var a = moment(), c;
a.set({
year: 2011,
month: 9,
assert.equal(a.seconds(), 8, 'second');
assert.equal(a.milliseconds(), 9, 'milliseconds');
- var c = moment([2016,0,1]);
+ c = moment([2016,0,1]);
assert.equal(c.set({weekYear: 2016}).weekYear(), 2016, 'week year correctly sets with object syntax');
assert.equal(c.set({quarter: 3}).quarter(), 3, 'quarter sets correctly with object syntax');
});
});
test('year setter', function (assert) {
- var a = moment([2015, 3, 15]);
+ var a = moment([2015, 3, 15]), b, c, d, e;
assert.equal(moment(a).year(2016).format('YYYY-MM-DD'), '2016-04-15', 'set from 2015 to 2016');
assert.equal(moment(a).year(2011).format('YYYY-MM-DD'), '2011-04-15', 'set from 2015 to 2011');
- var b = moment([2012, 1, 29]);
+ b = moment([2012, 1, 29]);
assert.equal(moment(b).year(2017).format('YYYY-MM-DD'), '2017-02-28', 'set from last day of february on a leap year to a non leap year');
assert.equal(moment(b).year(2004).format('YYYY-MM-DD'), '2004-02-29', 'set from last day of february on a leap year to a leap year');
- var c = moment([2012, 9, 4]);
+ c = moment([2012, 9, 4]);
assert.equal(moment(c).year(2017).format('YYYY-MM-DD'), '2017-10-04', 'set from a random day on a leap year to a non leap year');
assert.equal(moment(c).year(2004).format('YYYY-MM-DD'), '2004-10-04', 'set from a random day on a leap year to a leap year');
- var d = moment([2020, 1, 29]);
+ d = moment([2020, 1, 29]);
assert.equal(moment(d).year('2020').format('YYYY-MM-DD'), '2020-02-29', 'set from last day of february in 2020 to the same year, provided as string');
- var e = moment([2012, 1, 29]);
+ e = moment([2012, 1, 29]);
assert.equal(moment(e).year('2020').format('YYYY-MM-DD'), '2020-02-29', 'set from last day of february on a leap year to 2020, provided as string');
});
test('object set ordering', function (assert) {
- var a = moment([2016,3,30]);
+ var a = moment([2016,3,30]), b, c;
assert.equal(a.set({date:31, month:4}).date(), 31, 'setter order automatically arranged by size');
- var b = moment([2015,1,28]);
+ b = moment([2015,1,28]);
assert.equal(b.set({date:29, year: 2016}).format('YYYY-MM-DD'), '2016-02-29', 'year is prioritized over date');
//check a nonexistent time in US isn't set
- var c = moment([2016,2,13]);
+ c = moment([2016,2,13]);
c.set({
hour:2,
minutes:30,
module('instanceof');
test('instanceof', function (assert) {
- var mm = moment([2010, 0, 1]);
-
var extend = function (a, b) {
var i;
for (i in b) {
-import { module, test } from '../qunit';
+import { test } from '../qunit';
import isArray from '../../lib/utils/is-array.js';
});
test('is between without units inclusivity', function (assert) {
- var m = moment(new Date(2011, 3, 2, 3, 4, 5, 10)), mCopy = moment(m);
+ var m = moment(new Date(2011, 3, 2, 3, 4, 5, 10));
assert.equal(m.isBetween(
moment(new Date(2011, 3, 2, 3, 4, 5, 10)),
moment(new Date(2012, 3, 2, 3, 4, 5, 10)), null, '()'), false, 'start and end are excluded, start is equal to moment');
});
test('is between milliseconds inclusivity', function (assert) {
- var m = moment(new Date(2011, 3, 2, 3, 4, 5, 10)), mCopy = moment(m);
+ var m = moment(new Date(2011, 3, 2, 3, 4, 5, 10));
assert.equal(m.isBetween(
moment(new Date(2010, 3, 2, 3, 4, 5, 10)),
moment(new Date(2012, 3, 2, 3, 4, 5, 10)), 'milliseconds'), true, 'options, no inclusive');
-import { module, test } from '../qunit';
+import { test } from '../qunit';
import isNumber from '../../lib/utils/is-number.js';
'20100130T235959,999-0700',
'20100130T000000,000+0700',
'20100130 000000,000Z'
- ];
+ ], i;
- for (var i = 0; i < tests.length; i++) {
+ for (i = 0; i < tests.length; i++) {
assert.equal(moment(tests[i]).isValid(), true, tests[i] + ' should be valid in normal');
assert.equal(moment.utc(tests[i]).isValid(), true, tests[i] + ' should be valid in normal');
}
weekdays = 'one_two_three_four_five_six_seven'.split('_'),
weekdaysShort = 'on_tw_th_fo_fi_si_se'.split('_'),
weekdaysMin = '1_2_3_4_5_6_7'.split('_'),
- weekdaysLocale = 'four_five_six_seven_one_two_three'.split('_'),
- weekdaysShortLocale = 'fo_fi_si_se_on_tw_th'.split('_'),
- weekdaysMinLocale = '4_5_6_7_1_2_3'.split('_'),
- week = {
- dow : 3,
- doy : 6
- };
- var customLocale = moment.localeData('numerologists');
+ customLocale = moment.localeData('numerologists');
assert.deepEqual(customLocale.months(), months);
assert.deepEqual(customLocale.monthsShort(), monthsShort);
moment.locale('en');
var a = moment([2012, 5, 6]).locale('es'),
- b = a.clone(),
- c = moment(a);
+ b = a.clone();
assert.equal(b.format('MMMM'), 'junio', 'using moment.fn.clone()');
assert.equal(b.format('MMMM'), 'junio', 'using moment()');
fullKeyCaps,
fullKeyPlural,
fullKeyCapsPlural,
- fullKeyLower,
alias,
index;
for (index = 0; index < length; index += 1) {
fullKey = fullKeys[index];
fullKeyCaps = fullKey.toUpperCase();
- fullKeyLower = fullKey.toLowerCase();
fullKeyPlural = fullKey + 's';
fullKeyCapsPlural = fullKeyCaps + 's';
alias = aliases[index];
});
test('now - Date mocked', function (assert) {
- // We need to test mocking the global Date object, so disable 'Read Only' jshint check
- /* jshint -W020 */
var RealDate = Date,
customTimeMs = moment('2015-01-01T01:30:00.000Z').valueOf();
MockDate.prototype = RealDate.prototype;
+ // eslint-disable-next-line
Date = MockDate;
try {
assert.equal(moment().valueOf(), customTimeMs, 'moment now() time should use the global Date object');
} finally {
+ // eslint-disable-next-line
Date = RealDate;
}
});
});
test('custom rounding', function (assert) {
- var roundingDefault = moment.relativeTimeRounding();
+ var roundingDefault = moment.relativeTimeRounding(), a, retainValue;
// Round relative time evaluation down
moment.relativeTimeRounding(Math.floor);
moment.relativeTimeThreshold('d', 27);
moment.relativeTimeThreshold('M', 12);
- var a = moment.utc();
+ a = moment.utc();
a.subtract({minutes: 59, seconds: 59});
assert.equal(a.toNow(), 'in 59 minutes', 'Round down towards the nearest minute');
assert.equal(a.toNow(), 'in a year', 'Round down towards the nearest year');
// Do not round relative time evaluation
- var retainValue = function (value) {
+ retainValue = function (value) {
return value.toFixed(3);
};
moment.relativeTimeRounding(retainValue);
});
test('toDate returns a copy of the internal date', function (assert) {
- var m = moment();
- var d = m.toDate();
+ var m = moment(),
+ d = m.toDate();
m.year(0);
assert.notEqual(d, m.toDate());
});
test('toJSON works when moment is frozen', function (assert) {
if (Date.prototype.toISOString) {
- var expected = new Date().toISOString();
- var m = moment(expected);
+ var expected = new Date().toISOString(),
+ m = moment(expected);
if (Object.freeze != null) {
Object.freeze(m);
}
test('parse zone without a timezone', function (assert) {
test.expectedDeprecations();
- var m1 = moment.parseZone('2016-02-01T00:00:00');
- var m2 = moment.parseZone('2016-02-01T00:00:00Z');
- var m3 = moment.parseZone('2016-02-01T00:00:00+00:00'); //Someone might argue this is not necessary, you could even argue that is wrong being here.
- var m4 = moment.parseZone('2016-02-01T00:00:00+0000'); //Someone might argue this is not necessary, you could even argue that is wrong being here.
+ var m1 = moment.parseZone('2016-02-01T00:00:00'),
+ m2 = moment.parseZone('2016-02-01T00:00:00Z'),
+ m3 = moment.parseZone('2016-02-01T00:00:00+00:00'), //Someone might argue this is not necessary, you could even argue that is wrong being here.
+ m4 = moment.parseZone('2016-02-01T00:00:00+0000'); //Someone might argue this is not necessary, you could even argue that is wrong being here.
assert.equal(
m1.format('M D YYYY HH:mm:ss ZZ'),
'2 1 2016 00:00:00 +0000',
test('parse zone with a minutes unit abs less than 16 should retain minutes', function (assert) {
//ensure when minutes are explicitly parsed, they are retained
//instead of converted to hours, even if less than 16
- var n = moment.parseZone('2013-01-01T00:00:00-00:15');
+ var n = moment.parseZone('2013-01-01T00:00:00-00:15'), o;
assert.equal(n.utcOffset(), -15);
assert.equal(n.zone(), 15);
assert.equal(n.hour(), 0);
- var o = moment.parseZone('2013-01-01T00:00:00+00:15');
+
+ o = moment.parseZone('2013-01-01T00:00:00+00:15');
assert.equal(o.utcOffset(), 15);
assert.equal(o.zone(), -15);
assert.equal(o.hour(), 0);
import moment from '../moment';
import { setupDeprecationHandler, teardownDeprecationHandler } from './helpers/deprecation-handler';
-export var test = QUnit.test;
-export var only = QUnit.only;
+export var test = QUnit.test,
+ only = QUnit.only;
export function module (name, lifecycle) {
QUnit.module(name, {
module.exports = function (grunt) {
grunt.task.registerTask('qtest', 'run tests locally', function () {
- var done = this.async();
+ var done = this.async(), testrunner, tests;
- var testrunner = require('node-qunit');
+ testrunner = require('node-qunit');
testrunner.options.log.assertions = false;
testrunner.options.log.tests = false;
testrunner.options.log.summary = false;
testrunner.options.log.testing = false;
testrunner.options.maxBlockDuration = 600000;
- var tests;
-
if (grunt.option('only') != null) {
tests = grunt.file.expand.apply(null, grunt.option('only').split(',').map(function (file) {
if (file === 'moment') {
// var esperanto = require('esperanto');
var rollup = require('rollup').rollup;
// var babel = require('rollup-plugin-babel');
- var path = require('path');
- var Promise = require('es6-promise').Promise;
- var TMP_DIR = 'build/tmp';
+ var path = require('path'),
+ Promise = require('es6-promise').Promise,
+ TMP_DIR = 'build/tmp',
+ headerCache = {};
function moveComments(code, moveType) {
var comments = [], rest = [], skipId = -1;
return comments.concat([''], rest).join('\n');
}
- var headerCache = {};
function getHeaderByFile(headerFile) {
if (headerFile === 'none') {
return '';
grunt.task.registerTask('transpile-custom-raw',
'build just custom language bundles',
function (locales) {
- var done = this.async();
+ var done = this.async(),
- var localeFiles = locales.split(',').map(function (locale) {
+ localeFiles = locales.split(',').map(function (locale) {
var file = grunt.file.expand({cwd: 'src'}, 'locale/' + locale + '.js');
if (file.length !== 1) {
// we failed to find a locale