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


PHP Carbon::diffInSeconds方法代码示例

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


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

示例1: fire

 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     //
     $map = Map::findOrFail($this->argument('map'));
     $minimap = $map->minimap;
     if (!$minimap->locked || $this->option('force')) {
         // Call dibs on editing this minimap
         $supernow = new Carbon();
         $this->info('[' . Carbon::now() . '] Locking and processing map ' . $map->id);
         $minimap->updated_at = new \DateTime();
         $minimap->locked = true;
         $minimap->save();
         // Load the tiles. May take some time. =)
         $tiles = Tile::where('mapid', $map->id)->where('posz', 7)->get();
         // Prepare the canvas, maestro!
         \OTWorlds\MinimapPainter::$filename = $minimap->path;
         \OTWorlds\MinimapPainter::load($map->width, $map->height);
         foreach ($tiles as $tile) {
             \OTWorlds\MinimapPainter::paint(intval($tile->posx), intval($tile->posy), intval($tile->itemid));
         }
         // Finish up
         \OTWorlds\MinimapPainter::save();
         // Let other processes edit this map again
         $minimap->locked = false;
         $minimap->save();
         $donenow = new Carbon();
         $this->info('[' . $donenow->now() . '] Done. Processed ' . $tiles->count() . ' tiles in ' . $donenow->diffInSeconds($supernow) . ' seconds.');
     } else {
         $this->error('Minimap is locked. Either another process is using it, or the last one crashed. Use --force to ignore.');
     }
 }
开发者ID:Ablankzin,项目名称:OTWorlds,代码行数:36,代码来源:MinimapRefresh.php

示例2: process

 /**
  * Process
  *
  * @param mixed $value
  * @param array $options
  *
  * @return float|null
  */
 public function process($value, array $options = array())
 {
     $options = array_replace($this->getDefaultOptons(), $options);
     if ($value === null) {
         return;
     }
     if (is_object($value) || is_resource($value) || is_array($value)) {
         $this->throwException($options, 'error');
     }
     // Can be used to allow 'now' or 'today' for example
     if ($options['allow'] && in_array($value, $options['allow'])) {
         return $value;
     }
     if (!preg_match($this->getPattern(), $value, $matches)) {
         $this->throwException($options, 'error');
     }
     if (!$this->checkMatches($matches)) {
         $this->throwException($options, 'error');
     }
     if ($options['min'] || $options['max']) {
         $date = new Carbon($value);
         if ($options['min']) {
             $min = new Carbon($options['min']);
             if ($min === false || $min->getLastErrors()['warning_count']) {
                 throw new \InvalidArgumentException('Variable for "min" is not date');
             }
             if ($date->diffInSeconds($min, false) > 0) {
                 $this->throwException($options, 'error_max', array('date' => $options['min']));
             }
         }
         if ($options['max']) {
             $max = new Carbon($options['max']);
             if ($max === false || $max->getLastErrors()['warning_count']) {
                 throw new \InvalidArgumentException('Variable for "max" is not date');
             }
             if ($date->diffInSeconds($max, false) < 0) {
                 $this->throwException($options, 'error_max', array('date' => $options['max']));
             }
         }
     }
     return $value;
 }
开发者ID:apishka,项目名称:validator,代码行数:50,代码来源:DateTimeTypeAbstract.php

示例3: getAvgWaitTime

 /**
  * Gets average wait time
  *
  * @return integer
  */
 private function getAvgWaitTime()
 {
     $cases = $this->case->PendingCases();
     $arTime = [];
     foreach ($cases as $key => $case) {
         foreach ($case->messages as $id => $message) {
             if ($message->answers()->exists()) {
                 $postDate = new Carbon($message->post_date);
                 $answerDate = new Carbon($message->answers()->first()->post_date);
                 $waitTime = $answerDate->diffInSeconds($postDate);
                 array_push($arTime, $waitTime);
             }
         }
     }
     if (count($arTime) != 0) {
         return round(array_sum($arTime) / count($arTime) / 60);
     }
     return 0;
 }
开发者ID:rubenwouters,项目名称:crm-launcher,代码行数:24,代码来源:DashboardController.php

示例4: updateActivity

 public function updateActivity(Project $project, Activity $activity)
 {
     $started_at = new Carbon(Input::get('started_at'));
     $finished_at = new Carbon(Input::get('finished_at'));
     $diff = $started_at->diffInSeconds($finished_at);
     if ($diff < 0) {
         abort(500, 'Finished at should be after started at');
     }
     $activity->update(['description' => Input::get('description'), 'started_at' => $started_at, 'duration' => $diff, 'type' => Activity::TYPE_ACTIVITY, 'task_id' => Input::get('task_id')]);
 }
开发者ID:titus-toia,项目名称:treabar,代码行数:10,代码来源:ManagerController.php

示例5: lengthInSeconds

 /**
  * Get the difference between start and end dates of the period in seconds.
  *
  * @return int
  */
 public function lengthInSeconds()
 {
     return $this->startDate->diffInSeconds($this->endDate);
 }
开发者ID:asdf20122012,项目名称:carbon-period,代码行数:9,代码来源:CarbonPeriod.php

