-
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
Add DateTime.fromSecondsSinceEpoch
and int get secondsSinceEpoch
#59961
Comments
Summary: User proposes adding |
Adding constructors should be non-breaking, but adding a getter to an interface is breaking. I don't think the benefit would be worth that. |
I guess it could be argued that this field could be added using extension like done with: |
I created this PR to propose a concept for the I welcome your thoughts and feedback! |
Not seeing the big need for this. It is just If we do decide to add something, why just seconds? Not sure I want all of them. |
Proposal to Add Features to the
DateTime
ClassDateTime.fromSecondsSinceEpoch
:A constructor that creates a DateTime instance from seconds since the epoch.
int get secondsSinceEpoch
:A getter that retrieves the number of seconds since the epoch from a DateTime instance.
Using
dateTime.millisecondsSinceEpoch ~/ 1000
for conversions is often verbose.Adding these features would simplify the code and enhance the dev-experience.
It would be useful when only seconds are needed from DateTime, ultimately reducing overhead from unnecessary operations with milliseconds.
AS-IS
TO-BE
Thanks!
I’d love to hear your thoughts—feel free to drop a comment!
The text was updated successfully, but these errors were encountered: