-
Notifications
You must be signed in to change notification settings - Fork 35
/
index.js
105 lines (96 loc) · 3.13 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import { _adapters, helpers } from 'chart.js';
import {
parse, format, isValid,
startOfSecond, startOfMinute, startOfHour, startOfDay,
startOfWeek, startOfMonth, startOfQuarter, startOfYear,
addMilliseconds, addSeconds, addMinutes, addHours,
addDays, addWeeks, addMonths, addQuarters, addYears,
differenceInMilliseconds, differenceInSeconds, differenceInMinutes,
differenceInHours, differenceInDays, differenceInWeeks,
differenceInMonths, differenceInQuarters, differenceInYears,
endOfSecond, endOfMinute, endOfHour, endOfDay,
endOfWeek, endOfMonth, endOfQuarter, endOfYear
} from 'date-fns';
var 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: 'DD',
month: 'MMM YYYY',
quarter: '[Q]Q - YYYY',
year: 'YYYY'
};
_adapters._date.override({
_id: 'date-fns', // DEBUG
formats: function() {
return FORMATS;
},
parse: function(value) {
if (helpers.isNullOrUndef(value)) {
return null;
}
value = parse(value, this.options);
return isValid(value) ? value.getTime() : null;
},
format: function(time, fmt) {
return format(time, fmt, this.options);
},
add: function(time, amount, unit) {
switch (unit) {
case 'millisecond': return addMilliseconds(time, amount);
case 'second': return addSeconds(time, amount);
case 'minute': return addMinutes(time, amount);
case 'hour': return addHours(time, amount);
case 'day': return addDays(time, amount);
case 'week': return addWeeks(time, amount);
case 'month': return addMonths(time, amount);
case 'quarter': return addQuarters(time, amount);
case 'year': return addYears(time, amount);
default: return time;
}
},
diff: function(max, min, unit) {
switch (unit) {
case 'millisecond': return differenceInMilliseconds(max, min);
case 'second': return differenceInSeconds(max, min);
case 'minute': return differenceInMinutes(max, min);
case 'hour': return differenceInHours(max, min);
case 'day': return differenceInDays(max, min);
case 'week': return differenceInWeeks(max, min);
case 'month': return differenceInMonths(max, min);
case 'quarter': return differenceInQuarters(max, min);
case 'year': return differenceInYears(max, min);
default: return 0;
}
},
startOf: function(time, unit, weekday) {
switch (unit) {
case 'second': return startOfSecond(time);
case 'minute': return startOfMinute(time);
case 'hour': return startOfHour(time);
case 'day': return startOfDay(time);
case 'week': return startOfWeek(time);
case 'isoWeek': return startOfWeek(time, { weekStartsOn: weekday });
case 'month': return startOfMonth(time);
case 'quarter': return startOfQuarter(time);
case 'year': return startOfYear(time);
default: return time;
}
},
endOf: function(time, unit) {
switch (unit) {
case 'second': return endOfSecond(time);
case 'minute': return endOfMinute(time);
case 'hour': return endOfHour(time);
case 'day': return endOfDay(time);
case 'week': return endOfWeek(time);
case 'month': return endOfMonth(time);
case 'quarter': return endOfQuarter(time);
case 'year': return endOfYear(time);
default: return time;
}
}
});