8000 Constants for the minimum and maximum values of each Temporal type · Issue #23 · js-temporal/proposal-temporal-v2 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Constants for the minimum and maximum values of each Temporal type #23

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

Open
ptomato opened this issue Mar 17, 2022 · 0 comments
Open

Constants for the minimum and maximum values of each Temporal type #23

ptomato opened this issue Mar 17, 2022 · 0 comments

Comments

@ptomato
7D55 Copy link
Collaborator
ptomato commented Mar 17, 2022

Several Temporal types have an allowed range of values (tc39/proposal-temporal#24):

  • Instant, ZonedDateTime: ±1e8 24-hour days around the Unix epoch (±86400_0000_0000_000_000_000n nanoseconds), same as legacy Date
    • min value: -271821-04-20T00:00:00Z
    • max value: +275760-09-13T00:00:00Z
  • PlainDateTime: such that any valid Instant can be converted to a PlainDateTime at any UTC offset in the range of ±23:59:59.999999999
    • min value: -271821-04-19T00:00:00.000000001
    • max value: +275760-09-13T23:59:59.999999999
  • PlainDate: such that any valid PlainDateTime can be converted to a PlainDate
    • min value: -271821-04-20
    • max value: +275760-09-13
  • PlainYearMonth: such that any valid PlainDate can be converted to a PlainYearMonth
    • min value: -271821-04
    • max value: +275760-09

It's not currently possible to get these values from JS, except by knowing what they are through out-of-band documentation.

One recommendation would be to include constants on each type's constructor (e.g. Temporal.Instant.MAX_VALUE). This would avoid polluting top-level autocomplete with a large number of rarely used options. Also it would match other types' behavior like Number.

Advantages:

These are useful for input validation, expanded polyfills, and tests.

Concerns:

None, this seems useful to have.

Prior art:

  • Legacy Date has a Date object where the internal date value is NaN, but no min or max value constants
  • Python: datetime.datetime.max, etc.
  • Rust: chrono::MAX_DATE, etc.

Constraints / corner cases:

  • What calendar would the min and max values for ZonedDateTime, PlainDate, PlainDateTime, and PlainYearMonth have? iso8601 as the "machine" calendar might be the answer here.
  • What time zone would the min and max values for ZonedDateTime have? Unlike the calendar, it seems like it could be harmful to choose UTC as the time zone.
  • Would we have max and min values for PlainTime (00:00–23:59:59.999999999)?
  • Would we have max and min values for PlainMonthDay (01-01–??-??)? The max value depends on the calendar. For example, the Gregorian calendar would have 12-31 as the max value, and the Hebrew calendar would have a max value of PlainMonthDay.from({ monthCode: 'M12', day: 29 })(?)
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
0