-
Notifications
You must be signed in to change notification settings - Fork 7.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
Added DateTime[Immutable]::[get|set]Microseconds #12557
Conversation
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 am a little on the fence about the API here.
How often do you need to set only microseconds? Should, instead of adding setMicroseconds
, this be a second optional argument on setTimestamp
?
And of course, setTime()
already has the microsecond
argument too.
We don't have any setters for any of the other single date/time fields either.
Hi @derickr,
There are two different cases based on what to create a DateTime object from:
The second case might by another DateTime object, which is covered by
For me there are to reasons here to not add a second argument to
With
Personally I would like to have other getters and setters as well but this is definitively out of scope of this PR and might be better maintainable for libs like Carbon. Not sure. |
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.
You have me convinced with the API :-)
However, we don't have any tests in this PR yet! And these we need.
nice :)
True, now added |
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.
One nit about the test file, and after my earlier merge this now has a conflict. So could you please rebase (and feel free to force-push to your personal branch) and fix the conflicts?
44f9651
to
6bf195e
Compare
@derickr rebased and fixed your comments now |
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.
LGTM, but trying to sort out the test failure before merging.
6bf195e
to
aa19dd1
Compare
@derickr This was unrelated - Just rebased again and now everything is green 🎉 |
Also use |
Just an idea. What if we add new features to |
Introducing inconsistency isn't making anything better. If you want to see the mutable class go away, an RFC deprecating it would be a better way and if you are on it deprecating the function interface would be something I support. |
@marc-mabe, yes, agree. @derickr, I remember your tweet about datetime deprecations. Have you decided anything? |
9b5bc67
to
55204bd
Compare
55204bd
to
7316d8c
Compare
Rebased the PR. The test failure is unrelated due to #13299. @derickr @iluuu1994 can this PR be merged now? |
@@ -3844,12 +3844,76 @@ PHP_METHOD(DateTimeImmutable, setTimestamp) | |||
} | |||
/* }}} */ | |||
|
|||
/* {{{ */ | |||
PHP_METHOD(DateTimeImmutable, setMicroseconds) |
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 know I'm late to the party, but the 2 methods should share the same implementation, shouldn't they? Only ~2-3 lines differ, which could be handled easily one way or another.
This PR was merged into the 7.1 branch. Discussion ---------- [Clock] Add get/setMicroseconds() | Q | A | ------------- | --- | Branch? | 7.1 | Bug fix? | no | New feature? | yes | Deprecations? | no | Issues | - | License | MIT Polyfilling php/php-src#12557 Commits ------- 3e5b677 [Clock] Add get/setMicroseconds()
Follow up of #12413 to manage handling microseconds without precision loss or stringifying/parsing from string.