+--------------------------------------------------------------------+
| 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
*/
/**
*
*/
public static function getAbbrWeekdayNames() {
- static $days = array();
+ static $days = [];
if (!$days) {
// First day of the week
$firstDay = Civi::settings()->get('weekBegins');
*
*/
public static function getFullWeekdayNames() {
- static $days = array();
+ static $days = [];
if (!$days) {
// First day of the week
$firstDay = Civi::settings()->get('weekBegins');
$config = CRM_Core_Config::singleton();
if ($dateParts) {
- if (array_intersect(array('h', 'H'), $dateParts)) {
+ if (array_intersect(['h', 'H'], $dateParts)) {
$format = $config->dateformatDatetime;
}
- elseif (array_intersect(array('d', 'j'), $dateParts)) {
+ elseif (array_intersect(['d', 'j'], $dateParts)) {
$format = $config->dateformatFull;
}
- elseif (array_intersect(array('m', 'M'), $dateParts)) {
+ elseif (array_intersect(['m', 'M'], $dateParts)) {
$format = $config->dateformatPartial;
}
else {
$type = 'PM';
}
- $date = array(
+ $date = [
'%b' => CRM_Utils_Array::value($month, $abbrMonths),
'%B' => CRM_Utils_Array::value($month, $fullMonths),
'%d' => $day > 9 ? $day : '0' . $day,
'%P' => $type,
'%A' => $type,
'%Y' => $year,
- );
+ ];
return strtr($format, $date);
}
* date/datetime in MySQL format
*/
public static function isoToMysql($iso) {
- $dropArray = array('-' => '', ':' => '', ' ' => '');
+ $dropArray = ['-' => '', ':' => '', ' ' => ''];
return strtr($iso, $dropArray);
}
}
}
-
/**
* @param null $timeStamp
*
$from = self::processDate($from, $fromTime);
$to = self::processDate($to, $toTime);
- return array($from, $to);
+ return [$from, $to];
}
/**
* @return int
* array $results contains years or months
*/
- static public function calculateAge($birthDate) {
- $results = array();
+ public static function calculateAge($birthDate) {
+ $results = [];
$formatedBirthDate = CRM_Utils_Date::customFormat($birthDate, '%Y-%m-%d');
$bDate = explode('-', $formatedBirthDate);
$scheduleDate = explode("-", date("n-j-Y-H-i-s", $date));
- $date = array();
+ $date = [];
$date['M'] = $scheduleDate[0];
$date['d'] = $scheduleDate[1];
$date['Y'] = $scheduleDate[2];
* according to the available parts at the smarty layer.
*/
public static function getDateFieldViewFormat($format) {
- $supportableFormats = array(
+ $supportableFormats = [
'mm/dd' => '%B %E%f',
'dd-mm' => '%E%f %B',
'yy-mm' => '%Y %B',
'M yy' => '%b %Y',
'yy' => '%Y',
'dd/mm/yy' => '%E%f %B %Y',
- );
+ ];
return array_key_exists($format, $supportableFormats) ? $supportableFormats[$format] : self::pickBestSmartyFormat($format);
}
* @return array
*/
public static function datePluginToPHPFormats() {
- $dateInputFormats = array(
+ $dateInputFormats = [
"mm/dd/yy" => 'm/d/Y',
"dd/mm/yy" => 'd/m/Y',
"yy-mm-dd" => 'Y-m-d',
"M yy" => 'M Y',
"M Y" => 'M Y',
"yy" => 'Y',
- );
+ ];
return $dateInputFormats;
}
*/
public static function relativeToAbsolute($relativeTerm, $unit) {
$now = getdate();
- $from = $to = $dateRange = array();
+ $from = $to = $dateRange = [];
$from['H'] = $from['i'] = $from['s'] = 0;
$relativeTermParts = explode('_', $relativeTerm);
$relativeTermPrefix = $relativeTermParts[0];
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 (array(
- '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 array
*/
public static function getDatePickerExtra($field) {
- $extra = array();
+ $extra = [];
if (isset($field['date_format'])) {
$extra['date'] = $field['date_format'];
$extra['time'] = $field['time_format'];
* Array ready to pass to $this->addForm('datepicker' as attributes.
*/
public static function getDatePickerAttributes(&$field) {
- $attributes = array();
- $dateAttributes = array(
+ $attributes = [];
+ $dateAttributes = [
'start_date_years' => 'minYear',
'end_date_years' => 'maxYear',
'date_format' => 'format',
- );
+ ];
foreach ($dateAttributes as $dateAttribute => $mapTo) {
if (isset($field[$dateAttribute])) {
$attributes[$mapTo] = $field[$dateAttribute];
$config = CRM_Core_Config::singleton();
if ($formatType) {
// get actual format
- $params = array('name' => $formatType);
- $values = array();
+ $params = ['name' => $formatType];
+ $values = [];
CRM_Core_DAO::commonRetrieve('CRM_Core_DAO_PreferencesDate', $params, $values);
if ($values['date_format']) {
$time = '0' . $time;
}
- return array($date, $time);
+ return [$date, $time];
}
/**
// 4. If date and time then convert to default date time format.
$dateKey = 'date';
- $dateParams = array($dateKey => $date);
+ $dateParams = [$dateKey => $date];
if (CRM_Utils_Date::convertToDefaultDate($dateParams, $dateType, $dateKey)) {
$dateVal = $dateParams[$dateKey];
$ruleName = 'date';
if ($dateType == 1) {
- $matches = array();
+ $matches = [];
if (preg_match("/(\s(([01]\d)|[2][0-3]):([0-5]\d))$/", $date, $matches)) {
$ruleName = 'dateTime';
if (strpos($date, '-') !== FALSE) {
* @return array
*/
public static function getCalendarDayOfMonth() {
- $month = array();
+ $month = [];
for ($i = 1; $i <= 31; $i++) {
$month[$i] = $i;
if ($i == 31) {
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);
+ }
+
}