-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Time
struct initialization with dates greater than December, 31st 9999
#12559
Comments
Thanks for raising this issue. The restriction on maximum date at the end of year 9999 has been in place since the That said, I don't think there's a strict requirement to keep this limitation in place. But removing that single check is not sufficient. The limitation on the max value of representable dates is encoded everywhere in the Time API, from interfaces to algorithms. It would require a careful approach to identify what this affects and how to resolve it. |
You could also check whether there's a BSON library for C#, and whether it conforms to the spec, and how, given that C# has the same limitation... and then take the same approach, which is probably one of these two:
|
Dear @asterite, thanks for the suggestion and sorry I forgot to mention that I've already researched into that.
Which is the exact same thing that I'm doing right now, in order to get the spec to pass. Thinking about another application where it could be potentially useful: maybe in astronomical computations where planet conjunctions, comet pass by's or things like that are calculated in the next thousands of years? Anyway, thanks again for your feedback! Let's say that you all agree with the proposed change. |
I'm fine with extending the range of Time to support years greater than 9999. I also think this is a good task for you to take, @Pluvie , if you want.
Right, I think going over the Time specs and making sure values greater than 9999 are supported should be pretty straight-forward. |
It is also not currently allowed to create a 0 year date: |
I don't think a general purpose calendar API is really suitable for astronomical computations. So I wouldn't see that as a practical use case. I think it still wouldn't hurt to provide a wider span of values. FWIW Ruby supports years in truely astronomical ranges (the API notes. |
Thanks again for the feedback guys! My approach would be, at a first stage, to only focus only on extending the maximum date with I've already read the contributing guidelines, if there is something else to know please do tell me. |
That is a good thing because AFAIK year 0 never was. It went from 1BC to 1AD. |
Yes and no. Depends on the calendar, or more specifically the year numbering. The ISO-8601 calendar uses astronomical numbering, which includes a year zero. It's equivalent to 1BC. That's for continuity reasons. Having a gap between year 1BC and 1AD would be catastrophic for calendrical calculations. |
I don't think your math is right. The biggest datetime representable with 64-bits and calendar epoch SECONDS_PER_DAY = 86400
DAYS_PER_YEAR = 365.2425
EPOCH_YEAR = 1
p! (Int64::MAX / SECONDS_PER_DAY / DAYS_PER_YEAR + EPOCH_YEAR) # => 292277024627.9277 Note that we can't go up entirely to |
If |
Hi all!
First of all thank you and congratulations for developing such an amazing language!
I've been a hardcore loving Rubyist for 10+ years now, but since I've discovered Crystal some months ago, I've been seriously in doubt about what of the two would be my favorite language 😄 and that definitely didn't happen with all the Rust, Go, Elixir, Clojure etc. experiences!
Anyhow, I just wanted to discuss a little improvement on the
Time
struct to allow the creation of dates greater than December, 31st 9999. I've looked into the source code, atcrystal/src/time.cr:476
and I've seen that if the internal@seconds
of the Time are greater thanTime::MAX_SECONDS
then anArgumentError.new "Invalid time: seconds out of range"
is raised.Since I'm still a newbie of the language, I might miss something out, but I'm asking myself the reason why there is this limit, and didn't find an answer so far. What I thought is that, technically, since
@seconds
is aInt64
the check should be made onInt64::MAX
, not the arbitraryTime::MAX_SECONDS
. But of course you cannot even create anInt64
greater than the max (Arithmetic overflow error), so I think that just removing that check is sufficient.One particular reason about this change is this: I'm developing a BSON specification implementation in pure Crystal (no C bindings). One of the BSON corpus tests is failing because I cannot instantiate dates greater than 31/12/9999 (see https://github.com/mongodb/specifications/blob/master/source/bson-corpus/tests/datetime.json line 25, where the test asks you to create a BSON object with a field with date 01/01/10000).
What do you think about this? Thanks!
The text was updated successfully, but these errors were encountered: