php-store-hours
php-store-hours copied to clipboard
Render tomorrow or first day that the store is opened if store is closed.
I think that one thing is missing. The fact that I can't print tomorrow's hours or the first hour's day that the store is opened when the store is actually close. As much as Google do in google search, it says at what hour the store will open if the store is actually closed, or it says if the store is going to close and so on.
Can you please at least add the feature that prints tomorrow hours?
Or perhaps, "We're open again in n hours and n minutes". ;o)
I was also looking for this function, but because it was not available, I came up with something myself.. Feel free to modify the output to your needs. Currently it outputs an array with date as key and time as value, when store is open again.
/**
*
* @param string $timestamp
* @return array Date & Time store is open again
*/
public function opens_at($timestamp = null)
{
$timestamp = (null !== $timestamp) ? $timestamp : time();
$weekday_short = date('N', $timestamp);
$dateformat = 'd.m.Y';
$i = 0;
// Check whether we are open today
$opens_at_all = $this->hours_today($timestamp);
// Not open today
if (empty($opens_at_all))
{
for ($i = 1; $i <= 7; $i++)
{
// Create a new timestamp
$newtimestamp = strtotime('+'. $i .' days', $timestamp);
// Check whether we are open
$opens_at_all = $this->hours_today($newtimestamp);
if (!empty($opens_at_all))
break;
}
}
// Opens today
if (isset($opens_at_all[0]))
{
list($opens_at, $closes_at) = explode('-', $opens_at_all[0]);
return array(date($dateformat, strtotime(date($dateformat) . ' +'. $i .' day')) => $opens_at);
}
return array();
}
Spreizu ive tired using your code but it gives error on 1st line - public function opens_at($timestamp = null)
do you know how i can fixthis please? thanks
I was also looking for this function, but because it was not available, I came up with something myself.. Feel free to modify the output to your needs. Currently it outputs an array with date as key and time as value, when store is open again.
/** * * @param string $timestamp * @return array Date & Time store is open again */ public function opens_at($timestamp = null) { $timestamp = (null !== $timestamp) ? $timestamp : time(); $weekday_short = date('N', $timestamp); $dateformat = 'd.m.Y'; $i = 0; // Check whether we are open today $opens_at_all = $this->hours_today($timestamp); // Not open today if (empty($opens_at_all)) { for ($i = 1; $i <= 7; $i++) { // Create a new timestamp $newtimestamp = strtotime('+'. $i .' days', $timestamp); // Check whether we are open $opens_at_all = $this->hours_today($newtimestamp); if (!empty($opens_at_all)) break; } } // Opens today if (isset($opens_at_all[0])) { list($opens_at, $closes_at) = explode('-', $opens_at_all[0]); return array(date($dateformat, strtotime(date($dateformat) . ' +'. $i .' day')) => $opens_at); } return array(); }
Spreizu ive tired using your code but it gives error on 1st line - public function opens_at($timestamp = null)
do you know how i can fixthis please? thanks