From 742a98ea737d6507aa61a7eaa121992b3e35e689 Mon Sep 17 00:00:00 2001 From: Brian Coords Date: Fri, 10 Jan 2025 14:57:13 -0800 Subject: [PATCH] Fix monthly stats when months from a previous year are shown. --- php/classes/class-all-episode-stats.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/php/classes/class-all-episode-stats.php b/php/classes/class-all-episode-stats.php index 6bffcf9..7343b01 100644 --- a/php/classes/class-all-episode-stats.php +++ b/php/classes/class-all-episode-stats.php @@ -187,12 +187,18 @@ private function fetch_all_episodes_stats(){ return $all_episodes_stats; } - $start_month_template = sprintf( '%s-%%s-01 00:00:00', date( 'Y' ) ); - $end_month_template = sprintf( '%s-%%s-%s 23:59:59', date( 'Y' ), date( 't' ) ); - $last_months_stats = array(); foreach ( $this->dates as $month_number => $month_name ) { + + $year = date( 'Y' ); + if ( 12 === $month_number ) { + $year = date( 'Y', strtotime( current_time( 'Y-m-d' ) . 'FIRST DAY OF -1 YEAR' ) ); + } + + $start_month_template = sprintf( '%s-%%s-01 00:00:00', $year ); + $end_month_template = sprintf( '%s-%%s-%s 23:59:59', $year, date( 't' ) ); + $month_formatted = sprintf( "%02d", $month_number ); $month_start = strtotime( sprintf( $start_month_template, $month_formatted ) ); $month_end = strtotime( sprintf( $end_month_template, $month_formatted ) );