Skip to content

Commit ef37192

Browse files
committed
#34 Fix number of days or months between dates
1 parent fcd9de2 commit ef37192

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

functions/admin-page.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,20 @@ function codeable_transcactions_stats_cb() {
173173

174174
}
175175

176-
$chart_revenue_avg = array_fill(0, count($chart_revenue), round(array_sum($chart_revenue) / count($chart_revenue), 2));
177-
$chart_tasks_count_avg = array_fill(0, count($chart_tasks_count), round(array_sum($chart_tasks_count) / count($chart_tasks_count), 2));
176+
$fromDT = new DateTime($from_year.'-'.$from_month.'-'.$from_day);
177+
$toDT = new DateTime($to_year.'-'.$to_month.'-'.$to_day);
178+
179+
$datediff = date_diff($fromDT, $toDT);
180+
181+
if ($chart_display_method == 'months') {
182+
$datediffcount = $datediff->format('%m') + ($datediff->format('%y') * 12) + 1;
183+
}
184+
if ($chart_display_method == 'days') {
185+
$datediffcount = $datediff->format('%a');
186+
}
187+
188+
$chart_revenue_avg = array_fill(0, count($chart_revenue), round(array_sum($chart_revenue) / $datediffcount, 2));
189+
$chart_tasks_count_avg = array_fill(0, count($chart_tasks_count), round(array_sum($chart_tasks_count) / $datediffcount, 2));
178190

179191
?>
180192

0 commit comments

Comments
 (0)