Skip to content

Commit ba7fea0

Browse files
committed
Release 0.1.2
1 parent 139b73f commit ba7fea0

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

dist/chartjs-adapter-moment.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*!
2+
* chartjs-adapter-moment v0.1.2
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) { 'use strict';
12+
13+
moment = moment && Object.prototype.hasOwnProperty.call(moment, 'default') ? moment['default'] : moment;
14+
Chart = Chart && Object.prototype.hasOwnProperty.call(Chart, 'default') ? Chart['default'] : Chart;
15+
16+
const FORMATS = {
17+
datetime: 'MMM D, YYYY, h:mm:ss a',
18+
millisecond: 'h:mm:ss.SSS a',
19+
second: 'h:mm:ss a',
20+
minute: 'h:mm a',
21+
hour: 'hA',
22+
day: 'MMM D',
23+
week: 'll',
24+
month: 'MMM YYYY',
25+
quarter: '[Q]Q - YYYY',
26+
year: 'YYYY'
27+
};
28+
29+
Chart._adapters._date.override(typeof moment === 'function' ? {
30+
_id: 'moment', // DEBUG ONLY
31+
32+
formats: function() {
33+
return FORMATS;
34+
},
35+
36+
parse: function(value, format) {
37+
if (typeof value === 'string' && typeof format === 'string') {
38+
value = moment(value, format);
39+
} else if (!(value instanceof moment)) {
40+
value = moment(value);
41+
}
42+
return value.isValid() ? value.valueOf() : null;
43+
},
44+
45+
format: function(time, format) {
46+
return moment(time).format(format);
47+
},
48+
49+
add: function(time, amount, unit) {
50+
return moment(time).add(amount, unit).valueOf();
51+
},
52+
53+
diff: function(max, min, unit) {
54+
return moment(max).diff(moment(min), unit);
55+
},
56+
57+
startOf: function(time, unit, weekday) {
58+
time = moment(time);
59+
if (unit === 'isoWeek') {
60+
return time.isoWeekday(weekday).valueOf();
61+
}
62+
return time.startOf(unit).valueOf();
63+
},
64+
65+
endOf: function(time, unit) {
66+
return moment(time).endOf(unit).valueOf();
67+
}
68+
} : {});
69+
70+
})));

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)