-
Notifications
You must be signed in to change notification settings - Fork 11.8k
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
DateTimeUtils - Helper logic to handle time #1531
Comments
A point we'll have to address if attempting to cater to a 'calendar day' usage will be that of timezones, which may be a major issue due to daylight savings, etc. |
Yes that is true. I would probably assume UTC for simplicity and it would be possible to shift the time (e.g UTC+1 or UTC-10) |
Leap seconds are dealt with at the EVM level. The unix timestamp that is obtained from |
#533 is quite old, and there's some discussion in that issue related to the security/correctness of using There's some ambiguity in #533, as it is not clear if it proposes |
The reason I commented on this issue is that while auditing a smart contract I found errors in the way dates were computed. The contract I was auditing had to lock some tokens until a certain date. It computed dates with I'd love to recommend the authors to use a human-readable representation of the dates, but I couldn't find a maintained function/lib for doing so. Having something like |
So, functions to create timestamps from human dates: Would these functions return the Also, how should we deal with timezones?
@alcuadrado Mind sharing how it was wrong exactly? |
Timezones are a mess, and DST only complicates matters further. I'd make it so that times specified in either UTC, or at a fixed offset (e.g. UTC+8 for Hong Kong, UTC-4 for Chile, etc.). |
I think functions would be more efficient. Btw, some of the functions in this library are also super useful.
I'd only do UTC. I don't see a way of managing timezones trustlessly, as any government can change their country's timezone whenever they want.
The offset was expressed as |
We're interested in adding this to the library. No one has started working on it yet. This looks like good information for whoever wants to work on this: Low-Level Date Algorithms |
Is this even under consideration? |
The team is not proactively working on this feature but we would be happy to receive a PR implementing the interface I described above:
|
Add date and datetime utility functions to convert from civil date time to Unix time.
Add date and datetime utility functions to convert from civil date time to Unix time.
Add date and datetime utility functions to convert from civil date time to Unix time.
Add date and datetime utility functions to convert from civil date time to Unix time.
🧐 Motivation
Time is important and off-chain there are often cases where time related checks need to be performed. To handle this on chain it would be nice to have some utils that would encapsulate these checks.
There are many use cases for this:
📝 Details
There is a library that is already implementing this logic (https://github.com/pipermerriam/ethereum-datetime), but this is not really up to date, nor audited.
Also it would be interesting to consider edge cases like leap seconds (at least mention why they are not implemented).
An api should include method to check if what year/ month/ day/ hour/ minute a certain timestamp is.
The text was updated successfully, but these errors were encountered: