Debian Codegraph @

vendor/static/chart.js/dist/core/core.adapters.d.ts

raw
1 /**
2 * @namespace Chart._adapters
3 * @since 2.8.0
4 * @private
5 */
6 import type { AnyObject } from '../types/basic.js';
7 import type { ChartOptions } from '../types/index.js';
8 export type TimeUnit = 'millisecond' | 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'quarter' | 'year';
9 export interface DateAdapter<T extends AnyObject = AnyObject> {
10 readonly options: T;
11 /**
12 * Will called with chart options after adapter creation.
13 */
14 init(this: DateAdapter<T>, chartOptions: ChartOptions): void;
15 /**
16 * Returns a map of time formats for the supported formatting units defined
17 * in Unit as well as 'datetime' representing a detailed date/time string.
18 */
19 formats(this: DateAdapter<T>): Record<TimeUnit | 'datetime', string>;
20 /**
21 * Parses the given `value` and return the associated timestamp.
22 * @param value - the value to parse (usually comes from the data)
23 * @param [format] - the expected data format
24 */
25 parse(this: DateAdapter<T>, value: unknown, format?: string): number | null;
26 /**
27 * Returns the formatted date in the specified `format` for a given `timestamp`.
28 * @param timestamp - the timestamp to format
29 * @param format - the date/time token
30 */
31 format(this: DateAdapter<T>, timestamp: number, format: string): string;
32 /**
33 * Adds the specified `amount` of `unit` to the given `timestamp`.
34 * @param timestamp - the input timestamp
35 * @param amount - the amount to add
36 * @param unit - the unit as string
37 */
38 add(this: DateAdapter<T>, timestamp: number, amount: number, unit: TimeUnit): number;
39 /**
40 * Returns the number of `unit` between the given timestamps.
41 * @param a - the input timestamp (reference)
42 * @param b - the timestamp to subtract
43 * @param unit - the unit as string
44 */
45 diff(this: DateAdapter<T>, a: number, b: number, unit: TimeUnit): number;
46 /**
47 * Returns start of `unit` for the given `timestamp`.
48 * @param timestamp - the input timestamp
49 * @param unit - the unit as string
50 * @param [weekday] - the ISO day of the week with 1 being Monday
51 * and 7 being Sunday (only needed if param *unit* is `isoWeek`).
52 */
53 startOf(this: DateAdapter<T>, timestamp: number, unit: TimeUnit | 'isoWeek', weekday?: number | boolean): number;
54 /**
55 * Returns end of `unit` for the given `timestamp`.
56 * @param timestamp - the input timestamp
57 * @param unit - the unit as string
58 */
59 endOf(this: DateAdapter<T>, timestamp: number, unit: TimeUnit): number;
60 }
61 declare const _default: {
62 _date: {
63 new (options?: AnyObject): DateAdapter;
64 override<T extends AnyObject = AnyObject>(members: Partial<Omit<DateAdapter<T>, "options">>): void;
65 };
66 };
67 export default _default;