From: Iskren Chernev Date: Fri, 25 Dec 2015 14:44:10 +0000 (+0200) Subject: Use moment.now instead of moment.fn.now for changing time source X-Git-Tag: 2.11.0~10^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b1d686ed481e2211cb81a1c60eca850fcea93f21;p=thirdparty%2Fmoment.git Use moment.now instead of moment.fn.now for changing time source --- diff --git a/src/lib/create/from-anything.js b/src/lib/create/from-anything.js index dd99f9d51..7b92587ec 100644 --- a/src/lib/create/from-anything.js +++ b/src/lib/create/from-anything.js @@ -61,7 +61,7 @@ export function prepareConfig (config) { function configFromInput(config) { var input = config._i; if (input === undefined) { - config._d = new Date(Moment.prototype.now()); + config._d = new Date(hooks.now()); } else if (isDate(input)) { config._d = new Date(+input); } else if (typeof input === 'string') { diff --git a/src/lib/create/from-array.js b/src/lib/create/from-array.js index c1bb6b56f..25dbc28fc 100644 --- a/src/lib/create/from-array.js +++ b/src/lib/create/from-array.js @@ -1,14 +1,15 @@ +import { hooks } from '../utils/hooks'; import { createDate, createUTCDate } from './date-from-array'; import { daysInYear } from '../units/year'; import { weekOfYear, weeksInYear, dayOfYearFromWeeks } from '../units/week-calendar-utils'; import { YEAR, MONTH, DATE, HOUR, MINUTE, SECOND, MILLISECOND } from '../units/constants'; import { createLocal } from './local'; -import { Moment } from '../moment/constructor'; import defaults from '../utils/defaults'; import getParsingFlags from './parsing-flags'; function currentDateArray(config) { - var nowValue = new Date(Moment.prototype.now()); + // hooks is actually the exported moment object + var nowValue = new Date(hooks.now()); if (config._useUTC) { return [nowValue.getUTCFullYear(), nowValue.getUTCMonth(), nowValue.getUTCDate()]; } diff --git a/src/lib/moment/prototype.js b/src/lib/moment/prototype.js index 17e9f6477..39775880b 100644 --- a/src/lib/moment/prototype.js +++ b/src/lib/moment/prototype.js @@ -13,7 +13,6 @@ import { to, toNow } from './to'; import { getSet } from './get-set'; import { locale, localeData, lang } from './locale'; import { prototypeMin, prototypeMax } from './min-max'; -import { now } from './now'; import { startOf, endOf } from './start-end-of'; import { valueOf, toDate, toArray, toObject, toJSON, unix } from './to-type'; import { isValid, parsingFlags, invalidAt } from './valid'; @@ -43,7 +42,6 @@ proto.locale = locale; proto.localeData = localeData; proto.max = prototypeMax; proto.min = prototypeMin; -proto.now = now; proto.parsingFlags = parsingFlags; proto.set = getSet; proto.startOf = startOf; diff --git a/src/test/moment/now.js b/src/test/moment/now.js index ee493df81..e61abf827 100644 --- a/src/test/moment/now.js +++ b/src/test/moment/now.js @@ -15,9 +15,9 @@ test('now', function (assert) { test('now - custom value', function (assert) { var CUSTOM_DATE = '2015-01-01T01:30:00.000Z'; - var oldFn = moment.fn.now; + var oldFn = moment.now; - moment.fn.now = function () { + moment.now = function () { return new Date(CUSTOM_DATE).valueOf(); }; @@ -26,6 +26,6 @@ test('now - custom value', function (assert) { assert.ok(moment.utc().toISOString() === CUSTOM_DATE, 'moment() constructor should use the function defined by moment.now, but it did not'); assert.ok(moment.utc([]).toISOString() === '2015-01-01T00:00:00.000Z', 'moment() constructor should fall back to the date defined by moment.now when an empty array is given, but it did not'); } finally { - moment.fn.now = oldFn; + moment.now = oldFn; } });