]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Faster date operations (#5982)
authorBen McCann <322311+benmccann@users.noreply.github.com>
Thu, 17 Jan 2019 15:01:27 +0000 (07:01 -0800)
committerSimon Brunel <simonbrunel@users.noreply.github.com>
Thu, 17 Jan 2019 15:01:27 +0000 (16:01 +0100)
src/adapters/adapter.moment.js
src/scales/scale.time.js

index 601247099863c55aed54d1efe3e856950e65f3cd..04c03155924e6ff9d9e101e8f401a7323d322d7c 100644 (file)
@@ -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
index 6cf481b4ce22559ad4a25ca85351b9e54375f202..3744230a56483e8e1f8682653ecf854c3010db4c 100644 (file)
@@ -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);