diff --git a/src/adapters/adapter.moment.js b/src/adapters/adapter.moment.js index 38f7e58d516..045cfcd8c04 100644 --- a/src/adapters/adapter.moment.js +++ b/src/adapters/adapter.moment.js @@ -6,7 +6,7 @@ var moment = require('moment'); var adapter = require('../core/core.adapters')._date; var helpers = require('../helpers/helpers.core'); -var SHORT_PRESETS = { +var FORMATS = { millisecond: 'h:mm:ss.SSS a', second: 'h:mm:ss a', minute: 'h:mm a', @@ -18,23 +18,21 @@ var SHORT_PRESETS = { year: 'YYYY' }; -var LONG_PRESETS = { - millisecond: 'MMM D, YYYY h:mm:ss.SSS a', - second: 'MMM D, YYYY h:mm:ss a', - minute: 'MMM D, YYYY h:mm a', - hour: 'MMM D, YYYY hA', - day: 'MMM D, YYYY', - week: 'll', - month: 'MMM YYYY', - quarter: '[Q]Q - YYYY', - year: 'YYYY' +var PRESETS = { + full: 'MMM D, YYYY h:mm:ss.SSS a', + time: 'MMM D, YYYY h:mm:ss a', + date: 'MMM D, YYYY' }; helpers.merge(adapter, moment ? { _id: 'moment', // DEBUG ONLY - presets: function(long) { - return long ? LONG_PRESETS : SHORT_PRESETS; + formats: function() { + return FORMATS; + }, + + presets: function() { + return PRESETS; }, parse: function(value, format) { diff --git a/src/core/core.adapters.js b/src/core/core.adapters.js index c1f7b50e0d7..9798b7e0d62 100644 --- a/src/core/core.adapters.js +++ b/src/core/core.adapters.js @@ -25,13 +25,23 @@ function abstract() { * @typedef {('millisecond'|'second'|'minute'|'hour'|'day'|'week'|'month'|'quarter'|'year')} * @memberof Chart._adapters._date * @name Unit - * */ + */ /** @lends Chart._adapters._date */ module.exports._date = { /** * Returns a map of time formats for the supported units. - * @param {boolean} [long] - query for long formats. + * @returns {{string: string}} + */ + formats: function() { + return {}; + }, + + /** + * Returns a map of date/time formats for the following presets: + * 'full': date + time + millisecond + * 'time': date + time + * 'date': date * @returns {{string: string}} */ presets: function() { diff --git a/src/scales/scale.time.js b/src/scales/scale.time.js index 6ed217b5e18..96ecff48817 100644 --- a/src/scales/scale.time.js +++ b/src/scales/scale.time.js @@ -410,23 +410,23 @@ function ticksFromTimestamps(values, majorUnit) { * Return the time format for the label with the most parts (milliseconds, second, etc.) */ function determineLabelFormat(timestamps) { - var presets = adapter.presets(true); + var presets = adapter.presets(); var ilen = timestamps.length; var i, ts, hasTime; for (i = 0; i < ilen; i++) { ts = timestamps[i]; if (ts % INTERVALS.second.size !== 0) { - return presets.millisecond; + return presets.full; } if (ts % INTERVALS.day.size !== 0) { hasTime = true; } } if (hasTime) { - return presets.second; + return presets.time; } - return presets.day; + return presets.date; } var defaultConfig = { @@ -499,7 +499,7 @@ module.exports = Scale.extend({ // supposed to contain *all* unit/string pairs but this can't be resolved // when loading the scale (adapters are loaded afterward), so let's populate // missing formats on update - helpers.mergeIf(time.displayFormats, adapter.presets()); + helpers.mergeIf(time.displayFormats, adapter.formats()); return Scale.prototype.update.apply(me, arguments); },