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') {
+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()];
}
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';
proto.localeData = localeData;
proto.max = prototypeMax;
proto.min = prototypeMin;
-proto.now = now;
proto.parsingFlags = parsingFlags;
proto.set = getSet;
proto.startOf = startOf;
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();
};
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;
}
});