/** * @throws \Exception * * @return array Mutates the filter values so that it is readily prepared for processing. */ public function getMutatedValues() { $operator = head($this->values); $dates = explode(' - ', last($this->values)); switch ($operator) { case 'before': $values = [DateRange::before(Carbon::createFromFormat(Filterable::$date_format, head($dates), 'GB')->startOfDay())]; break; case 'not_in': $values = [new DateRange(Carbon::createFromFormat(Filterable::$date_format, last($dates), 'GB')->addDay()->startOfDay(), Carbon::createFromFormat(Filterable::$date_format, head($dates), 'GB')->subDay()->endOfDay())]; break; case 'after': $values = [DateRange::after(Carbon::createFromFormat(Filterable::$date_format, last($dates), 'GB')->endOfDay())]; break; case 'in': default: $values = [new DateRange(Carbon::createFromFormat(Filterable::$date_format, head($dates), 'GB')->subDay()->endOfDay(), Carbon::createFromFormat(Filterable::$date_format, last($dates), 'GB')->addDay()->startOfDay())]; } return $values; }
public function test_before_date_is_initialised_without_before_date() { $range = new DateRange(Carbon::today()->subSecond(), $expected = null); $this->assertEquals($expected, $range->getBefore()); }
public function test_yesterday() { $range = new DateRange(Carbon::yesterday()->subSecond(), Carbon::yesterday()->endOfDay()->addSecond()); $expected_result = 'Yesterday'; $this->assertEquals($expected_result, $range->forHumans()); }
/** * @inherit */ public function getOptions() { return ['operator' => ['In' => 'in', 'Not In' => 'not_in', 'After' => 'after', 'Before' => 'before'], 'date_range' => ['Current Day' => DateRange::today()->toInclusiveString(Filterable::$date_format, ' - '), 'Previous Day' => DateRange::yesterday()->toInclusiveString(Filterable::$date_format, ' - '), 'Current Week' => DateRange::thisWeek()->toInclusiveString(Filterable::$date_format, ' - '), 'Last Week' => DateRange::lastWeek()->toInclusiveString(Filterable::$date_format, ' - '), 'Current Month' => DateRange::thisMonth()->toInclusiveString(Filterable::$date_format, ' - '), 'Previous Month' => DateRange::lastMonth()->toInclusiveString(Filterable::$date_format, ' - '), 'Current Year' => DateRange::thisYear()->toInclusiveString(Filterable::$date_format, ' - '), 'Previous Year' => DateRange::lastYear()->toInclusiveString(Filterable::$date_format, ' - ')]]; }
public function test_getTo_returns_a_new_carbon_instance_with_correct_value() { $range = new DateRange(Carbon::today()->subSecond(), $before = Carbon::today()->endOfDay()->addSecond()); $this->assertEquals(Carbon::today()->endOfDay(), $range->getTo()); $this->assertTrue($before !== $range->getTo()); }