]> git.ipfire.org Git - thirdparty/Chart.js.git/commit
Type fixes for time adapters (#12010)
authorJosh Kelley <joshkel@gmail.com>
Wed, 29 Jan 2025 10:32:29 +0000 (05:32 -0500)
committerGitHub <noreply@github.com>
Wed, 29 Jan 2025 10:32:29 +0000 (11:32 +0100)
commitf744621c9c6ed331d6fe81ac9744fa72bdb0700d
treef62a52074c42c0674080c08fc5167dfb436d2be1
parent246c5c78edd3a72de1ab3a4a0c4fc8b639d48c2e
Type fixes for time adapters (#12010)

Specific changes:

* `formats` is defined as an arbitrary record.  In practice, it maps from `TimeUnit` and `'datetime'` to the specific date library's format strings.
* `parse` and `format` were defined as requiring `TimeUnit`, but they actually take date library format strings.  (E.g., it's up to the caller to look up format strings via `formats()` or user parameters.)
* `endOf` is never passed `isoWeek` (`isoWeek` isn't a normal `TimeUnit`, it's only used as a special case to `startOf`), and [chartjs-adapter-date-fns](https://github.com/chartjs/chartjs-adapter-date-fns/blob/v3.0.0/src/index.js#L101) doesn't support it.
* The constructor's options parameter is optional.
* `weekday` is documented as allowing a boolean (true means to start on Monday).
* `export default { _date: DateAdapterBase }` meant that `new _date()` returns a `DateAdapterBase` instance, whose methods take no parameters.  Since it can be overridden at runtime, I replaced it with a more generic constructor + static methods.
src/core/core.adapters.ts
src/scales/scale.time.js