+--------------------------------------------------------------------+
| CiviCRM version 5 |
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2018 |
+ | Copyright CiviCRM LLC (c) 2004-2019 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
/**
*
* @package CRM
- * @copyright CiviCRM LLC (c) 2004-2018
+ * @copyright CiviCRM LLC (c) 2004-2019
*/
/**
*
*/
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
*
$now = self::isoToMysql($now);
}
- return ($mysqlDate >= $now) ? FALSE : TRUE;
+ return (strtotime($mysqlDate) >= strtotime($now)) ? FALSE : TRUE;
}
/**
$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];
break;
}
- foreach (array(
- 'from',
- 'to',
- ) as $item) {
+ foreach ([
+ 'from',
+ 'to',
+ ] as $item) {
if (!empty($$item)) {
$dateRange[$item] = self::format($$item);
}
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.
+ *
+ * @param array $params
+ * @param string $dateField
+ * @param bool $isDatePicker
+ * Non datepicker fields are deprecated. Exterminate Exterminate.
+ * (but for now handle them).
+ */
+ public static function convertFormDateToApiFormat(&$params, $dateField, $isDatePicker = TRUE) {
+ if (!empty($params[$dateField . '_relative'])) {
+ $dates = CRM_Utils_Date::getFromTo($params[$dateField . '_relative'], NULL, NULL);
+ unset($params[$dateField . '_relative']);
+ }
+ if (!empty($params[$dateField . '_low'])) {
+ $dates[0] = $isDatePicker ? $params[$dateField . '_low'] : date('Y-m-d H:i:s', strtotime($params[$dateField . '_low']));
+ unset($params[$dateField . '_low']);
+ }
+ if (!empty($params[$dateField . '_high'])) {
+ $dates[1] = $isDatePicker ? $params[$dateField . '_high'] : date('Y-m-d 23:59:59', strtotime($params[$dateField . '_high']));
+ unset($params[$dateField . '_high']);
+ }
+ if (empty($dates)) {
+ return;
+ }
+ if (empty($dates[0])) {
+ $params[$dateField] = ['<=' => $dates[1]];
+ }
+ elseif (empty($dates[1])) {
+ $params[$dateField] = ['>=' => $dates[0]];
+ }
+ else {
+ $params[$dateField] = ['BETWEEN' => $dates];
+ }
+ }
+
}