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

Improving js-joda support #627

Open
joshkel opened this issue Sep 28, 2022 · 0 comments
Open

Improving js-joda support #627

joshkel opened this issue Sep 28, 2022 · 0 comments

Comments

@joshkel
Copy link
Contributor

joshkel commented Sep 28, 2022

I'm looking at using the js-joda adapters with the MUI date/time pickers and am running into limitations: js-joda provides several date/time classes, but @date-io/js-joda only supports a few of them. (See here for a good overview of the Java Joda-Time API; js-joda is modeled off of that.)

I'm happy to work on a PR to improve this but wasn't sure about date-io's error-handling philosophy:

  • @date-io/js-joda has several functions that fall through and return undefined (e.g., 1, 2); I'm more familiar with getting TypeScript compiler errors ("Function lacks ending return statement and return type does not include 'undefined' (ts(2366))") in cases like this and adding explicit returns to address that.
  • Luxon, Moment, and Day.js apparently handle errors by returning special "invalid" date objects. js-joda instead handles errors by throwing exceptions (which is more what I'm used to). @date-io/js-joda apparently handles this difference by catching some errors and instead return the error object. (In my mind, this addresses that discrepancy but introduces other potential problems - the resulting Temporal | Error union isn't captured by the type system, and exceptions that aren't of the expected type cause the code to fall through to returning undefined, like I mentioned above.)

To pick a concrete example: How should isAfter work if it's asked to compare a js-joda LocalDate (a date with no time specified) with a LocalTime (a time of day with no date specified)?

  1. Explicitly return false, since they aren't comparable, similar to how NaN !== NaN?
  2. Fall through to return undefined, indicating that there's a potential hole in @date-io/js-joda's abstraction over js-joda?
  3. Throw an exception, since that's what js-joda itself would do if you compared a LocalDate to a LocalTime?
  4. Something I'm not thinking of?

If you can provide some guidance on how to handle these interface mismatches and how errors ought to be handled within date-io, I can try to put together a PR to extend @date-io/js-joda accordingly. Thanks!

@joshkel joshkel changed the title Improving js-jod Improving js-joda Sep 28, 2022
@joshkel joshkel changed the title Improving js-joda Improving js-joda support Sep 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant