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
3.0 - Use DateTime in Time utility 'is' and 'was' comparisons #2251
Conversation
All this code looks very similar. May be you can put the main code into a protected method and parameterize it? Something like: _isSameDate($dateString, $format1, $format2, $timezone = null) |
I like @ravage84's suggestion. |
Or, alternatively, do we want to scrap all these methods and have a single public method with an options parameter? Incomplete, but illustrates the idea:
Edit: Maybe name the method 'compareTo'? |
I think the named methods are nice as they make the calling code more expressive and easier to read. If those methods all use a single method internally that is fine. |
@markstory Sounds good, will update later this evening. |
Any comments on this? |
* @return boolean True if datetime string is within the constraint | ||
*/ | ||
protected static function _evaluateConstraint($dateString, $timezone = null, $anchor, $format) { | ||
$dateTime = new \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.
I am usually a fan of keeping object variables uppercase on first letter ($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.
I think having it as lowercase is fine for 3.x. We will be using object more extensively and the code will look like a giant collection of uppercase letters if we follow that.
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 used to use $Foo as well, but it got really annoying as code started having more objects.
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.
So will we drop if for 3.x completely? Or just for php-internal objects etc?
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 like lowercase as well.
Also maybe $dateTime = new \DateTime();
instead of $dateTime = new \DateTime;
(without the brackets).
Refactoring looks good, although I'm concerned that we are making more difficult to spot and fix this ticket which is related to the functions you are changing #2032 |
The new refactorings look good. |
* @param string $format The date and time format used for comparison | ||
* @return boolean True if datetime string is within the constraint | ||
*/ | ||
protected static function _evaluateConstraint($dateString, $timezone = null, $anchor, $format) { |
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.
The default value for $timezone
isn't really useful here, because the rest of the parameters are mandatory.
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.
Yeah optional arguments followed by mandatory ones is generally frowned upon.
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.
Maybe $timezone (if optional compared to the others) should then be the last one.
Moved the "timezone" parameter to be the last parameter. Renamed the method to be semantically correct. |
Looks great. |
Still not fully happy with the name |
Yeah I feel (because it returns a boolean) it should be |
@Phally 👍 I like that better too. |
Excellent! |
3.0 - Use DateTime in Time utility 'is' and 'was' comparisons
No description provided.