/** * 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.'); } }
/** * 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; }
/** * 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; }
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')]); }
/** * Get the difference between start and end dates of the period in seconds. * * @return int */ public function lengthInSeconds() { return $this->startDate->diffInSeconds($this->endDate); }
/** * @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); }
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); }
/** * 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; }
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); } }
/** * Set the closesAt attribute. * * @param Carbon $timestamp */ public function setClosesAt(Carbon $timestamp) { $this->length = $timestamp->diffInSeconds($this->opensAt()); $this->calculateClosesAt(); }
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]); } }