moment / luxon

⏱ A library for working with dates and times in JS
https://moment.github.io/luxon
MIT License
15.23k stars 730 forks source link

Document behaviour of formatting methods on invalid DateTimes #1474

Open ab-pm opened 1 year ago

ab-pm commented 1 year ago

Like others (#1421) I was caught off-guard by the typings update that declared many return values to be nullable. I had read the validity docs when I first encountered the library, but have forgotten them since (albeit using isValid in a few places) and not thought about what this meant for formatting methods like .toString() or .toISO().

The behaviour of returning null on invalid DateTime objects is completely missing from the API documentation afaics.

The TypeScript typings should not be the only reminder about this. I would expect the return type of all the to… methods to include | null in the API docs, a sentence like "If invalid, returns null." added to each of their descriptions, and also a section (warning) about this behaviour on the formatting docs.

icambron commented 1 year ago

Sure would take PRs adding these