protected function checkStamp($style, $data) { switch ($style) { case 1: $search = \App\Firstcache::where('star', $data['star'])->where('size', $data['size'])->where('class', $data['class'])->where('planet', $data['planet'])->where('step', $data['step'])->first(); break; case 2: $search = \App\Secondcache::where('style', $data['style'])->first(); break; case 3: $search = \App\Thirdcache::where('star', $data['star'])->where('size', $data['size'])->where('class', $data['class'])->first(); break; case 0: $search = \App\Zerocache::where('id', '>', 0)->first(); break; } if ($search) { $created = new Carbon($search->created_at); $now = Carbon::now(); if ($created->diffInMinutes($now) > 180) { $search->delete(); return false; } $this->chart = unserialize($search->data); return true; } return false; }
public function cancelReservation(User $user, Trip $trip) { $now = new Carbon(); $departure = new Carbon($trip->leaves_at); $reservation = Booking::where('user_id', $user->id)->where('trip_id', $trip->id)->first(); $reservationTime = new Carbon($reservation->created_at); $percent = $now->diffInMinutes($reservationTime) / $departure->diffInMinutes($reservationTime); $karma = round(1 + pow(pow(47, 1 / 3) * $percent, 3)); $user->karma = $user->karma - $karma; $user->save(); }
public static function score(Pirep &$pirep, $rule) { $pirepStart = new Carbon($pirep->pirep_start_time); $offBlocks = new Carbon($pirep->off_blocks_time); $length = $pirepStart->diffInMinutes($offBlocks); foreach ($rule['thresholds'] as $threshold) { // Does the preparation time meet this threshold? if ($length >= $threshold['moreThan'] && $length <= $threshold['lessThan']) { return ['name' => $threshold['name'], 'points' => $threshold['points']]; } } throw new UnsuccessfulScoringException(); }
public static function score(Pirep &$pirep, $rule) { $flightStart = new Carbon($pirep->departure_time); $flightEnd = new Carbon($pirep->landing_time); $length = $flightStart->diffInMinutes($flightEnd); foreach ($rule['thresholds'] as $threshold) { // Does the flight length meet this threshold? if ($length >= $threshold['moreThan'] && $length <= $threshold['lessThan']) { return ['name' => $threshold['name'], 'points' => $threshold['points']]; } } throw new UnsuccessfulScoringException(); }
/** * Execute the console command. * * @return mixed */ public function fire() { // $dt = Carbon::now('Asia/Colombo'); $spams = spam::get(); foreach ($spams as $spam) { $dt2 = new Carbon($spam->updated_at, 'Asia/Colombo'); $val = $dt2->diffInMinutes($dt); if ($val > 6) { $spam->delete(); } } $this->info('spam table cleard!'); }
public function getNearestPostDuration($key) { if ($duration = $this->cache->get($key . '-duration')) { return $duration; } else { $nearest_scheduled_post = $this->post->nearestScheduledPost(); if (!is_null($nearest_scheduled_post)) { $nearest_scheduled_posts_date = new Carbon($nearest_scheduled_post->publish_date, config('app.timezone')); $time_difference = $nearest_scheduled_posts_date->diffInMinutes(Carbon::now(config('app.timezone'))) + 1; if ($time_difference > 0) { $duration = $this->cache->remember($key . '-duration', function () use($time_difference) { return $time_difference; }, ['posts'], $time_difference); return $duration; } } } }
/** * Remove the specified post from storage. * * @param int $id * * @return Response */ public function destroy($id) { $post = $this->postRepository->find($id); if (empty($post)) { Flash::error('post no encontrada.'); return redirect(url('home')); } $created = new Carbon($post->created_at); $transcurrido = $created->diffInMinutes(); if (Auth::user()->rol != 'admin' && $transcurrido < 120) { Flash::warning('Deben pasar 2 horas para poder eliminar el Post han pasado ' . $transcurrido . ' minutos desde la creación'); return redirect(url('home')); } $this->postRepository->delete($id); if (file_exists($post->imagen)) { unlink($post->imagen); } if (file_exists($post->archivo)) { unlink($post->archivo); } Flash::success('Post borrado satisfactoriamente.'); return redirect(url('home')); }
/** * Get the difference between start and end dates of the period in minutes. * * @return int */ public function lengthInMinutes() { return $this->startDate->diffInMinutes($this->endDate); }
private function getIntervalMinutes() { $dt = new Carbon('today ' . $this->interval); $diff_minutes = $dt->diffInMinutes(Carbon::today()); return $diff_minutes; }
public static function ageInDays(Carbon $date) : string { return number_format(round($date->diffInMinutes() / (24 * 60), 2), 2) . ' (' . $date->diffForHumans() . ')'; }
public function storeSchedule() { $input['json'] = '{ "user": "******", "event": "1", "time_slots": [ { "start": 1411239474, "end": 1411539474, "weighting": "5" }, { "start": 1411269474, "end": 1411549474, "weighting": "5" } ] }'; $decoded = json_decode($input['json']); $user_id = $decoded->user; $occasion_id = $decoded->event; // Get the occasion tied to the user $occasion = User::find($user_id)->occasions->find($occasion_id); if ($occasion == null) { return null; } $time_slots = $decoded->time_slots; $insert = array(); for ($i = 0; $i < count($time_slots); $i++) { $start = $time_slots[$i]->start; $ts_start = Carbon::createFromTimeStamp($start); $end = $time_slots[$i]->end; $ts_end = Carbon::createFromTimeStamp($end); $insert[] = array('start' => $ts_start->toDateTimeString(), 'end' => $ts_end->toDateTimeString(), 'weighting' => $time_slots[$i]->weighting, 'user_id' => $user_id, 'occasion_id' => $occasion_id); } //dd($insert); Timeslot::insert($insert); $occasion->pivot->complete = 1; $occasion->pivot->save(); $num_incomplete_occasions = Occasion::find($occasion_id)->users()->wherePivot('complete', 0)->count(); if ($num_incomplete_occasions != 0) { return $occasion; } // The events are done - push $occasion = Occasion::find($occasion_id); $host_start = new Carbon($occasion->start); $host_end = new Carbon($occasion->end); $diff = $host_start->diffInMinutes($host_end); $num_users = $occasion->users->count(); $score = array(); $score = array_fill(0, 10000, 0); //$score[0] = 'test'; //$score = 0; $k = 0; $previous = new Carbon($occasion->start); // implement eager loading for ($i = 0; $i < $diff; $i += 15) { for ($j = 0; $j < $num_users; $j++) { $start = new Carbon($occasion->start); $start->addMinutes($i); $timeslot = Timeslot::where('user_id', '=', $j)->where('start', '<=', $previous->toDateTimeString())->where('end', '>=', $start->toDateTimeString())->first(); if ($timeslot != null) { //dd($timeslot); //$score = array_add($score, $i, $timeslot->weighting); $score[$i] += $timeslot->weighting; //$score[$i] += $timeslot->weighting; //$score[] = array($timeslot->weighting); //$k++; //var_dump($score); } } $previous = $start; } $score = array_filter($score); //dd($score); rsort($score); $top3 = array_reverse(array_slice($score, 0, 3)); $users = Occasion::find($occasion_id)->users()->get(); $data = array('temp'); $users = $users->each(function ($user) use($data) { \Mail::send('emails.invite', $data, function ($message) use($user) { $message->to($user->email, $user->name)->subject('Your event has been scheduled!'); }); \Twilio::message($user->phone, 'An event has finished scheduling! Open up Calendr to learn more.'); }); $app_id = 'jVmr9Q4ItzKs2abze4T2mRvECJ8AxMwCKT5G8anC'; $rest_key = 'hNv7GwawFKdvpyb6B6u8sLqlSQMW3YWWRQeKVll7'; $master_key = 'wzwEOPsb5w45qWQQVJSCqTtL6yvD82Y90SiVDh4y'; ParseClient::initialize($app_id, $rest_key, $master_key); $data = array("alert" => "An event has finished scheduling! Press here to learn more."); ParsePush::send(array("channels" => ["PHPFans"], "data" => $data)); $query = ParseInstallation::query(); $query->equalTo("design", "rad"); ParsePush::send(array("where" => $query, "data" => $data)); // dd($score); }
private function getMinDiff(Carbon $time1, Carbon $time2) { if ($time2->lt($time1)) { // if timeout is less than breakout $time2->addDay(); } // add 1 day return $time2->diffInMinutes($time1); }
public function getProfile($userid) { $user = User::find($userid); if (count($user) >= 1) { $updated = new Carbon($user->updated_at); $now = Carbon::now(); if ($updated->diff($now)->m < 1) { $lastOnline = "Last seen less than a minute ago"; } elseif ($updated->diff($now)->h < 1) { $lastOnline = $updated->diffInMinutes($now) > 1 ? sprintf("Last seen %d minutes ago", $updated->diffInMinutes($now)) : sprintf("Last seen %d minute ago", $updated->diffInMinutes($now)); } elseif ($updated->diff($now)->d < 1) { $lastOnline = $updated->diffInHours($now) > 1 ? sprintf("Last seen %d hours ago", $updated->diffInHours($now)) : sprintf("Last seen %d hour ago", $updated->diffInHours($now)); } elseif ($updated->diff($now)->d < 7) { $lastOnline = $updated->diffInDays($now) > 1 ? sprintf("Last seen %d days ago", $updated->diffInDays($now)) : sprintf("Last seen %d day ago", $updated->diffInDays($now)); } elseif ($updated->diff($now)->m < 1) { $lastOnline = $updated->diffInWeeks($now) > 1 ? sprintf("Last seen %d weeks ago", $updated->diffInWeeks($now)) : sprintf("Last seen %d week ago", $updated->diffInWeeks($now)); } elseif ($updated->diff($now)->y < 1) { $lastOnline = $updated->diffInMonths($now) > 1 ? sprintf("Last seen %d months ago", $updated->diffInMonths($now)) : sprintf("Last seen %d month ago", $updated->diffInMonths($now)); } else { $lastOnline = $updated->diffInYears($now) > 1 ? sprintf("Last seen %d years ago", $updated->diffInYears($now)) : sprintf("Last seen %d year ago", $updated->diffInYears($now)); } return view('dashboard.userProfile', ['user' => $user, 'lastOnline' => $lastOnline]); } else { return view('dashboard.userProfile'); } }