/
core.adapters.js
115 lines (100 loc) · 3.03 KB
/
core.adapters.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
106
107
108
109
110
111
112
113
114
115
/**
* @namespace Chart._adapters
* @since 2.8.0
* @private
*/
/**
* @return {*}
*/
function abstract() {
throw new Error('This method is not implemented: Check that a complete date adapter is provided.');
}
/**
* Date adapter (current used by the time scale)
* @namespace Chart._adapters._date
* @memberof Chart._adapters
* @private
*/
/**
* Currently supported unit string values.
* @typedef {('millisecond'|'second'|'minute'|'hour'|'day'|'week'|'month'|'quarter'|'year')} Unit
* @memberof Chart._adapters._date
*/
export class DateAdapter {
constructor(options, chartOptions) {
this.options = options || {};
this.chartOptions = chartOptions || {};
}
/**
* Returns a map of time formats for the supported formatting units defined
* in Unit as well as 'datetime' representing a detailed date/time string.
* @returns {{string: string}}
*/
formats() {
return abstract();
}
/**
* Parses the given `value` and return the associated timestamp.
* @param {any} value - the value to parse (usually comes from the data)
* @param {string} [format] - the expected data format
* @returns {(number|null)}
*/
parse(value, format) { // eslint-disable-line no-unused-vars
return abstract();
}
/**
* Returns the formatted date in the specified `format` for a given `timestamp`.
* @param {number} timestamp - the timestamp to format
* @param {string} format - the date/time token
* @return {string}
*/
format(timestamp, format) { // eslint-disable-line no-unused-vars
return abstract();
}
/**
* Adds the specified `amount` of `unit` to the given `timestamp`.
* @param {number} timestamp - the input timestamp
* @param {number} amount - the amount to add
* @param {Unit} unit - the unit as string
* @return {number}
*/
add(timestamp, amount, unit) { // eslint-disable-line no-unused-vars
return abstract();
}
/**
* Returns the number of `unit` between the given timestamps.
* @param {number} a - the input timestamp (reference)
* @param {number} b - the timestamp to subtract
* @param {Unit} unit - the unit as string
* @return {number}
*/
diff(a, b, unit) { // eslint-disable-line no-unused-vars
return abstract();
}
/**
* Returns start of `unit` for the given `timestamp`.
* @param {number} timestamp - the input timestamp
* @param {Unit|'isoWeek'} unit - the unit as string
* @param {number} [weekday] - the ISO day of the week with 1 being Monday
* and 7 being Sunday (only needed if param *unit* is `isoWeek`).
* @return {number}
*/
startOf(timestamp, unit, weekday) { // eslint-disable-line no-unused-vars
return abstract();
}
/**
* Returns end of `unit` for the given `timestamp`.
* @param {number} timestamp - the input timestamp
* @param {Unit|'isoWeek'} unit - the unit as string
* @return {number}
*/
endOf(timestamp, unit) { // eslint-disable-line no-unused-vars
return abstract();
}
}
DateAdapter.override = function(members) {
Object.assign(DateAdapter.prototype, members);
};
export default {
_date: DateAdapter
};