Skip to content

Commit 4dd9fb1

Browse files
committed
Release 0.1.1
1 parent 459fac0 commit 4dd9fb1

File tree

3 files changed

+84
-0
lines changed

3 files changed

+84
-0
lines changed

bower.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "chartjs-adapter-moment",
3+
"description": "Chart.js adapter to use Moment.js for time functionalities",
4+
"homepage": "https://www.chartjs.org",
5+
"license": "MIT",
6+
"version": "0.1.1",
7+
"main": "dist/chartjs-adapter-moment.js"
8+
}

dist/chartjs-adapter-moment.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*!
2+
* chartjs-adapter-moment v0.1.1
3+
* https://www.chartjs.org
4+
* (c) 2020 Chart.js Contributors
5+
* Released under the MIT license
6+
*/
7+
(function (global, factory) {
8+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('moment'), require('chart.js')) :
9+
typeof define === 'function' && define.amd ? define(['moment', 'chart.js'], factory) :
10+
(global = global || self, factory(global.moment, global.Chart));
11+
}(this, (function (moment, chart_js) { 'use strict';
12+
13+
moment = moment && moment.hasOwnProperty('default') ? moment['default'] : moment;
14+
15+
const FORMATS = {
16+
datetime: 'MMM D, YYYY, h:mm:ss a',
17+
millisecond: 'h:mm:ss.SSS a',
18+
second: 'h:mm:ss a',
19+
minute: 'h:mm a',
20+
hour: 'hA',
21+
day: 'MMM D',
22+
week: 'll',
23+
month: 'MMM YYYY',
24+
quarter: '[Q]Q - YYYY',
25+
year: 'YYYY'
26+
};
27+
28+
chart_js._adapters._date.override(typeof moment === 'function' ? {
29+
_id: 'moment', // DEBUG ONLY
30+
31+
formats: function() {
32+
return FORMATS;
33+
},
34+
35+
parse: function(value, format) {
36+
if (typeof value === 'string' && typeof format === 'string') {
37+
value = moment(value, format);
38+
} else if (!(value instanceof moment)) {
39+
value = moment(value);
40+
}
41+
return value.isValid() ? value.valueOf() : null;
42+
},
43+
44+
format: function(time, format) {
45+
return moment(time).format(format);
46+
},
47+
48+
add: function(time, amount, unit) {
49+
return moment(time).add(amount, unit).valueOf();
50+
},
51+
52+
diff: function(max, min, unit) {
53+
return moment(max).diff(moment(min), unit);
54+
},
55+
56+
startOf: function(time, unit, weekday) {
57+
time = moment(time);
58+
if (unit === 'isoWeek') {
59+
return time.isoWeekday(weekday).valueOf();
60+
}
61+
return time.startOf(unit).valueOf();
62+
},
63+
64+
endOf: function(time, unit) {
65+
return moment(time).endOf(unit).valueOf();
66+
}
67+
} : {});
68+
69+
})));

dist/chartjs-adapter-moment.min.js

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)