pimplesushant-pere

Timezone + Incomplete

Feb 4th, 2019
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.15 KB | None | 0 0
  1. if (!function_exists('timezone_diff')) {
  2.     function timezone_diff()
  3.     {
  4.         $countries = Country::all();
  5.  
  6.         $now_utc = \Carbon\Carbon::now('UTC');
  7.         $yesterday_start = \Carbon\Carbon::create($now_utc->year, $now_utc->month, $now_utc->day, 00, 00, 01)->subDay();
  8.         $yesterday_end = \Carbon\Carbon::create($now_utc->year, $now_utc->month, $now_utc->day, 23, 59, 59)->subDay();
  9.         $utc_midnight = \Carbon\Carbon::create($now_utc->year, $now_utc->month, $now_utc->day, 0, 0, 0);
  10.  
  11.         $times['$yesterday_start'] = $yesterday_start->format('Y-m-d H:i:s');
  12.         $times['$yesterday_end'] = $yesterday_end->format('Y-m-d H:i:s');
  13.         $times['$utc_midnight'] = $utc_midnight->format('Y-m-d H:i:s');
  14.         $times['$now_utc'] = $now_utc->format('Y-m-d H:i:s');
  15.  
  16.         foreach ($countries as $country) {
  17.             $country_now = \Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $now_utc, 'UTC');
  18.             $country_now->setTimezone($country->timezone);
  19.             $country_now = $country_now->format('Y-m-d H:i:s');
  20.             $times[$country->name] = $country_now;
  21.         }
  22.         return preview($times);
  23.     }
  24. }
Add Comment
Please, Sign In to add comment