public function isNotificationNeeded()
 {
     // If the next mission has a precise launch specificity (allowing us to accurately calculate times)
     if ($this->nextMission->launchSpecificity == LaunchSpecificity::Precise) {
         // Get the current difference in seconds between now (and the last time this method was called, which is always 1 minute
         // earlier because the MissionCountdownNotificationCommand is a 1 minute repeating cronjob)), and the scheduled launch
         // datetime.
         $nowDiffInSeconds = $this->nextMission->launchDateTime->diffInSeconds($this->now);
         $lastRunDiffInSeconds = $this->nextMission->launchDateTime->diffInSeconds($this->lastRun);
         // is it less than 1 day to launch now, and it was greater before?
         if ($nowDiffInSeconds < 86400 && $lastRunDiffInSeconds >= 86400) {
             $this->timeRemaining = CarbonInterval::hours(24);
             return true;
             // it is less than 3 hours to launch now, and it was greater before?
         } elseif ($nowDiffInSeconds < 10800 && $lastRunDiffInSeconds >= 10800) {
             $this->timeRemaining = CarbonInterval::hours(3);
             return true;
             // is it less than 1 hour to launch now, and it was greater before?
         } elseif ($nowDiffInSeconds < 3600 && $lastRunDiffInSeconds >= 3600) {
             $this->timeRemaining = CarbonInterval::hours(1);
             return true;
         }
     }
     return false;
 }
Пример #2
0
 /**
  * @covers ::convert
  */
 public function testConvert()
 {
     $test1 = Converter::convert(Calends::create(0, 'unix'));
     $this->assertEquals(['start' => Carbon::createFromTimestamp(0), 'duration' => \Carbon\CarbonInterval::seconds(0), 'end' => Carbon::createFromTimestamp(0)], $test1);
     $test2 = Converter::convert(Calends::create(['start' => 0, 'end' => 86400], 'unix'));
     $this->assertEquals(['start' => Carbon::createFromTimestamp(0), 'duration' => \Carbon\CarbonInterval::seconds(86400), 'end' => Carbon::createFromTimestamp(86400)], $test2);
 }
Пример #3
0
 public function testFluentSettersWeeksAndDaysIsCumulative()
 {
     $ci = CarbonInterval::year(5)->weeksAndDays(2, 6);
     $this->assertCarbonInterval($ci, 5, 0, 20, 0, 0, 0);
     $this->assertSame(20, $ci->dayz);
     $this->assertSame(2, $ci->weeks);
     $this->assertSame(6, $ci->dayzExcludeWeeks);
 }
Пример #4
0
 public function carbonInterval()
 {
     $tempTime = $this->time;
     $hours = (int) ($tempTime / self::$secondsPerHour);
     $tempTime -= $hours * self::$secondsPerHour;
     $minutes = (int) ($tempTime / self::$secondsPerMinute);
     $tempTime -= $minutes * self::$secondsPerMinute;
     $seconds = $tempTime;
     return \Carbon\CarbonInterval::hours($hours)->minutes($minutes)->seconds($seconds);
 }
Пример #5
0
 public function orders()
 {
     $orders = file_get_contents('http://api.komandir.kz/libs/port.php?city=' . $this->city->index);
     $orders = json_decode($orders);
     foreach ($orders as $k => $v) {
         CarbonInterval::setLocale('ru');
         $dt1 = Carbon::parse($v->SOURCE_TIME);
         $dt2 = Carbon::now()->subMinutes(5);
         $difference = $dt1->diffInMinutes($dt2, true);
         $hours = intval($difference / 60);
         $minutes = $difference % 60;
         $last_changed = DB::table('users_logs')->where('city', '=', $this->city->index)->where('order_id', '=', $v->ID)->orderBy('date', 'desc')->select('user_name')->first();
         $orders[$k]->LAST_CHANGED = isset($last_changed->user_name) ? $last_changed->user_name : NULL;
         $orders[$k]->DIFFERENCE = $hours == 0 && $minutes == 0 ? 'Подано' : CarbonInterval::hours($hours)->minutes($minutes);
         //$orders[$k]->DIFFERENCE = $dt1->diffInMinutes($dt2, true);
     }
     $crews = DB::connection($this->city->db)->table('crews_inline')->where('status', '=', 'waiting')->where('code', '<>', '0')->orderBy('code')->get(['code']);
     return view('personal.airport', ['res' => $orders, 'crews' => $crews, 'city' => $this->city->index]);
 }
 public function __invoke(array $parameters) : array
 {
     $fromDate = $parameters['fromDate'];
     $toDate = $parameters['toDate'];
     $interval = $parameters['interval'] ?? CarbonInterval::create(0, 0, 0, 1);
     $windowSize = $parameters['windowSize'] ?? $interval;
     $fromDate->sub($windowSize);
     $fromStep = clone $fromDate;
     $toStep = clone $fromDate;
     $toStep->add($windowSize);
     $data = ['prepared' => [], 'ongoing' => [], 'completed' => [], 'done' => []];
     for (;;) {
         if ($toStep->gte($toDate)) {
             break;
         }
         $data['prepared'][$toStep->format('Y-m-d')] = ['data' => $this->data($fromStep, $toStep)];
         $fromStep->add($interval);
         $toStep->add($interval);
     }
     return $data;
 }
 /**
  * @expectedException InvalidArgumentException
  */
 public function testInstanceWithDaysThrowsException()
 {
     $ci = CarbonInterval::instance(Carbon::now()->diff(Carbon::now()->addWeeks(3)));
 }
 public function testYearsAndMonthInCatalan()
 {
     CarbonInterval::setLocale('ca');
     $this->assertSame('1 any 1 mes', CarbonInterval::create(1, 1)->forHumans());
     $this->assertSame('2 anys 1 mes', CarbonInterval::create(2, 1)->forHumans());
 }
Пример #9
0
 public function testDiffFilteredNegativeWithSignWithSecondObject()
 {
     $dt1 = Carbon::createFromDate(2001, 1, 31);
     $dt2 = Carbon::createFromDate(1999, 1, 1);
     $this->assertSame(-12, $dt1->diffFiltered(CarbonInterval::month(), function (Carbon $date) {
         return $date->year === 2000;
     }, $dt2, false));
 }
Пример #10
0
 public function subscriptionExtendedBy($pretty = false)
 {
     $secondsExtended = (new DeltaVCalculator())->toSeconds($this->totalDeltaV());
     return $pretty ? CarbonInterval::seconds($secondsExtended) : $secondsExtended;
 }
Пример #11
0
 public function testAddWithNegativeDiffDateInterval()
 {
     $diff = Carbon::now()->diff(Carbon::now()->subWeeks(3));
     $ci = CarbonInterval::create(4, 3, 6, 7, 8, 10, 11)->add($diff);
     $this->assertCarbonInterval($ci, 4, 3, 28, 8, 10, 11);
 }
Пример #12
0
 /**
  * Register Twig tags
  * @return array
  */
 public function registerMarkupTags()
 {
     return ['filters' => ['duration' => function ($datetime) {
         $interval = preg_split('/\\:|\\:0/', $datetime);
         $diff = new \DateInterval('PT' . $interval[0] . 'H' . $interval[1] . 'M');
         \Carbon\CarbonInterval::setLocale('ru');
         return \Carbon\CarbonInterval::instance($diff);
     }, 'dateLocale' => [$this, 'dateLocale'], 'unique' => function ($array) {
         if (!$array) {
             return $array;
         }
         return $ret = array_unique($array, SORT_REGULAR);
     }, 'pluck' => function ($collection, ...$items) {
         if (!$collection) {
             return;
         }
         $ret = [];
         foreach ($collection as $key => $object) {
             $_ret = [];
             foreach ($items as $key) {
                 if (array_key_exists($key, $object)) {
                     $_ret[$key] = $object[$key];
                 } else {
                     return;
                 }
             }
             $ret[] = $_ret;
         }
         return $ret;
     }, 'emt' => function ($string) {
         return EMTypograph::fast_apply($string, ['Nobr.nowrap' => 'on', 'Nobr.hyphen_nowrap' => 'on', 'OptAlign.all' => 'off', 'Text.paragraphs' => 'off', 'Text.breakline' => 'off']);
     }, 'emts' => function ($string) {
         return EMTypograph::fast_apply($string, ['Nobr.nowrap' => 'on', 'Nobr.hyphen_nowrap' => 'on', 'OptAlign.all' => 'off', 'Text.paragraphs' => 'off', 'Text.breakline' => 'off']);
     }], 'functions' => ['dateLocaleIntervalOld' => function ($date_start, $date_end) {
         $s = \Carbon\Carbon::parse($date_start);
         $e = \Carbon\Carbon::parse($date_end);
         $c = $e->month > $s->month;
         // \Carbon\Carbon::setLocale('ru');
         if ($c) {
             return sprintf("c %s %s по %s %s", $s->day, $this->dateLocale($s, "%h"), $e->day, $this->dateLocale($e, "%h"));
         } else {
             return sprintf("c %s по %s %s", $s->day, $e->day, $this->dateLocale($e, "%h"));
         }
     }, 'dateLocaleInterval' => function ($date_start, $date_end) {
         $s = \Carbon\Carbon::parse($date_start);
         $sm = \Carbon\Carbon::parse($date_start)->startOfMonth()->day;
         $e = \Carbon\Carbon::parse($date_end);
         $em = \Carbon\Carbon::parse($date_end)->endOfMonth()->day;
         $isDifferentMonth = $e->month > $s->month;
         $isDifferentYear = $e->year > $s->year;
         $isFullMonth = $s->month == $e->month && $s->day == $sm && $e->day == $em;
         // \Carbon\Carbon::setLocale('ru');
         if ($isDifferentYear) {
             return sprintf("c %s %s %s по %s %s %s", $s->day, $this->dateLocale($s, "%h"), $s->year, $e->day, $this->dateLocale($e, "%h"), $s->year);
         }
         if ($isDifferentMonth) {
             return sprintf("c %s %s по %s %s", $s->day, $this->dateLocale($s, "%h"), $e->day, $this->dateLocale($e, "%h"));
         }
         if ($isFullMonth) {
             return sprintf("в %s %s", $this->dateLocale($s, "%X"), $s->year);
         }
         return sprintf("c %s по %s %s", $s->day, $e->day, $this->dateLocale($e, "%h"));
     }]];
 }
Пример #13
0
 public function testYearsAndMonthInGerman()
 {
     CarbonInterval::setLocale('de');
     $this->assertSame('1 Jahr 1 Monat', CarbonInterval::create(1, 1)->forHumans());
     $this->assertSame('2 Jahre 1 Monat', CarbonInterval::create(2, 1)->forHumans());
 }
Пример #14
0
 /**
  * {@inheritdoc}
  */
 public static function convert(Calends $cal)
 {
     return ['start' => Source::createFromTimestamp($cal->getDate('unix')), 'duration' => CarbonInterval::seconds($cal->getDuration(0)), 'end' => Source::createFromTimestamp($cal->getEndDate('unix'))];
 }
Пример #15
0
 /**
  * Responds to POST::/workouts/create requests
  *
  * @param WorkoutRequest $request The request containing the new workout data
  */
 public function store(WorkoutRequest $request)
 {
     $workout = Workout::create(['user_id' => \Auth::id()]);
     // very similar to update's logic except there is no checking for existing
     // entities.
     $valid = true;
     $invalidProperty = null;
     $exercise_groups = array_values($request->get('exercise_groups'));
     for ($i = 0; $i < count($exercise_groups); $i++) {
         $group_num = $i + 1;
         $group = $exercise_groups[$i];
         if (!$valid) {
             $invalidProperty = 'exercise_groups';
             break;
         }
         $exercise_group = ExerciseGroup::create(['workout_id' => $workout->id, 'exercise_id' => $group['exercise_id'], 'group_order' => $group_num]);
         $exercise = $exercise_group->exercise;
         $exercise_measurements = array_values($group['exercise_measurements']);
         for ($j = 0; $j < count($exercise_measurements); $j++) {
             $measurement_num = $j + 1;
             $measurement = $exercise_measurements[$j];
             $weight = null;
             $weight_unit_id = null;
             $distance = null;
             $distance_unit_id = null;
             $reps = null;
             $time = null;
             if ($exercise->exercise_type & Exercise::$exerciseTypeWeighted) {
                 if (!isset($measurement['weight'])) {
                     $valid = false;
                     $invalidProperty = 'weight';
                     break;
                 }
                 $weight = $measurement['weight'];
                 $weight_unit_id = $measurement['weight_unit_id'];
             } else {
                 if ($exercise->exercise_type & Exercise::$exerciseTypeDistance) {
                     if (!isset($measurement['distance'])) {
                         $valid = false;
                         $invalidProperty = 'distance';
                         break;
                     }
                     $distance = $measurement['distance'];
                     $distance_unit_id = $measurement['distance_unit_id'];
                 }
             }
             if ($exercise->exercise_type & Exercise::$exerciseTypeRepetition) {
                 if (!isset($measurement['reps'])) {
                     $valid = false;
                     $invalidProperty = 'reps';
                     break;
                 }
                 $reps = $measurement['reps'];
             } else {
                 if ($exercise->exercise_type & Exercise::$exerciseTypeTime) {
                     if (!isset($measurement['time'])) {
                         $valid = false;
                         $invalidProperty = 'time';
                         break;
                     }
                     // convert time to seconds
                     $time = $measurement['time'];
                     $interval = \Carbon\CarbonInterval::hours($time['hours'])->minutes($time['minutes'])->seconds($time['seconds']);
                     $time = ExerciseMeasurement::toSeconds($interval);
                 }
             }
             ExerciseMeasurement::create(['exercise_group_id' => $exercise_group->id, 'set_order' => $measurement_num, 'weight' => $weight, 'weight_unit_id' => $weight_unit_id, 'distance' => $distance, 'distance_unit_id' => $distance_unit_id, 'reps' => $reps, 'time' => $time]);
         }
     }
     if (!$valid) {
         $workout->delete();
         \Session::flash('workout', 'There was an error creating your workout');
         \Session::flash('property', $invalidProperty);
     }
     return redirect('/workouts');
 }
Пример #16
0
 public function testSecondsGetter()
 {
     $d = CarbonInterval::create(4, 5, 6, 5, 8, 9, 10);
     $this->assertSame(10, $d->seconds);
 }
Пример #17
0
 /**
  * Register Twig tags
  * @return array
  */
 public function registerMarkupTags()
 {
     return ['filters' => ['duration' => function ($datetime) {
         $interval = preg_split('/\\:|\\:0/', $datetime);
         $diff = new \DateInterval('PT' . $interval[0] . 'H' . $interval[1] . 'M');
         \Carbon\CarbonInterval::setLocale('ru');
         return \Carbon\CarbonInterval::instance($diff);
     }, 'dateLocale' => [$this, 'dateLocale']]];
 }
Пример #18
0
 /**
  * get DateInterval.
  *
  * @param $minutes
  *
  * @return CarbonInterval
  */
 protected function getDateInterval($minutes)
 {
     return CarbonInterval::minutes($minutes);
 }
Пример #19
0
 public function returningForAction(DateTime $fromDate, DateTime $toDate = null, DateInterval $interval = null, DateInterval $windowSize = null) : array
 {
     $fromDate = clone $fromDate;
     if ($toDate) {
         $toDate = clone $toDate;
     } else {
         $toDate = Carbon::now();
     }
     if (!$interval) {
         $interval = CarbonInterval::create(0, 1);
     }
     /**
      * Rturn empty array for impossible query
      */
     if ($fromDate->gt($toDate)) {
         return [];
     }
     return (new Pipeline())->pipe(new ReturningForAction($this, $this->log))->pipe(function (array $parameters) : array {
         $preparedChunks = array_chunk($parameters['prepared'], 100, true);
         $result = ['prepared' => [], 'ongoing' => $parameters['ongoing'], 'completed' => $parameters['completed'], 'done' => $parameters['done']];
         foreach ($preparedChunks as $prepared) {
             $result = array_merge_recursive($result, (new Pipeline())->pipe(new BeginCount($this, $this->log))->pipe(new Wait($this, $this->log))->pipe(new CompleteCount($this, $this->log))->process(['prepared' => $prepared, 'completed' => [], 'done' => [], 'ongoing' => []]));
         }
         return $result;
     })->pipe(new ToSortedAssociative(function (string $key1, string $key2) : int {
         $date1 = Carbon::createFromFormat('Y-m-d', $key1);
         $date2 = Carbon::createFromFormat('Y-m-d', $key2);
         return $date2->diffInSeconds($date1, false);
     }))->process(['fromDate' => $fromDate, 'toDate' => $toDate, 'interval' => $interval, 'windowSize' => $windowSize]);
 }
Пример #20
0
 public function __construct($years = 1, $months = null, $weeks = null, $days = null, $hours = null, $minutes = null, $seconds = null)
 {
     parent::__construct($years, $months, $weeks, $days, $hours, $minutes, $seconds);
 }
Пример #21
0
 /**
  * Get the difference in hours using a filter closure
  *
  * @param Closure $callback
  * @param Carbon $dt
  * @param boolean $abs Get the absolute of the difference
  *
  * @return int
  */
 public function diffInHoursFiltered(Closure $callback, Carbon $dt = null, $abs = true)
 {
     return $this->diffFiltered(CarbonInterval::hour(), $callback, $dt, $abs);
 }
 public function testYearsAndMonthsInDanish()
 {
     CarbonInterval::setLocale('da');
     $this->assertSame('1 år 1 måned', CarbonInterval::create(1, 1)->forHumans());
     $this->assertSame('2 år 1 måned', CarbonInterval::create(2, 1)->forHumans());
 }