SHARE
TWEET

Untitled

a guest Jun 19th, 2017 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2. * Returns true if store is closed
  3. *
  4. * @param mixed $store_id
  5. * @param string $day int 1-7
  6. * @param int $time format '00:00' - '23:59'
  7. * @return bool
  8. */
  9. function is_store_closed($store_id)
  10. {
  11.     $CI =& get_instance();
  12.    
  13.     $hours = StoreHours::getHours(1, 3);
  14.    
  15.     $format = 'H:i';
  16.    
  17.     // break up current time
  18.     $current    = explode(':', date($format, time()));
  19.     $current_h = intval($current[0]);
  20.     $current_m = intval($current[1]);
  21.  
  22.     // break up open time    
  23.     $open          = explode(':', convert_to_gmt('08:00', 'America/Los_Angeles'));
  24.     $open_h        = intval($open[0]);
  25.     $open_m        = intval($open[1]);
  26.    
  27.     // break up closed time
  28.     $closed        = explode(':', convert_to_gmt('20:00', 'America/Los_Angeles'));
  29.     $closed_h      = intval($closed[0]);
  30.     $closed_m      = intval($closed[1]);
  31.    
  32.     // break up first and second shift times if exist
  33.     if ($hours->split_from != '' && $hours->split_to != '')
  34.     {
  35.         $open2     = explode(':', convert_to_gmt($hours->split_from, 'America/Los_Angeles'));
  36.         $open2_h   = intval($open2[0]);
  37.         $open2_m   = intval($open2[1]);
  38.        
  39.         $closed2   = explode(':', convert_to_gmt($hours->split_to, 'America/Los_Angeles'));
  40.         $closed2_h = intval($closed2[0]);
  41.         $closed2_m = intval($closed2[1]);
  42.     }
  43.    
  44.     $restaurant_closed = true;
  45.    
  46.     if ( ($current_h >= $open_h) && ($current_m >= $open_m) && ($current_h <= $closed_h) && ($current_h <= $closed_m) )
  47.         $store_closed = false;
  48.        
  49.     if (!$store_closed) echo 'STORE IS OPEN!';
  50.     else echo 'STORE IS CLOSED!';
  51.        
  52. }
  53.  
  54. /**
  55. * Convert's store's time to GMT
  56. * @return string
  57. */
  58. function convert_to_gmt($time = false, $timezone_str = 'GMT')
  59. {
  60.     $format = 'H:i';
  61.    
  62.     $time = ($time === false) ? 'now' : date($format, strtotime($time));
  63.    
  64.     $store_time = new DateTime($time, new DateTimeZone($timezone_str));
  65.    
  66.     $store_time->setTimezone(new DateTimeZone('GMT'));
  67.  
  68.     return $store_time->format($format);
  69. }
RAW Paste Data
Top