-
Notifications
You must be signed in to change notification settings - Fork 115
Adds better code example #251
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
base: master
Are you sure you want to change the base?
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.
Thanks for the PR!
I left two comments. Let me know what you think and do what you feel is better.
function isNakedDay() | ||
{ | ||
$now = new \DateTime('now', new \DateTimeZone('UTC')); | ||
$start = new \DateTime('00:00, April 9', new \DateTimeZone('+14:00')); | ||
$end = new \DateTime('23:59:59.999999, April 9', new \DateTimeZone('-12:00')); | ||
|
||
return $now >= $start && $now <= $end; |
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.
Should we simplify it a step further? :)
This would also ensure consistency with the explanation below the code.
function isNakedDay() | |
{ | |
$now = new \DateTime('now', new \DateTimeZone('UTC')); | |
$start = new \DateTime('00:00, April 9', new \DateTimeZone('+14:00')); | |
$end = new \DateTime('23:59:59.999999, April 9', new \DateTimeZone('-12:00')); | |
return $now >= $start && $now <= $end; | |
function isNakedDay() | |
{ | |
$now = new \DateTime('now', new \DateTimeZone('UTC')); | |
$start = new \DateTime('00:00, April 9', new \DateTimeZone('+14:00')); | |
$end = new \DateTime('00:00, April 10', new \DateTimeZone('-12:00')); | |
return $now >= $start && $now < $end; |
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 personally feel it is better to be explicit because there is general confusion over whether 00:00 is the start or end of the day: https://en.wikipedia.org/wiki/Midnight
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 term Midnight is ambiguous, indeed, as are 12-hours clocks, with AM and PM being used to try to make some sense out of it. I know of no confusion about 00:00 being the start of the day though.
As the article you’re pointing to tells us, and based on ISO, while they represent the exact same time, 00:00:00 is the start of the day, 24:00:00 the end of the day, and Midnight subject to interpretations. :)
I wonder how a \DateTime('24:00, April 9', new \DateTimeZone('-12:00'));
would behave.
Co-authored-by: Fabien Basmaison <[email protected]>
The existing code is unnecessarily hard to understand.