d', $baseTimestamp ); $this->setDateRange( $startDate, $endDate ); } /** * Updates the date range. * * @since 4.3.0 * * @param string $startDate The start date. * @param string $endDate The end date. * @return void */ public function setDateRange( $startDate, $endDate ) { $this->startDate = $startDate; $this->endDate = $endDate; // Timestamp. $this->startTimestamp = strtotime( $startDate ); $this->endTimestamp = strtotime( $endDate ); // Compare date. $this->days = ceil( abs( $this->endTimestamp - $this->startTimestamp ) / DAY_IN_SECONDS ) + 1; $compareEndDate = $this->startTimestamp - DAY_IN_SECONDS; $compareStartDate = $compareEndDate - ( $this->days * DAY_IN_SECONDS ); $this->compareStartDate = date( 'Y-m-d', $compareStartDate ); $this->compareEndDate = date( 'Y-m-d', $compareEndDate ); } /** * Returns the current date range. * * @since 4.3.0 * * @return array The current date range. */ public function getDateRange() { return [ 'start' => $this->startDate, 'end' => $this->endDate, 'compareStart' => $this->compareStartDate, 'compareEnd' => $this->compareEndDate ]; } }