当前位置: 首页>>代码示例>>PHP>>正文


PHP Carbon::timezone方法代码示例

本文整理汇总了PHP中Carbon\Carbon::timezone方法的典型用法代码示例。如果您正苦于以下问题:PHP Carbon::timezone方法的具体用法?PHP Carbon::timezone怎么用?PHP Carbon::timezone使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Carbon\Carbon的用法示例。


在下文中一共展示了Carbon::timezone方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: overview

 /**
  * @param Device $thermostat
  *
  * @return \Illuminate\Http\JsonResponse
  */
 public function overview(Device $thermostat)
 {
     $timezone = $thermostat->structure->tz();
     $city = City::findCity($thermostat->structure->postal_code, $thermostat->structure->country_code);
     /** @var \Grumpydictator\Gchart\GChart $chart */
     $chart = App::make('gchart');
     $chart->addColumn('Time', 'timeofday');
     $chart->addColumn('Target temperature', 'number');
     $chart->addColumn('Ambient temperature', 'number');
     $chart->addColumn('Outside temperature', 'number');
     $start = Carbon::now($timezone)->startOfDay();
     $end = Carbon::now($timezone)->endOfDay();
     $start->timezone('utc');
     $end->timezone('utc');
     // get all entries between start and end.
     $ambient = LogEntry::betweenTimes($start, $end)->withLogValue('target_temperature_c')->withLogValue('ambient_temperature_c')->orderBy('date', 'ASC')->where('log_entries.device_id', $thermostat->id)->get([DB::Raw('DATE_FORMAT(`log_entries`.`time`,"%Y-%m-%d %H:%i") as `date`'), DB::Raw('`target_temperature_c`.`value` AS `target_temperature_c`'), DB::Raw('`ambient_temperature_c`.`value` AS `ambient_temperature_c`')]);
     $chartData = [];
     foreach ($ambient as $entry) {
         /** @var Carbon $time */
         $time = $entry->date;
         $chartData[$time] = ['target_temperature_c' => floatval($entry->target_temperature_c), 'ambient_temperature_c' => floatval($entry->ambient_temperature_c), 'main_temp' => null];
     }
     unset($entry, $ambient, $time);
     // get outside temperature between start and end:
     $outside = Report::betweenTimes($start, $end)->withReportValue('main.temp')->orderBy('reports.time', 'ASC')->where('reports.city_id', $city->id)->get([DB::Raw('DATE_FORMAT(`reports`.`time`,"%Y-%m-%d %H:%i") as `date`'), DB::Raw('`main_temp`.`value` AS `main_temp`')]);
     foreach ($outside as $entry) {
         $time = $entry->date;
         $chartData[$time]['main_temp'] = floatval($entry->main_temp);
     }
     ksort($chartData);
     $previous = null;
     foreach ($chartData as $time => $row) {
         $obj = new Carbon($time);
         $obj->timezone($timezone);
         if (is_null($previous)) {
             $previous = clone $obj;
         }
         $target = isset($row['target_temperature_c']) ? $row['target_temperature_c'] : null;
         $ambient = isset($row['ambient_temperature_c']) ? $row['ambient_temperature_c'] : null;
         $main = isset($row['main_temp']) ? $row['main_temp'] : null;
         // only add row when previous is not null and time is not smaller than previous
         if (!is_null($previous) && $obj >= $previous) {
             $chart->addRow($obj, $target, $ambient, $main);
             $previous = clone $obj;
         }
     }
     $chart->generate();
     return Response::json($chart->getData());
 }
开发者ID:JC5,项目名称:marauder,代码行数:54,代码来源:ChartController.php

示例2: setUpdatedAt

 /**
  * Set the value of the "updated at" attribute.
  *
  * @param  mixed  $value
  * @return void
  */
 public function setUpdatedAt($value)
 {
     $this->{static::UPDATED_AT} = $value;
     if (!$value instanceof Carbon) {
         $value = new Carbon($value);
     }
     $this->{static::UPDATED_AT . '_gmt'} = $value->timezone('GMT');
 }
