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

Add a feature to extend the supported range of dates #886

Closed
jedel1043 opened this issue Nov 20, 2022 · 2 comments
Closed

Add a feature to extend the supported range of dates #886

jedel1043 opened this issue Nov 20, 2022 · 2 comments

Comments

@jedel1043
Copy link

jedel1043 commented Nov 20, 2022

At boa (A Javascript interpreter) we're using chrono to handle the Javascript Date builtin; we mainly use it to easily create, parse and format local and UTC datetimes. However, we discovered that several tests were failing because of the supported range of dates by chrono. The README specifies:

Date types are limited in about +/- 262,000 years from the common epoch.

While the ECMAScript spec mentions:

The smaller range supported by a time value as specified in this section is approximately -273,790 to 273,790 years relative to 1970.

chrono's supported range is smaller than the range specified by the spec.

The time crate has a feature (large-dates) to extend the allowed range of dates, so we would be very glad to see a similar feature in chrono that extended its supported range.

Thanks!

@esheppa
Copy link
Collaborator

esheppa commented Nov 21, 2022

this could be supported by the work in #882, just by swapping out the i16 year for i32. This might be better as a seperate type rather than a feature flag such that both types could be used in a single project

bors bot pushed a commit to boa-dev/boa that referenced this issue Nov 22, 2022
Just a general cleanup of the `Date` builtin to use slightly better patterns and to fix our warnings about deprecated functions.

About the regressed tests. It seems to be a `chrono` bug, so I opened up an issue (chronotope/chrono#884) for it and they've already opened a PR fixing it (chronotope/chrono#885).

However, while checking out the remaining failing tests, I realized there's a more fundamental limitation with the library. Currently, [`chrono`](https://github.com/chronotope/chrono) specifies:

> Date types are limited in about +/- 262,000 years from the common epoch.

While the [ECMAScript spec](https://tc39.es/ecma262/#sec-time-values-and-time-range) says:

> The smaller range supported by a time value as specified in this section is approximately -273,790 to 273,790 years relative to 1970.

The range allowed by the spec is barely outside of the range supported by `chrono`! This is why the remaining `Date` tests fail.
Seeing that, I would like to ping @djc and @esheppa (the maintainers of `chrono`) to ask if it would be feasible to add a feature, akin to the `large-dates` feature from the `time` crate, that expands the supported range of `chrono`.

EDIT: Filed chronotope/chrono#886
@pitdicker
Copy link
Collaborator

We have no spare bits left in the internal representation of our NaiveDate type (the time crate did have some). Our current representation includes 4 bits to cache whether the year is a leap year and what is the first weekday of the year. Those are used in many of the operations chrono supports on NaiveDates, including conversion to timestamps and formatting.

So this feature either needs a substantial change to chrono's internals and performance characteristics, or it needs the backing type to switch from i32 to i64.

I don't think a large-dates feature is going to be a good fit for chrono. As the time crate already supports this use case, maybe it is best to that library instead.

@pitdicker pitdicker closed this as not planned Won't fix, can't repro, duplicate, stale Feb 2, 2024
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

3 participants