Skip to content

Instantly share code, notes, and snippets.

@bohnna
Last active October 8, 2015 23:42
Show Gist options
  • Select an option

  • Save bohnna/2eeaacacb4e7f09e98c6 to your computer and use it in GitHub Desktop.

Select an option

Save bohnna/2eeaacacb4e7f09e98c6 to your computer and use it in GitHub Desktop.
function blahblahblah() {
$hours = get_op_hours();
$current_time = dateTime::createFromFormat('h:i a', date('h:i a', current_time('timestamp')));
$close_time = dateTime::createFromFormat('h:i a', $hours['close']);
$open_time = dateTime::createFromFormat('h:i a', $hours['open']);
if (is_business_open($hours['open'], $hours['close'])) {
$diff = $close_time->diff($current_time);
if ($diff->h < 5 && $diff->h >= 1) {
if ($diff->h === 1) {
if ($diff->i < 59 && $diff->i > 0) {
echo 'Closing in ' . $diff->format('%h hour %i minutes.');
} else {
echo 'Closing in ' . $diff->format('%h hour.');
}
} else {
if ($diff->i < 59 && $diff->i > 0) {
$rounded = $diff->format('%h');
$rounded++;
echo 'Closing in less than ' . $rounded . ' hours.';
} else {
echo 'Closing in ' . $diff->format('%h hours.');
}
}
} elseif ($diff->h < 1 && $diff->i > 0) {
if ($diff->i === 1) {
echo 'Closing in ' . $diff->format('%i minute.');
} else {
echo 'Closing in ' . $diff->format('%i minutes.');
}
}
} elseif (!is_business_open($hours['open'], $hours['close'])) {
$diff = $current_time->diff($open_time);
if ($diff->h < 5) {
if ($diff->h === 1) {
if ($diff->i > 1) {
echo 'Opening in ' . $diff->format('%h hour %i minutes.');
} else {
echo 'Opening in ' . $diff->format('%h hour.');
}
} elseif ($diff->h === 0) {
if ($diff->i > 1) {
echo 'Opening in ' . $diff->format('%i minutes.');
} elseif ($diff->i === 1) {
echo 'Opening in ' . $diff->format('%i 1 minute.');
}
} else {
if ($diff->i > 1) {
echo 'Opening in ' . $diff->format('%h hours %i minutes.');
} else {
echo 'Opening in ' . $diff->format('%h hours.');
}
}
} elseif ($diff->h > 5) {
echo 'Closed';
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment