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


PHP Carbon::startOfDay方法代码示例

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


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

示例1: getStartDateForPeriod

 /**
  * @param string $period
  *
  * @return Carbon
  */
 public function getStartDateForPeriod($period)
 {
     $start = new Carbon();
     switch ($period) {
         default:
         case 'month':
             $start->startOfDay();
             $start->subMonth();
             break;
         case 'year':
             $start->startOfMonth();
             $start->subYear();
             break;
     }
     return $start;
 }
开发者ID:JC5,项目名称:marauder,代码行数:21,代码来源:ChartHelper.php

示例2: index

 public function index(Request $request)
 {
     $now = new Carbon();
     if ($request->isMethod('post')) {
         $from = new Carbon($request->input('from', $now->toDateString()));
         $to = new Carbon($request->input('to', $now->toDateString()));
         $lessons = \App\Lesson::orderBy('given_at', 'asc')->where('given_at', '>=', $from->startOfDay()->toDateTimeString())->where('given_at', '<=', $to->endOfDay()->toDateTimeString())->get();
     } else {
         $lessons = \App\Lesson::orderBy('given_at', 'asc')->get();
     }
     $groups = \App\CustomerGroup::orderBy('groupname', 'desc')->get();
     return view('lesson.index')->with(['lessons' => $lessons, 'groups' => $groups, 'now' => $now->toDateString(), 'from' => isset($from) ? $from->toDateString() : '', 'to' => isset($to) ? $to->toDateString() : '']);
 }
开发者ID:bengitiger,项目名称:cleverup-crm-laravel5,代码行数:13,代码来源:LessonController.php

示例3: index

 /**
  * Display a listing of tarefas
  *
  * @return Response
  */
 public function index()
 {
     $data = Input::get();
     $data['view'] = Input::has('view') ? Input::get('view') : 'today';
     // today, late, next, done
     $data['paginate'] = Input::has('paginate') ? Input::get('paginate') : 10;
     $dt = new Carbon();
     $tarefas = Tarefa::where(function ($query) use($data, $dt) {
         switch ($data['view']) {
             case 'late':
                 $query->where('date', '<', $dt->format('Y-m-d'))->where('done', false);
                 break;
             case 'next':
                 $query->where('date', '>', $dt->format('Y-m-d'))->where('done', false);
                 break;
             case 'done':
                 $query->where('done', true);
                 break;
             default:
                 // TODAY
                 $query->where('date', '>=', $dt->startOfDay()->format('Y-m-d'))->where('date', '<=', $dt->endOfDay()->format('Y-m-d'));
                 break;
         }
     })->orderBy(Input::get('order_by', 'date'), Input::get('order', 'DESC'))->with('cliente', 'conversas')->paginate(Input::get('paginate', 10));
     // $tarefas = Tarefa::orderBy('date', 'DESC')->with('cliente')->get();
     $hoje = date('Y-m-d');
     $ontem = Carbon::create(date('Y'), date('m'), date('d'))->subDay();
     $amanha = Carbon::create(date('Y'), date('m'), date('d'))->addDay();
     $proximo = Carbon::create(date('Y'), date('m'), date('d'))->addDay();
     //Igual amanhã?
     if ($proximo->isWeekend()) {
         $proximo = new Carbon('next monday');
     }
     $tarefas->pendentes = Tarefa::where('date', '<', $hoje)->where('done', 0)->orderBy('date', 'ASC')->with('cliente', 'conversas')->get();
     $tarefas->hoje = Tarefa::where('date', '<', $amanha->startOfDay())->where('date', '>', $ontem)->where('done', 0)->with('cliente', 'conversas')->get();
     $tarefas->nextDay = Tarefa::where('done', 0)->where('date', '>=', $amanha)->where('date', '<', $proximo->addDay())->orderBy('date', 'DESC')->with('cliente', 'conversas')->get();
     $tarefas->proximas = Tarefa::where('date', '>=', $amanha)->orderBy('date', 'ASC')->where('done', 0)->with('cliente', 'conversas')->get();
     $tarefas->concluidas = Tarefa::where('done', 1)->orderBy('updated_at', 'DESC')->with('cliente', 'conversas')->get();
     $tarefas->days = $tarefas->groupBy(function ($tarefa) {
         return date('Y-m-d', strtotime($tarefa->date));
     });
     if (Request::ajax()) {
         return $tarefas;
     }
     if (Route::is('tarefas.print')) {
         return View::make('tarefas.print', compact('tarefas'));
     } else {
         return View::make('tarefas.index', compact('tarefas'));
     }
 }
