-
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
[WIP] feat: Add DateTimeSecondsSinceEpoch
#59975
base: main
Are you sure you want to change the base?
Conversation
Thank you for your contribution! This project uses Gerrit for code reviews. Your pull request has automatically been converted into a code review at: https://dart-review.googlesource.com/c/sdk/+/405740 Please wait for a developer to review your code review at the above link; you can speed up the review if you sign into Gerrit and manually add a reviewer that has recently worked on the relevant code. See CONTRIBUTING.md to learn how to upload changes to Gerrit directly. Additional commits pushed to this PR will update both the PR and the corresponding Gerrit CL. After the review is complete on the CL, your reviewer will merge the CL (automatically closing this PR). |
sdk/lib/core/date_time.dart
Outdated
/// Creates a [DateTime] instance from seconds since epoch. | ||
static DateTime fromSecondsSinceEpoch(int seconds) { | ||
return DateTime.fromMillisecondsSinceEpoch(seconds * 1000); | ||
} |
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.
Do note that static methods cannot be added to classes using extension methods. So what you do here is just declaring a static method on the extension itself and which needs to be called with: DateTimeSecondsSinceEpoch.fromSecondsSinceEpoch
which I don't think was your intention.
Hi @KKimj are you still working on this? |
Hello! :) @mit-mit |
Hi @KKimj please respond to the comments in the review tool: https://dart-review.googlesource.com/c/sdk/+/405740 |
https://dart-review.googlesource.com/c/sdk/+/405740 has been updated with the latest commits from this pull request. |
1 similar comment
https://dart-review.googlesource.com/c/sdk/+/405740 has been updated with the latest commits from this pull request. |
|
Hi @KKimj code reviews for Dart happen in the code review tool, so kindly respond there, not here on github: |
@KKimj are you still working on addressing the code review comments ? |
sdk/lib/core/date_time.dart
Outdated
|
||
/// Adds methods for seconds since epoch to [DateTime] objects. | ||
@Since("3.8") | ||
extension DateTimeSecondsSinceEpoch on DateTime { |
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.
Hello,
Small question, why not making the change like other factories line 415 ?
external DateTime.fromMillisecondsSinceEpoch(
int millisecondsSinceEpoch, {
bool isUtc = false,
});
...
external DateTime.fromMicrosecondsSinceEpoch(
int microsecondsSinceEpoch, {
bool isUtc = false,
});
…nceEpoch` getter
https://dart-review.googlesource.com/c/sdk/+/405740 has been updated with the latest commits from this pull request. |
1 similar comment
https://dart-review.googlesource.com/c/sdk/+/405740 has been updated with the latest commits from this pull request. |
@KKimj when you are done, can you reply to the comments in https://dart-review.googlesource.com/c/sdk/+/405740?tab=comments ? |
sdk/lib/core/date_time.dart
Outdated
|
||
/// Adds methods for seconds since epoch to [DateTime] objects. | ||
@Since("3.8") | ||
extension DateTimeSecondsSinceEpoch on DateTime { |
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.
Is this extension useful as a getter has been set inside the DateTime class ?
/// DateTime.fromSecondsSinceEpoch(1641031200, isUtc:true); | ||
/// print(newYearsDay); // 2022-01-01 10:00:00.000Z | ||
/// ``` | ||
external DateTime.fromSecondsSinceEpoch( |
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 can see some logics about max value and validation for milliseconds and microseconds from epoch but nothing for seconds since epoch, is that expected ?
https://dart-review.googlesource.com/c/sdk/+/405740 has been updated with the latest commits from this pull request. |
1 similar comment
https://dart-review.googlesource.com/c/sdk/+/405740 has been updated with the latest commits from this pull request. |
Working-in-progress
Resolve : #59961
Contribution guidelines:
dart format
.Note that this repository uses Gerrit for code reviews. Your pull request will be automatically converted into a Gerrit CL and a link to the CL written into this PR. The review will happen on Gerrit but you can also push additional commits to this PR to update the code review.