From 69b4a4c003d7aeb328d1b6c70da8a0bfc000f684 Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Thu, 17 Jan 2019 07:01:27 -0800 Subject: [PATCH] Faster date operations (#5982) --- src/adapters/adapter.moment.js | 10 +++++----- src/scales/scale.time.js | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/adapters/adapter.moment.js b/src/adapters/adapter.moment.js index 601247099..04c031559 100644 --- a/src/adapters/adapter.moment.js +++ b/src/adapters/adapter.moment.js @@ -41,7 +41,7 @@ helpers.merge(adapter, moment ? { } else if (!(value instanceof moment)) { value = moment(value); } - return value.isValid() ? +value : null; + return value.isValid() ? value.valueOf() : null; }, format: function(time, format) { @@ -49,7 +49,7 @@ helpers.merge(adapter, moment ? { }, add: function(time, amount, unit) { - return +moment(time).add(amount, unit); + return moment(time).add(amount, unit).valueOf(); }, diff: function(max, min, unit) { @@ -59,13 +59,13 @@ helpers.merge(adapter, moment ? { startOf: function(time, unit, weekday) { time = moment(time); if (unit === 'isoWeek') { - return +time.isoWeekday(weekday); + return time.isoWeekday(weekday).valueOf(); } - return +time.startOf(unit); + return time.startOf(unit).valueOf(); }, endOf: function(time, unit) { - return +moment(time).endOf(unit); + return moment(time).endOf(unit).valueOf(); }, // DEPRECATIONS diff --git a/src/scales/scale.time.js b/src/scales/scale.time.js index 6cf481b4c..3744230a5 100644 --- a/src/scales/scale.time.js +++ b/src/scales/scale.time.js @@ -574,8 +574,8 @@ module.exports = Scale.extend({ max = parse(timeOpts.max, me) || max; // In case there is no valid min/max, set limits based on unit time option - min = min === MAX_INTEGER ? +adapter.startOf(+new Date(), unit) : min; - max = max === MIN_INTEGER ? +adapter.endOf(+new Date(), unit) + 1 : max; + min = min === MAX_INTEGER ? +adapter.startOf(Date.now(), unit) : min; + max = max === MIN_INTEGER ? +adapter.endOf(Date.now(), unit) + 1 : max; // Make sure that max is strictly higher than min (required by the lookup table) me.min = Math.min(min, max);