php-store-hours icon indicating copy to clipboard operation
php-store-hours copied to clipboard

Render tomorrow or first day that the store is opened if store is closed.

Open ctrlmaniac opened this issue 8 years ago • 4 comments

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?

ctrlmaniac avatar Jul 07 '16 21:07 ctrlmaniac

Or perhaps, "We're open again in n hours and n minutes". ;o)

ghost avatar Aug 30 '16 19:08 ghost

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 avatar Apr 13 '17 18:04 Spreizu

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

dannyinhull avatar Aug 31 '21 22:08 dannyinhull

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

dannyinhull avatar Aug 31 '21 22:08 dannyinhull