Skip to content

Commit

Permalink
Release 0.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
chartjs-ci committed Jan 18, 2020
1 parent 459fac0 commit 4dd9fb1
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
8 changes: 8 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "chartjs-adapter-moment",
"description": "Chart.js adapter to use Moment.js for time functionalities",
"homepage": "https://www.chartjs.org",
"license": "MIT",
"version": "0.1.1",
"main": "dist/chartjs-adapter-moment.js"
}
69 changes: 69 additions & 0 deletions dist/chartjs-adapter-moment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*!
* chartjs-adapter-moment v0.1.1
* https://www.chartjs.org
* (c) 2020 Chart.js Contributors
* Released under the MIT license
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('moment'), require('chart.js')) :
typeof define === 'function' && define.amd ? define(['moment', 'chart.js'], factory) :
(global = global || self, factory(global.moment, global.Chart));
}(this, (function (moment, chart_js) { 'use strict';

moment = moment && moment.hasOwnProperty('default') ? moment['default'] : moment;

const FORMATS = {
datetime: 'MMM D, YYYY, h:mm:ss a',
millisecond: 'h:mm:ss.SSS a',
second: 'h:mm:ss a',
minute: 'h:mm a',
hour: 'hA',
day: 'MMM D',
week: 'll',
month: 'MMM YYYY',
quarter: '[Q]Q - YYYY',
year: 'YYYY'
};

chart_js._adapters._date.override(typeof moment === 'function' ? {
_id: 'moment', // DEBUG ONLY

formats: function() {
return FORMATS;
},

parse: function(value, format) {
if (typeof value === 'string' && typeof format === 'string') {
value = moment(value, format);
} else if (!(value instanceof moment)) {
value = moment(value);
}
return value.isValid() ? value.valueOf() : null;
},

format: function(time, format) {
return moment(time).format(format);
},

add: function(time, amount, unit) {
return moment(time).add(amount, unit).valueOf();
},

diff: function(max, min, unit) {
return moment(max).diff(moment(min), unit);
},

startOf: function(time, unit, weekday) {
time = moment(time);
if (unit === 'isoWeek') {
return time.isoWeekday(weekday).valueOf();
}
return time.startOf(unit).valueOf();
},

endOf: function(time, unit) {
return moment(time).endOf(unit).valueOf();
}
} : {});

})));
7 changes: 7 additions & 0 deletions dist/chartjs-adapter-moment.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4dd9fb1

Please sign in to comment.