Skip to content

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

moebrowne
Copy link

The existing code is unnecessarily hard to understand.

Copy link
Member

@arkhi arkhi left a 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.

Comment on lines +78 to +84
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;
Copy link
Member

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.

Suggested change
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;

Copy link
Author

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

Copy link
Member

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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants