| 10 | export type TimeUnit = class="st">'millisecond' | class="st">'second' | class="st">'minute' | class="st">'hour' | class="st">'day' | class="st">'week' | class="st">'month' | class="st">'quarter' | class="st">'year'; |
| 11 | |
| 12 | export interface DateAdapter<T extends AnyObject = AnyObject> { |
| 13 | readonly options: T; |
| 14 | /** |
| 15 | * Will called with chart options after adapter creation. |
| 16 | */ |
| 17 | init(this: DateAdapter<T>, chartOptions: ChartOptions): void; |
| 18 | /** |
| 19 | * Returns a map of time formats for the supported formatting units defined |
| 20 | * in Unit as well as class="st">'datetime' representing a detailed date/time string. |
| 21 | */ |
| 22 | formats(this: DateAdapter<T>): Record<TimeUnit | class="st">'datetime', string>; |
| 23 | /** |
| 24 | * Parses the given `value` and return the associated timestamp. |
| 25 | * @param value - the value to parse (usually comes from the data) |
| 26 | * @param [format] - the expected data format |
| 27 | */ |
| 28 | parse(this: DateAdapter<T>, value: unknown, format?: string): number | null; |
| 29 | /** |
| 30 | * Returns the formatted date in the specified `format` for a given `timestamp`. |
| 31 | * @param timestamp - the timestamp to format |
| 32 | * @param format - the date/time token |
| 33 | */ |
| 34 | format(this: DateAdapter<T>, timestamp: number, format: string): string; |
| 35 | /** |
| 36 | * Adds the specified `amount` of `unit` to the given `timestamp`. |
| 37 | * @param timestamp - the input timestamp |
| 38 | * @param amount - the amount to add |
| 39 | * @param unit - the unit as string |
| 40 | */ |
| 41 | add(this: DateAdapter<T>, timestamp: number, amount: number, unit: TimeUnit): number; |
| 42 | /** |
| 43 | * Returns the number of `unit` between the given timestamps. |
| 44 | * @param a - the input timestamp (reference) |
| 45 | * @param b - the timestamp to subtract |
| 46 | * @param unit - the unit as string |
| 47 | */ |
| 48 | diff(this: DateAdapter<T>, a: number, b: number, unit: TimeUnit): number; |
| 49 | /** |
| 50 | * Returns start of `unit` for the given `timestamp`. |
| 51 | * @param timestamp - the input timestamp |
| 52 | * @param unit - the unit as string |
| 53 | * @param [weekday] - the ISO day of the week with 1 being Monday |
| 54 | * and 7 being Sunday (only needed if param *unit* is `isoWeek`). |
| 55 | */ |
| 56 | startOf(this: DateAdapter<T>, timestamp: number, unit: TimeUnit | class="st">'isoWeek', weekday?: number | boolean): number; |
| 57 | /** |
| 58 | * Returns end of `unit` for the given `timestamp`. |
| 59 | * @param timestamp - the input timestamp |
| 60 | * @param unit - the unit as string |
| 61 | */ |
| 62 | endOf(this: DateAdapter<T>, timestamp: number, unit: TimeUnit): number; |
| 63 | } |
| 64 | |
| 65 | function abstract<T = void>(): T { |
| 66 | throw new Error(class="st">'This method is not implemented: Check that a complete date adapter is provided.'); |
no outgoing calls
no test coverage detected