. */ declare(strict_types=1); namespace FireflyIII\Helpers\Collector\Extensions; use Carbon\Carbon; use FireflyIII\Helpers\Collector\GroupCollectorInterface; /** * Trait TimeCollection */ trait TimeCollection { /** * Collect transactions after a specific date. * * @param Carbon $date * * @return GroupCollectorInterface */ public function setAfter(Carbon $date): GroupCollectorInterface { $afterStr = $date->format('Y-m-d 00:00:00'); $this->query->where('transaction_journals.date', '>=', $afterStr); return $this; } /** * Collect transactions before a specific date. * * @param Carbon $date * * @return GroupCollectorInterface */ public function setBefore(Carbon $date): GroupCollectorInterface { $beforeStr = $date->format('Y-m-d 00:00:00'); $this->query->where('transaction_journals.date', '<=', $beforeStr); return $this; } /** * Collect transactions created on a specific date. * * @param Carbon $date * * @return GroupCollectorInterface */ public function setCreatedAt(Carbon $date): GroupCollectorInterface { $after = $date->format('Y-m-d 00:00:00'); $before = $date->format('Y-m-d 23:59:59'); $this->query->where('transaction_journals.created_at', '>=', $after); $this->query->where('transaction_journals.created_at', '<=', $before); return $this; } /** * Set the start and end time of the results to return. * * @param Carbon $start * @param Carbon $end * * @return GroupCollectorInterface */ public function setRange(Carbon $start, Carbon $end): GroupCollectorInterface { if ($end < $start) { [$start, $end] = [$end, $start]; } // always got to end of day / start of day for ranges. $startStr = $start->format('Y-m-d 00:00:00'); $endStr = $end->format('Y-m-d 23:59:59'); $this->query->where('transaction_journals.date', '>=', $startStr); $this->query->where('transaction_journals.date', '<=', $endStr); return $this; } /** * Collect transactions updated on a specific date. * * @param Carbon $date * * @return GroupCollectorInterface */ public function setUpdatedAt(Carbon $date): GroupCollectorInterface { $after = $date->format('Y-m-d 00:00:00'); $before = $date->format('Y-m-d 23:59:59'); $this->query->where('transaction_journals.updated_at', '>=', $after); $this->query->where('transaction_journals.updated_at', '<=', $before); return $this; } }