From 1285ac452adbb06684be8fbd3ade8745a63db41a Mon Sep 17 00:00:00 2001 From: eileen Date: Thu, 16 Feb 2017 16:07:35 +1300 Subject: [PATCH] [NFC] towards CRM-19840 & other date fixes. Enhance the information available about dates. Based on the date format a format string in php and in 'our posix' should be returned. (as long as we set the context to 'input' our of cautiousness. min & max year should be calculated for all types, not just credit cards --- CRM/Core/SelectValues.php | 32 +++++++++++++++++++++----------- CRM/Price/Form/Field.php | 7 ------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/CRM/Core/SelectValues.php b/CRM/Core/SelectValues.php index ba24f9d6a8..344219ef5a 100644 --- a/CRM/Core/SelectValues.php +++ b/CRM/Core/SelectValues.php @@ -311,7 +311,8 @@ class CRM_Core_SelectValues { * @return array * the date array */ - public static function date($type = NULL, $format = NULL, $minOffset = NULL, $maxOffset = NULL) { + public static function date($type = NULL, $format = NULL, $minOffset = NULL, $maxOffset = NULL, $context = 'display') { + // These options are deprecated. Definitely not used in datepicker. Possibly not even in jcalendar+addDateTime. $date = array( 'addEmptyOption' => TRUE, 'emptyOptionText' => ts('- select -'), @@ -328,25 +329,34 @@ class CRM_Core_SelectValues { if (!$dao->find(TRUE)) { CRM_Core_Error::fatal(); } - } + if (!$maxOffset) { + $maxOffset = $dao->end; + } + if (!$minOffset) { + $minOffset = $dao->start; + } - if ($type == 'creditCard') { - $minOffset = $dao->start; - $maxOffset = $dao->end; $date['format'] = $dao->date_format; - $date['addEmptyOption'] = TRUE; - $date['emptyOptionText'] = ts('- select -'); - $date['emptyOptionValue'] = ''; + $date['time'] = (bool) $dao->time_format; } if (empty($date['format'])) { - $date['format'] = 'M d'; + if ($context == 'Input') { + $date['format'] = Civi::settings()->get('dateInputFormat'); + $date['php_datetime_format'] = self::datePluginToPHPFormats(Civi::settings()->get('dateInputFormat')); + } + else { + $date['format'] = 'M d'; + } } } + if (!isset($date['time'])) { + $date['time'] = FALSE; + } $year = date('Y'); - $date['minYear'] = $year - $minOffset; - $date['maxYear'] = $year + $maxOffset; + $date['minYear'] = $year - (int) $minOffset; + $date['maxYear'] = $year + (int) $maxOffset; return $date; } diff --git a/CRM/Price/Form/Field.php b/CRM/Price/Form/Field.php index bf39aa55b7..51f7d3fd05 100644 --- a/CRM/Price/Form/Field.php +++ b/CRM/Price/Form/Field.php @@ -327,13 +327,6 @@ class CRM_Price_Form_Field extends CRM_Core_Form { CRM_Core_DAO::getAttribute('CRM_Price_DAO_PriceField', 'help_post') ); - // active_on - $date_options = array( - 'format' => 'dmY His', - 'minYear' => date('Y') - 1, - 'maxYear' => date('Y') + 5, - 'addEmptyOption' => TRUE, - ); $this->addDateTime('active_on', ts('Active On'), FALSE, array('formatType' => 'activityDateTime')); // expire_on -- 2.25.1