开发者ID:waldenylson,项目名称:alfredapp,代码行数:55,代码来源:TarefasController.php

示例4: getHeatDistribution

 /**
  * @param Device $thermostat
  *
  * @return array
  */
 public function getHeatDistribution(Device $thermostat)
 {
     $return = ['today' => ['night' => 0, 'morning' => 0, 'afternoon' => 0, 'evening' => 0], 'yesterday' => ['night' => 0, 'morning' => 0, 'afternoon' => 0, 'evening' => 0], 'average' => ['night' => 0, 'morning' => 0, 'afternoon' => 0, 'evening' => 0]];
     // get total for today, grouped per hour
     // today:
     $result = $thermostat->logEntries()->onDay(new Carbon())->withLogValue('is_heating_on')->groupBy('hour')->whereNotNull('is_heating_on.value')->get([DB::Raw('date_format(log_entries.time,"%H") as `hour`'), DB::Raw('SUM(is_heating_on.value) * 5 as is_heating_on')]);
     $total = $result->sum('is_heating_on');
     foreach ($result as $entry) {
         $hour = intval($entry->hour);
         $total += $entry->is_heating_on;
         if ($hour >= 0 && $hour < 6) {
             $return['today']['night'] += intval($entry->is_heating_on);
         }
         if ($hour >= 6 && $hour < 12) {
             $return['today']['morning'] += intval($entry->is_heating_on);
         }
         if ($hour >= 12 && $hour < 18) {
             $return['today']['afternoon'] += intval($entry->is_heating_on);
         }
         if ($hour >= 18 && $hour <= 23) {
             $return['today']['evening'] += intval($entry->is_heating_on);
         }
     }
     // for each hour loop and group.
     // get total for yesterday, grouped per hour
     $result = $thermostat->logEntries()->onDay(Carbon::now()->subDay())->withLogValue('is_heating_on')->groupBy('hour')->whereNotNull('is_heating_on.value')->get([DB::Raw('date_format(log_entries.time,"%H") as `hour`'), DB::Raw('SUM(is_heating_on.value) * 5 as is_heating_on')]);
     $total = $result->sum('is_heating_on');
     foreach ($result as $entry) {
         $hour = intval($entry->hour);
         $total += $entry->is_heating_on;
         if ($hour >= 0 && $hour < 6) {
             $return['yesterday']['night'] += intval($entry->is_heating_on);
         }
         if ($hour >= 6 && $hour < 12) {
             $return['yesterday']['morning'] += intval($entry->is_heating_on);
         }
         if ($hour >= 12 && $hour < 18) {
             $return['yesterday']['afternoon'] += intval($entry->is_heating_on);
         }
         if ($hour >= 18 && $hour <= 23) {
             $return['yesterday']['evening'] += intval($entry->is_heating_on);
         }
     }
     // get average (using log entries AND summaries).
     // log entries first:
     // (summaries start after five days)
     // go back five days.
     $today = new Carbon();
     $today->startOfDay();
     $today->subDays(5);
     $result = $thermostat->logEntries()->withLogValue('is_heating_on')->after($today)->groupBy('hour')->whereNotNull('is_heating_on.value')->get([DB::Raw('date_format(log_entries.time,"%H") as `hour`'), DB::Raw('SUM(is_heating_on.value) * 5 as is_heating_on')]);
     $total = $result->sum('is_heating_on');
     foreach ($result as $entry) {
         $hour = intval($entry->hour);
         $total += $entry->is_heating_on;
         if ($hour >= 0 && $hour < 6) {
             $return['average']['night'] += intval($entry->is_heating_on);
         }
         if ($hour >= 6 && $hour < 12) {
             $return['average']['morning'] += intval($entry->is_heating_on);
         }
         if ($hour >= 12 && $hour < 18) {
             $return['average']['afternoon'] += intval($entry->is_heating_on);
         }
         if ($hour >= 18 && $hour <= 23) {
             $return['average']['evening'] += intval($entry->is_heating_on);
         }
     }
     // then, summaries!
     $result = $thermostat->summaryEntries()->withSummaryValue('is_heating_on')->before($today)->groupBy('hour')->whereNotNull('is_heating_on.value')->get([DB::Raw('date_format(summary_entries.time,"%H") as `hour`'), DB::Raw('SUM(is_heating_on.value) as is_heating_on')]);
     $total = $result->sum('is_heating_on');
     foreach ($result as $entry) {
         $hour = intval($entry->hour);
         $total += $entry->is_heating_on;
         if ($hour >= 0 && $hour < 6) {
             $return['average']['night'] += intval($entry->is_heating_on);
         }
         if ($hour >= 6 && $hour < 12) {
             $return['average']['morning'] += intval($entry->is_heating_on);
         }
         if ($hour >= 12 && $hour < 18) {
             $return['average']['afternoon'] += intval($entry->is_heating_on);
         }
         if ($hour >= 18 && $hour <= 23) {
             $return['average']['evening'] += intval($entry->is_heating_on);
         }
     }
     // do percentage for each
     foreach ($return as $type => $entry) {
         $sum = $entry['night'] + $entry['morning'] + $entry['afternoon'] + $entry['evening'];
         if ($sum > 0) {
             $return[$type]['night'] = round($entry['night'] / $sum * 100);
             $return[$type]['morning'] = round($entry['morning'] / $sum * 100);
             $return[$type]['afternoon'] = round($entry['afternoon'] / $sum * 100);
             $return[$type]['evening'] = round($entry['evening'] / $sum * 100);
//.........这里部分代码省略.........
开发者ID:JC5,项目名称:marauder,代码行数:101,代码来源:Home.php

示例5: summarize

 /**
  * Summarize the report entries from 5 days ago, to comply with Google Nest's
  * data retention rules.
  */
 public function summarize()
 {
     // go back five days.
     $today = new Carbon();
     $today->startOfDay();
     $today->subDays(5);
     echo "<pre>\n";
     echo "Starting on " . $today->format('d M Y') . "\n";
     // these have our interest.
     $summaries = [];
     $logToSave = ['has_leaf', 'is_heating_on'];
     // indicates that these entries 'add minutes', ie. each entry is +5 minutes.
     $addsMinutes = ['has_leaf', 'is_heating_on'];
     // get all log entries
     $logEntries = $this->_helper->getLogEntriesForDay($today);
     // debug info:
     echo 'Found ' . $logEntries->count() . ' log entries to summarize' . "\n";
     // loop all:
     /** @var Report $logEntry */
     foreach ($logEntries as $logEntry) {
         // get current hour.
         $hour = intval($logEntry->time->format('H'));
         // summary entry:
         if (!isset($summaries[$hour])) {
             // make time:
             $time = clone $logEntry->time;
             $time->hour = $hour;
             $time->minute = 0;
             $time->second = 0;
             // set initial variables:
             $summaries[$hour]['time'] = $time;
             $summaries[$hour]['device'] = intval($logEntry->device_id);
             $summaries[$hour]['entries'] = [];
         }
         // get relevant log entries:
         $values = $this->_helper->getLogValuesByEntry($logEntry, $logToSave);
         // loop them
         /** @var LogValue $value */
         foreach ($values as $value) {
             $name = $value->name;
             // some are booleans, they add to a total time:
             if (in_array($name, $addsMinutes)) {
                 $value = intval($value->value);
                 if ($value == 1) {
                     $summaries[$hour]['entries'][$name] = isset($summaries[$hour]['entries'][$name]) ? $summaries[$hour]['entries'][$name] + 5 : 5;
                 }
             }
             // others are numbers and become an average (like temp).
         }
     }
     // save all summaries built:
     foreach ($summaries as $summary) {
         $entry = $this->_helper->getSummaryEntry($summary['device'], $summary['time']);
         foreach ($summary['entries'] as $name => $value) {
             $value = $this->_helper->createSummaryValue($entry, $name, $value);
             if ($value === false) {
                 echo 'Could not save summary value for time ' . $summary['time']->format('d M Y H:i:s') . ' because value with name "' . $name . '" is already saved for entry #' . $entry->id . "!\n";
             }
         }
         echo "Saved " . $entry->summaryValues()->count() . " summarized fields (+values) for time " . $entry->time->format('d M Y H:i:s') . ".\n";
     }
     echo "Done summarizing.\n";
 }
开发者ID:JC5,项目名称:marauder,代码行数:67,代码来源:CronController.php

示例6: asDateFromValue

 /**
  * Create a Carbon date from a value that should be in the format.
  *
  * @param  mixed $value of date
  * @param  string $format date should be in
  * @return Carbon\Carbon|null
  */
 protected function asDateFromValue($value = null, $format = 'm/d/Y')
 {
     if ($value instanceof Carbon) {
         return $value;
     }
     try {
         return Carbon::createFromFormat($format, $value)->startOfDay();
     } catch (InvalidArgumentException $e) {
     }
     try {
         $date = new Carbon($value);
         return $date->startOfDay();
     } catch (InvalidArgumentException $e) {
         return null;
     }
 }
开发者ID:esensi,项目名称:core,代码行数:23,代码来源:DateValidator.php


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