$from, 'to' => $to, ); } /** * Resolves the comparison period as the same duration immediately before the current period. * * @param array $current Period array with from and to date strings. * @return array { from: string, to: string } */ protected static function resolve_compare_period( array $current ): array { if ( ! $current['from'] || ! $current['to'] ) { return array( 'from' => '', 'to' => '', ); } $duration = (int) round( ( strtotime( $current['to'] ) - strtotime( $current['from'] ) ) / DAY_IN_SECONDS ); $compare_to = gmdate( 'Y-m-d', strtotime( $current['from'] ) - DAY_IN_SECONDS ); $compare_from = gmdate( 'Y-m-d', strtotime( $compare_to ) - $duration * DAY_IN_SECONDS ); return array( 'from' => $compare_from, 'to' => $compare_to, ); } }