开发者ID:creativelittledots,项目名称:wp-kit-core,代码行数:14,代码来源:Post.php

示例3: publish

 public function publish($date, Carbon $startAt, Carbon $finishAt, $serviceId, $capacity = 1)
 {
     $vacancyKeys = ['business_id' => $this->business->id, 'service_id' => $serviceId, 'date' => $date];
     $vacancyValues = ['capacity' => intval($capacity), 'start_at' => $startAt->timezone('UTC')->toDateTimeString(), 'finish_at' => $finishAt->timezone('UTC')->toDateTimeString()];
     return Vacancy::updateOrCreate($vacancyKeys, $vacancyValues);
 }
开发者ID:timegridio,项目名称:concierge,代码行数:6,代码来源:VacancyManager.php

示例4: scopeAffectingInterval

 /**
  * Between Dates.
  *
  * @param Illuminate\Database\Query $query
  * @param Carbon                    $startAt
  * @param Carbon                    $finishAt
  *
  * @return Illuminate\Database\Query
  */
 public function scopeAffectingInterval($query, Carbon $startAt, Carbon $finishAt)
 {
     return $query->where(function ($query) use($startAt, $finishAt) {
         $query->where(function ($query) use($startAt, $finishAt) {
             $query->where('finish_at', '>=', $finishAt->timezone('UTC'))->where('start_at', '<=', $startAt->timezone('UTC'));
         })->orWhere(function ($query) use($startAt, $finishAt) {
             $query->where('finish_at', '<', $finishAt->timezone('UTC'))->where('finish_at', '>', $startAt->timezone('UTC'));
         })->orWhere(function ($query) use($startAt, $finishAt) {
             $query->where('start_at', '>', $startAt->timezone('UTC'))->where('start_at', '<', $finishAt->timezone('UTC'));
         })->orWhere(function ($query) use($startAt, $finishAt) {
             $query->where('start_at', '>', $startAt->timezone('UTC'))->where('finish_at', '<', $finishAt->timezone('UTC'));
         });
     });
 }
开发者ID:kdh4242,项目名称:timegrid,代码行数:23,代码来源:Appointment.php

示例5: scopeTillDate

 /**
  * Scope only till date.
  *
  * @param Illuminate\Database\Query $query
  * @param Carbon                    $date  Inquired range end date
  *
  * @return Illuminate\Database\Query Scoped appointments up to the inquired date
  */
 public function scopeTillDate($query, Carbon $date)
 {
     return $query->where('start_at', '<=', $date->timezone('UTC'));
 }
开发者ID:zeke8402,项目名称:timegrid,代码行数:12,代码来源:Appointment.php

示例6: todayAtSameTime

 /**
  * 日本時間で「今日の同時刻」を得る
  *
  * @param Carbon $time
  * @return Carbon
  */
 private function todayAtSameTime(Carbon $time)
 {
     $timezone = $time->timezone;
     // 日本人の感覚の「今日」にするため、日本時間で設定
     $sameTime = Carbon::now()->timezone('Asia/Tokyo');
     $time->timezone('Asia/Tokyo');
     $sameTime->hour = $time->hour;
     $sameTime->minute = $time->minute;
     $sameTime->second = $time->second;
     return $sameTime->timezone($timezone);
 }
开发者ID:HiroKws,项目名称:zakkuto-laravel-hub-site,代码行数:17,代码来源:CopyEverydayTasks.php

示例7: __toString

 public function __toString()
 {
     // 日付はタイムゾーンがバラバラなので、明示的に日本時間にする
     return 'URL:' . $this->source . "\n" . '日付:' . $this->date->timezone('Asia/Tokyo')->toDateTimeString() . "\n" . 'コンテンツ:' . "\n" . $this->content . "\n";
 }
开发者ID:HiroKws,项目名称:zakkuto-laravel-hub-site,代码行数:5,代码来源:FeedPosted.php


注:本文中的Carbon\Carbon::timezone方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。