]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Use moment.now instead of moment.fn.now for changing time source 2833/head
authorIskren Chernev <iskren.chernev@gmail.com>
Fri, 25 Dec 2015 14:44:10 +0000 (16:44 +0200)
committerIskren Chernev <iskren.chernev@gmail.com>
Fri, 25 Dec 2015 14:44:10 +0000 (16:44 +0200)
src/lib/create/from-anything.js
src/lib/create/from-array.js
src/lib/moment/prototype.js
src/test/moment/now.js

index dd99f9d519d244de6cce67d8ec75e5d018cf9fdf..7b92587ec7746565f86dbe4c46ab40dc83288ba7 100644 (file)
@@ -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') {
index c1bb6b56f9e3cccd5316b02465c7bcadf4afd04e..25dbc28fc6759fad58ec2d6b192741488560ad2b 100644 (file)
@@ -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()];
     }
index 17e9f6477dd8b47cd287a8e348531d8a158160d8..39775880bfee7b7b9076233ce3e9c72eb17b105e 100644 (file)
@@ -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;
index ee493df819fdda62a33ebb289969949f55a2e8ad..e61abf82725dce50366c3b162d5ebff4ebc73f13 100644 (file)
@@ -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;
     }
 });