示例6: later

 /**
  * @param Carbon $date
  * @param $method
  * @param $data
  * @param null $queueName
  */
 public function later(Carbon $date, $method, $data, $queueName = null)
 {
     $delay = $date->diffInSeconds(Carbon::now()) * 1000;
     $this->push($method, $data, $queueName, $delay);
 }
开发者ID:icombats,项目名称:tail,代码行数:11,代码来源:Tail.php

示例7: cloneEvent

 public function cloneEvent(Request $request, Event $event)
 {
     $this->authorize('create-event');
     $this->validate($request, ['start_date' => 'required|date_format:Y-m-d']);
     // Set up event information
     $startDate = new Carbon($event->start_date);
     $endDate = new Carbon($event->end_date);
     $newStartDate = new Carbon($request->input('start_date'));
     $departments = $event->departments;
     // Find the difference of the start dates
     $difference = $startDate->diffInSeconds($newStartDate);
     // Create new event from old event data
     $newEvent = Event::create(['name' => $event->name, 'description' => $event->description, 'start_date' => $startDate->addSeconds($difference)->format('Y-m-d'), 'end_date' => $endDate->addSeconds($difference)->format('Y-m-d')]);
     // Add the image manually because it's not automatically fillable
     if ($event->image) {
         $newEvent->image = $event->image;
         $newEvent->save();
     }
     // Loop through event departments
     foreach ($departments as $department) {
         // Create new department
         $newDepartment = new Department();
         $newDepartment->event_id = $newEvent->id;
         $newDepartment->save();
         // Because the event_id isn't fillable, we have to define it first and then update
         $newDepartment->update(['name' => $department->name, 'description' => $department->description, 'roles' => $department->roles]);
         // Loop through shifts
         $shifts = $department->shifts;
         foreach ($shifts as $shift) {
             // Adjust shift dates
             $shift->start_date = new Carbon($shift->start_date);
             $shift->end_date = new Carbon($shift->end_date);
             $shift->start_date = $shift->start_date->addSeconds($difference)->format('Y-m-d');
             $shift->end_date = $shift->end_date->addSeconds($difference)->format('Y-m-d');
             // Update the department ID
             $shift->department_id = $newDepartment->id;
             $newShift = Shift::create(['department_id' => $newDepartment->id, 'name' => $shift->name, 'start_date' => $shift->start_date, 'end_date' => $shift->end_date, 'start_time' => $shift->start_time, 'end_time' => $shift->end_time, 'duration' => $shift->duration, 'roles' => $shift->roles]);
             Slot::generate($newShift);
         }
     }
     $request->session()->flash('success', 'Event has been cloned.');
     return redirect('/event/' . $newEvent->id);
 }
开发者ID:playatech,项目名称:laravel-voldb,代码行数:43,代码来源:EventController.php

示例8: validateTimestamp

 /**
  * Check recentish timestamp
  *
  * @param int $timestamp
  *        	The timestamp to be checked
  * @return boolean
  */
 public function validateTimestamp($timestamp)
 {
     $now = new Carbon();
     return $now->diffInSeconds(Carbon::createFromTimestamp($timestamp)) < $this->timestampThreshold;
 }
开发者ID:gponster,项目名称:laravel-oauth-server,代码行数:12,代码来源:Pdo.php

示例9: getPendingResponse

 private function getPendingResponse()
 {
     $startDate = new Carbon($this->start_date);
     $difference = $startDate->diffInSeconds(Carbon::now());
     if ($difference <= 0) {
         // exhausted pending time, auction must boot
         $this->bootAuction();
         return self::AUCTION_STATUS_MESSAGE_BOOTING;
     } else {
         // return difference as time
         return MediDateTime::differenceToTime($difference);
     }
 }
开发者ID:brightantwiboasiako,项目名称:biddingapp,代码行数:13,代码来源:Auction.php

示例10: setClosesAt

 /**
  * Set the closesAt attribute.
  *
  * @param Carbon $timestamp
  */
 public function setClosesAt(Carbon $timestamp)
 {
     $this->length = $timestamp->diffInSeconds($this->opensAt());
     $this->calculateClosesAt();
 }
开发者ID:krzystof,项目名称:business-calendar,代码行数:10,代码来源:HasOpenAndClosesAtAttributes.php

示例11: getRaidTuesdayCountdown

 public function getRaidTuesdayCountdown()
 {
     if (Carbon::now('America/Chicago')->isSameDay(new Carbon('Tuesday 4am CST', 'America/Chicago'))) {
         $raidtuesday = new Carbon('Tuesday 4am CST', 'America/Chicago');
     } else {
         $raidtuesday = new Carbon('next Tuesday 4 AM', 'America/Chicago');
     }
     if ($raidtuesday->lt(Carbon::now('America/Chicago'))) {
         return \Response::json(['error' => false, 'msg' => 'Today is Raid Tuesday! Get your raids in!']);
     } else {
         $countdown = $raidtuesday->diffInSeconds(Carbon::now('America/Chicago'));
         $countdown = Text::timeDuration($countdown);
         return \Response::json(['error' => false, 'msg' => $countdown]);
     }
 }
开发者ID:GMSteuart,项目名称:PandaLove,代码行数:15,代码来源:ApiV1Controller.php


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