duration.ms = diffRes.milliseconds;
duration.M = diffRes.months;
ret = new Duration(duration);
if (isDuration(input) && hasOwnProp(input, '_locale')) {
ret._locale = input._locale;
if (isDuration(input) && hasOwnProp(input, '_isValid')) {
ret._isValid = input._isValid;
createDuration.fn = Duration.prototype;
createDuration.invalid = createInvalid$1;
function parseIso(inp, sign) {
// 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;
function positiveMomentsDifference(base, other) {
other.month() - base.month() + (other.year() - base.year()) * 12;
if (base.clone().add(res.months, 'M').isAfter(other)) {
res.milliseconds = +other - +base.clone().add(res.months, 'M');
function momentsDifference(base, other) {
if (!(base.isValid() && other.isValid())) {
return { milliseconds: 0, months: 0 };
other = cloneWithOffset(other, base);
if (base.isBefore(other)) {
res = positiveMomentsDifference(base, other);
res = positiveMomentsDifference(other, base);
res.milliseconds = -res.milliseconds;
res.months = -res.months;
// TODO: remove 'name' arg after deprecation is removed
function createAdder(direction, name) {
return function (val, period) {
//invert the arguments, but complain about it
if (period !== null && !isNaN(+period)) {
'(period, number) is deprecated. Please use moment().' +
'See http://momentjs.com/guides/#/warnings/add-inverted-param/ for more info.'
dur = createDuration(val, period);
addSubtract(this, dur, direction);
function addSubtract(mom, duration, isAdding, updateOffset) {
var milliseconds = duration._milliseconds,
days = absRound(duration._days),
months = absRound(duration._months);
updateOffset = updateOffset == null ? true : updateOffset;
setMonth(mom, get(mom, 'Month') + months * isAdding);
set$1(mom, 'Date', get(mom, 'Date') + days * isAdding);
mom._d.setTime(mom._d.valueOf() + milliseconds * isAdding);
hooks.updateOffset(mom, days || months);
var add = createAdder(1, 'add'),
subtract = createAdder(-1, 'subtract');
function isString(input) {
return typeof input === 'string' || input instanceof String;
// type MomentInput = Moment | Date | string | number | (number | string)[] | MomentInputObject | void; // null | undefined
function isMomentInput(input) {
isNumberOrStringArray(input) ||
isMomentInputObject(input) ||
function isMomentInputObject(input) {
var objectTest = isObject(input) && !isObjectEmpty(input),
for (i = 0; i < properties.length; i += 1) {
property = properties[i];
propertyTest = propertyTest || hasOwnProp(input, property);
return objectTest && propertyTest;
function isNumberOrStringArray(input) {
var arrayTest = isArray(input),
input.filter(function (item) {
return !isNumber(item) && isString(input);
return arrayTest && dataTypeTest;
function isCalendarSpec(input) {
var objectTest = isObject(input) && !isObjectEmpty(input),
for (i = 0; i < properties.length; i += 1) {
property = properties[i];
propertyTest = propertyTest || hasOwnProp(input, property);
return objectTest && propertyTest;
function getCalendarFormat(myMoment, now) {
var diff = myMoment.diff(now, 'days', true);
function calendar$1(time, formats) {
// Support for single parameter, formats only overload to the calendar function
if (arguments.length === 1) {
if (isMomentInput(arguments[0])) {
} else if (isCalendarSpec(arguments[0])) {
// 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 || createLocal(),
sod = cloneWithOffset(now, this).startOf('day'),
format = hooks.calendarFormat(this, sod) || 'sameElse',
(isFunction(formats[format])
? formats[format].call(this, now)
output || this.localeData().calendar(format, this, createLocal(now))
function isAfter(input, units) {
var localInput = isMoment(input) ? input : createLocal(input);
if (!(this.isValid() && localInput.isValid())) {
units = normalizeUnits(units) || 'millisecond';
if (units === 'millisecond') {
return this.valueOf() > localInput.valueOf();
return localInput.valueOf() < this.clone().startOf(units).valueOf();
function isBefore(input, units) {
var localInput = isMoment(input) ? input : createLocal(input);
if (!(this.isValid() && localInput.isValid())) {
units = normalizeUnits(units) || 'millisecond';
if (units === 'millisecond') {
return this.valueOf() < localInput.valueOf();
return this.clone().endOf(units).valueOf() < localInput.valueOf();
function isBetween(from, to, units, inclusivity) {
var localFrom = isMoment(from) ? from : createLocal(from),
localTo = isMoment(to) ? to : createLocal(to);
if (!(this.isValid() && localFrom.isValid() && localTo.isValid())) {
inclusivity = inclusivity || '()';
? this.isAfter(localFrom, units)
: !this.isBefore(localFrom, units)) &&
? this.isBefore(localTo, units)
: !this.isAfter(localTo, units))
function isSame(input, units) {
var localInput = isMoment(input) ? input : createLocal(input),
if (!(this.isValid() && localInput.isValid())) {
units = normalizeUnits(units) || 'millisecond';
if (units === 'millisecond') {
return this.valueOf() === localInput.valueOf();
inputMs = localInput.valueOf();
this.clone().startOf(units).valueOf() <= inputMs &&
inputMs <= this.clone().endOf(units).valueOf()
function isSameOrAfter(input, units) {
return this.isSame(input, units) || this.isAfter(input, units);
function isSameOrBefore(input, units) {
return this.isSame(input, units) || this.isBefore(input, units);
function diff(input, units, asFloat) {
var that, zoneDelta, output;
that = cloneWithOffset(input, this);
zoneDelta = (that.utcOffset() - this.utcOffset()) * 6e4;
units = normalizeUnits(units);
output = monthDiff(this, that) / 12;
output = monthDiff(this, that);
output = monthDiff(this, that) / 3;
output = (this - that) / 1e3;
output = (this - that) / 6e4;
output = (this - that) / 36e5;
output = (this - that - zoneDelta) / 864e5;
break; // 1000 * 60 * 60 * 24, negate dst
output = (this - that - zoneDelta) / 6048e5;
break; // 1000 * 60 * 60 * 24 * 7, negate dst
return asFloat ? output : absFloor(output);
function monthDiff(a, b) {
if (a.date() < b.date()) {
// end-of-month calculations work correct when the start month has more
// days than the end month.
var wholeMonthDiff = (b.year() - a.year()) * 12 + (b.month() - a.month()),
// b is in (anchor - 1 month, anchor + 1 month)
anchor = a.clone().add(wholeMonthDiff, 'months'),
anchor2 = a.clone().add(wholeMonthDiff - 1, 'months');
// linear across the month
adjust = (b - anchor) / (anchor - anchor2);
anchor2 = a.clone().add(wholeMonthDiff + 1, 'months');
// linear across the month
adjust = (b - anchor) / (anchor2 - anchor);
//check for negative zero, return zero if negative zero
return -(wholeMonthDiff + adjust) || 0;
hooks.defaultFormat = 'YYYY-MM-DDTHH:mm:ssZ';
hooks.defaultFormatUtc = 'YYYY-MM-DDTHH:mm:ss[Z]';
return this.clone().locale('en').format('ddd MMM DD YYYY HH:mm:ss [GMT]ZZ');
function toISOString(keepOffset) {
var utc = keepOffset !== true,
m = utc ? this.clone().utc() : this;
if (m.year() < 0 || m.year() > 9999) {
? 'YYYYYY-MM-DD[T]HH:mm:ss.SSS[Z]'
: 'YYYYYY-MM-DD[T]HH:mm:ss.SSSZ'
if (isFunction(Date.prototype.toISOString)) {
// native implementation is ~50x faster, use it when we can
return this.toDate().toISOString();
return new Date(this.valueOf() + this.utcOffset() * 60 * 1000)
.replace('Z', formatMoment(m, 'Z'));
utc ? 'YYYY-MM-DD[T]HH:mm:ss.SSS[Z]' : 'YYYY-MM-DD[T]HH:mm:ss.SSSZ'
* Return a human readable representation of a moment that can
* also be evaluated to get a new moment which is the same
* @link https://nodejs.org/dist/latest/docs/api/util.html#util_custom_inspect_function_on_objects
return 'moment.invalid(/* ' + this._i + ' */)';
func = this.utcOffset() === 0 ? 'moment.utc' : 'moment.parseZone';
prefix = '[' + func + '("]';
year = 0 <= this.year() && this.year() <= 9999 ? 'YYYY' : 'YYYYYY';
datetime = '-MM-DD[T]HH:mm:ss.SSS';
return this.format(prefix + year + datetime + suffix);
function format(inputString) {
inputString = this.isUtc()
var output = formatMoment(this, inputString);
return this.localeData().postformat(output);
function from(time, withoutSuffix) {
((isMoment(time) && time.isValid()) || createLocal(time).isValid())
return createDuration({ to: this, from: time })
.humanize(!withoutSuffix);
return this.localeData().invalidDate();
function fromNow(withoutSuffix) {
return this.from(createLocal(), withoutSuffix);
function to(time, withoutSuffix) {
((isMoment(time) && time.isValid()) || createLocal(time).isValid())
return createDuration({ from: this, to: time })