Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed a problem with months not being calculated correctly in format_…

…date_range.
  • Loading branch information...
commit e3c7e2c4bdf0a06708407f176c48a2a9c844dbd7 1 parent deb37a1
@hperrin hperrin authored
Showing with 6 additions and 0 deletions.
  1. +6 −0 system/classes/pines.php
View
6 system/classes/pines.php
@@ -602,6 +602,12 @@ public function format_date_range($start_timestamp, $end_timestamp, $format = nu
// Calculate number of months.
$years = (int) $end_date->format('Y') - (int) $start_date->format('Y');
$months = ($years * 12) + ((int) $end_date->format('n') - (int) $start_date->format('n'));
+ // Be sure we didn't go too far.
+ $test_date = clone $start_date;
+ $test_date->modify('+'.$months.' months');
+ $test_timestamp = (int) $test_date->format('U');
+ if ($test_timestamp > $end_timestamp)
+ $months--;
if (strpos($format, '#month#') !== false && $months == 1) {
$format = preg_replace('/\{?([^{}]*)#month#([^{}]*)\}?/s', '${1}'.$negative.$months.'${2}', $format);
$format = preg_replace('/\{([^{}]*)#months#([^{}]*)\}/s', '', $format);
Please sign in to comment.
Something went wrong with that request. Please try again.