<?php
/*
- +--------------------------------------------------------------------+
- | CiviCRM version 5 |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2019 |
- +--------------------------------------------------------------------+
- | This file is a part of CiviCRM. |
- | |
- | CiviCRM is free software; you can copy, modify, and distribute it |
- | under the terms of the GNU Affero General Public License |
- | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
- | |
- | CiviCRM is distributed in the hope that it will be useful, but |
- | WITHOUT ANY WARRANTY; without even the implied warranty of |
- | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
- | See the GNU Affero General Public License for more details. |
- | |
- | You should have received a copy of the GNU Affero General Public |
- | License and the CiviCRM Licensing Exception along |
- | with this program; if not, contact CiviCRM LLC |
- | at info[AT]civicrm[DOT]org. If you have questions about the |
- | GNU Affero General Public License or the licensing of CiviCRM, |
- | see the CiviCRM license FAQ at http://civicrm.org/licensing |
- +--------------------------------------------------------------------+
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC. All rights reserved. |
+ | |
+ | This work is published under the GNU AGPLv3 license with some |
+ | permitted exceptions and without any warranty. For full license |
+ | and copyright information, see https://civicrm.org/licensing |
+ +--------------------------------------------------------------------+
*/
/**
*
* @package CRM
- * @copyright CiviCRM LLC (c) 2004-2019
+ * @copyright CiviCRM LLC https://civicrm.org/licensing
*/
/**
switch ($unit) {
case 'year':
switch ($relativeTerm) {
- case 'this':
- $from['d'] = $from['M'] = 1;
- $to['d'] = 31;
- $to['M'] = 12;
- $to['Y'] = $from['Y'] = $now['year'];
- break;
-
case 'previous':
$from['M'] = $from['d'] = 1;
$to['d'] = 31;
break;
default:
- if ($relativeTermPrefix === 'ending') {
- $to['d'] = $now['mday'];
- $to['M'] = $now['mon'];
- $to['Y'] = $now['year'];
- $to['H'] = 23;
- $to['i'] = $to['s'] = 59;
- $from = self::intervalAdd('year', -$relativeTermSuffix, $to);
- $from = self::intervalAdd('second', 1, $from);
+ switch ($relativeTermPrefix) {
+
+ case 'ending':
+ $to['d'] = $now['mday'];
+ $to['M'] = $now['mon'];
+ $to['Y'] = $now['year'];
+ $to['H'] = 23;
+ $to['i'] = $to['s'] = 59;
+ $from = self::intervalAdd('year', -$relativeTermSuffix, $to);
+ $from = self::intervalAdd('second', 1, $from);
+ break;
+
+ case 'this':
+ $from['d'] = $from['M'] = 1;
+ $to['d'] = 31;
+ $to['M'] = 12;
+ $to['Y'] = $from['Y'] = $now['year'];
+ if (is_numeric($relativeTermSuffix)) {
+ $from['Y'] -= ($relativeTermSuffix - 1);
+ }
+ break;
}
+ break;
}
break;
$from['Y'] = $fYear;
$fiscalYear = mktime(0, 0, 0, $from['M'], $from['d'] - 1, $from['Y'] + 1);
$fiscalEnd = explode('-', date("Y-m-d", $fiscalYear));
-
$to['d'] = $fiscalEnd['2'];
$to['M'] = $fiscalEnd['1'];
$to['Y'] = $fiscalEnd['0'];
+ $to['H'] = 23;
+ $to['i'] = $to['s'] = 59;
+ if (is_numeric($relativeTermSuffix)) {
+ $from = self::intervalAdd('year', (-$relativeTermSuffix), $to);
+ $from = self::intervalAdd('second', 1, $from);
+ }
break;
case 'previous':
$to['d'] = $fiscalEnd['2'];
$to['M'] = $fiscalEnd['1'];
$to['Y'] = $fiscalEnd['0'];
+ $to['H'] = 23;
+ $to['i'] = $to['s'] = 59;
}
else {
$from['Y'] = $fYear - $relativeTermSuffix;
$to['d'] = $fiscalEnd['2'];
$to['M'] = $fiscalEnd['1'];
$to['Y'] = $fYear;
+ $to['H'] = 23;
+ $to['i'] = $to['s'] = 59;
}
break;
break;
}
- foreach ([
- 'from',
- 'to',
- ] as $item) {
- if (!empty($$item)) {
- $dateRange[$item] = self::format($$item);
- }
- else {
- $dateRange[$item] = NULL;
- }
- }
+ $dateRange['from'] = empty($from) ? NULL : self::format($from);
+ $dateRange['to'] = empty($to) ? NULL : self::format($to);
return $dateRange;
}