Skip to content
This repository has been archived by the owner on Dec 11, 2022. It is now read-only.

Commit

Permalink
Fixed a problem with months not being calculated correctly in format_…
Browse files Browse the repository at this point in the history
…date_range.
  • Loading branch information
hperrin committed May 17, 2012
1 parent deb37a1 commit e3c7e2c
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions system/classes/pines.php
Expand Up @@ -602,6 +602,12 @@ public function format_date_range($start_timestamp, $end_timestamp, $format = nu
// Calculate number of months. // Calculate number of months.
$years = (int) $end_date->format('Y') - (int) $start_date->format('Y'); $years = (int) $end_date->format('Y') - (int) $start_date->format('Y');
$months = ($years * 12) + ((int) $end_date->format('n') - (int) $start_date->format('n')); $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) { if (strpos($format, '#month#') !== false && $months == 1) {
$format = preg_replace('/\{?([^{}]*)#month#([^{}]*)\}?/s', '${1}'.$negative.$months.'${2}', $format); $format = preg_replace('/\{?([^{}]*)#month#([^{}]*)\}?/s', '${1}'.$negative.$months.'${2}', $format);
$format = preg_replace('/\{([^{}]*)#months#([^{}]*)\}/s', '', $format); $format = preg_replace('/\{([^{}]*)#months#([^{}]*)\}/s', '', $format);
Expand Down

0 comments on commit e3c7e2c

Please sign in to comment.