Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type fixes for time adapters #12010

Merged
merged 1 commit into from
Jan 29, 2025

Conversation

joshkel
Copy link
Contributor

@joshkel joshkel commented Jan 29, 2025

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 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.

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.
@LeeLenaleee LeeLenaleee added the type: types Typescript type changes label Jan 29, 2025
@LeeLenaleee LeeLenaleee added this to the Version 4.4.8 milestone Jan 29, 2025
@LeeLenaleee LeeLenaleee merged commit f744621 into chartjs:master Jan 29, 2025
7 checks passed
@joshkel joshkel deleted the time-adapter-type-fixes branch January 29, 2025 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: types Typescript type changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants