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;
 }
 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());
 }
 public function testSecondsSetter()
 {
     $d = CarbonInterval::create(4, 5, 6, 5, 8, 9, 10);
     $d->seconds = 34;
     $this->assertSame(34, $d->seconds);
 }
 public function testAllWithCreate()
 {
     $ci = CarbonInterval::create(5, 6, 2, 5, 9, 10, 11);
     $this->assertInstanceOfCarbonInterval($ci);
     $this->assertCarbonInterval($ci, 5, 6, 19, 9, 10, 11);
 }
 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);
 }
 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]);
 }
 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());
 }
 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());
 }