-
Notifications
You must be signed in to change notification settings - Fork 408
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
feat: add date and time functionality #4904
base: master
Are you sure you want to change the base?
Conversation
leanprover-community-mathlib4-bot
commented
Aug 5, 2024
•
edited by leanprover-community-bot
Loading
edited by leanprover-community-bot
Mathlib CI status (docs):
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add tests for the various conversion routines that catch all of the interesting cases.
It would be very nice to have a few examples of the library being used in practice to achieve some common things.
A very minor suggestion for an in-Lean use case: have the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gentle reminder that we will not be able to merge this until there are decent tests for much of the functionality.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have been reading up on leap seconds a bit more and I am now no longer convinced that it is a good idea to handle leap seconds in our library at all.
It appears to me that currently the leap second handling in the library allows converting between what I'll call "Unix Timestamps" and "UTC Timestamps" (perhaps "TAI Timestamp" would be more accurate, I'm not sure). The former is the number of "seconds" since UNIX epoch pretending that every day has exactly 86400 seconds and the latter is the number of SI seconds that have elapsed since UNIX epoch. The former corresponds to the std::chrono sys_time
and the latter corresponds to utc_time
.
Due to the way Unix timestamps work (see Wikipedia), if I just take the current time according to sys_time
(as you do in Timestamp.now
) and naively add it to 1970-01-01 00:00:00, then I will get the correct time.
It doesn't appear to me to be the case that having to handle UTC timestamps is something that comes up in practice.
A theoretical advantage of having the leap second information around would be to correctly calculate the number of (SI) seconds between two wall-clock readings in a given location, but the current API doesn't make this easy and furthermore, neither java.time
nor std::chrono
nor the Rust chrono
crate can do this, so it doesn't seem particularly important.
In summary, my suggestion would be to
- remove leap seconds from
ZoneRules
- drop all of the conversion functions that use this data
- probably (?) keep the possibility to represent a leap second in
PlainTime
(though I have to admit that my previous comment here might have been misguided - it's not clear to me now that being dependent here is particularly helpful. Maybe it would be more helpful ifPlainTime
,PlainDateTime
andZonedDateTime
were also dependent, but that seems quite excessive), but be very particular about how leap seconds are handled in the formatting and the arithmetic. After writing this comment I noticed that what I'm suggesting is quite close to this discussion.
What do you think about this suggestion? If we do keep the "UTC timestamps" around, then I would strongly suggest having them be a different type from Timestamp
, which I would suggest should always refer to Unix time.
I agree that handling UTC timestamps may not be necessary. However, I think that it is important to keep the support for leap seconds just to try keep the support for ISO 8601 compliant dates. In the future, If someone requests (that will not be the case I guess given that a lot of libraries don't implement something like that), I think that we can consider deriving a specialized type from the Timestamp type to address these problems. |
If I'm understanding you correctly, this is compatible with my request above, i.e., not reading the leap second information from the time zone database but keeping leap second representation in |
This PR introduces date and time functionality to the Lean 4 Std. It's not complete yet and I need to implement some these things:
Format
module so I can easily create a format for all the standard formats like ISO8601)./usr/share/zoneinfo/
or using a hardcoded version).%date 2000-01-01
.