+--------------------------------------------------------------------+
| CiviCRM version 5 |
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2019 |
+ | Copyright CiviCRM LLC (c) 2004-2020 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
/**
*
* @package CRM
- * @copyright CiviCRM LLC (c) 2004-2019
+ * @copyright CiviCRM LLC (c) 2004-2020
*/
/**
}
}
-
/**
* @param null $timeStamp
*
* @return int
* array $results contains years or months
*/
- static public function calculateAge($birthDate) {
+ public static function calculateAge($birthDate) {
$results = [];
$formatedBirthDate = CRM_Utils_Date::customFormat($birthDate, '%Y-%m-%d');
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;
}
return $field;
}
-
/**
* Get the fields required for the 'extra' parameter when adding a datepicker.
*
return $month;
}
-
/**
* Convert a relative date format to an api field.
*
}
}
+ /**
+ * Print out a date object in specified format in local timezone
+ *
+ * @param DateTimeObject $dateObject
+ * @param string $format
+ * @return string
+ */
+ public static function convertDateToLocalTime($dateObject, $format = 'YmdHis') {
+ $systemTimeZone = new DateTimeZone(CRM_Core_Config::singleton()->userSystem->getTimeZoneString());
+ $dateObject->setTimezone($systemTimeZone);
+ return $dateObject->format($format);
+ }
+
}