本文整理汇总了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());
}
示例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');
}
示例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);
}
示例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'));
});
});
}
示例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'));
}
示例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);
}
示例7: __toString
public function __toString()
{
// 日付はタイムゾーンがバラバラなので、明示的に日本時間にする
return 'URL:' . $this->source . "\n" . '日付:' . $this->date->timezone('Asia/Tokyo')->toDateTimeString() . "\n" . 'コンテンツ:' . "\n" . $this->content . "\n";
}