3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
17 class CRM_Core_Form_Date
{
20 * Various Date Formats.
22 const DATE_yyyy_mm_dd
= 1, DATE_mm_dd_yy
= 2, DATE_mm_dd_yyyy
= 4, DATE_Month_dd_yyyy
= 8, DATE_dd_mon_yy
= 16, DATE_dd_mm_yyyy
= 32;
25 * Build the date-format form.
27 * @param CRM_Core_Form $form
28 * The form object that we are operating on.
30 public static function buildAllowedDateFormats(&$form) {
34 if (CRM_Utils_System
::getClassName($form) == 'CRM_Activity_Import_Form_DataSource') {
35 $dateText = ts('yyyy-mm-dd OR yyyy-mm-dd HH:mm OR yyyymmdd OR yyyymmdd HH:mm (1998-12-25 OR 1998-12-25 15:33 OR 19981225 OR 19981225 10:30 OR ( 2008-9-1 OR 2008-9-1 15:33 OR 20080901 15:33)');
38 $dateText = ts('yyyy-mm-dd OR yyyymmdd (1998-12-25 OR 19981225) OR (2008-9-1 OR 20080901)');
41 $form->addRadio('dateFormats', ts('Date Format'), [
42 self
::DATE_yyyy_mm_dd
=> $dateText,
43 self
::DATE_mm_dd_yy
=> ts('mm/dd/yy OR mm-dd-yy (12/25/98 OR 12-25-98) OR (9/1/08 OR 9-1-08)'),
44 self
::DATE_mm_dd_yyyy
=> ts('mm/dd/yyyy OR mm-dd-yyyy (12/25/1998 OR 12-25-1998) OR (9/1/2008 OR 9-1-2008)'),
45 self
::DATE_Month_dd_yyyy
=> ts('Month dd, yyyy (December 12, 1998)'),
46 self
::DATE_dd_mon_yy
=> ts('dd-mon-yy OR dd/mm/yy (25-Dec-98 OR 25/12/98)'),
47 self
::DATE_dd_mm_yyyy
=> ts('dd/mm/yyyy (25/12/1998) OR (1/9/2008)'),
49 $form->setDefaults(['dateFormats' => self
::DATE_yyyy_mm_dd
]);
53 * Retrieve the date range - relative or absolute and assign it to the form.
57 * @param CRM_Core_Form $form
58 * The form the dates should be added to.
59 * @param string $fieldName
63 * @param string $fromLabel
64 * @param bool $required
65 * @param array $operators
66 * Additional value pairs to add.
67 * @param string $dateFormat
68 * @param bool|string $displayTime
69 * @param array $attributes
71 public static function buildDateRange(
72 &$form, $fieldName, $count = 1,
73 $from = '_from', $to = '_to', $fromLabel = 'From:',
74 $required = FALSE, $operators = [],
75 $dateFormat = 'searchDate', $displayTime = FALSE,
76 $attributes = ['class' => 'crm-select2']
78 CRM_Core_Error
::deprecatedFunctionWarning('function will be removed');
80 = CRM_Core_Form_Date
::returnDateRangeSelector(
81 $form, $fieldName, $count,
82 $from, $to, $fromLabel,
83 $required, $operators,
84 $dateFormat, $displayTime
86 CRM_Core_Form_Date
::addDateRangeToForm(
87 $form, $fieldName, $selector,
88 $from, $to, $fromLabel,
89 $required, $dateFormat, $displayTime,
95 * Build the date range array that will provide the form option values.
99 * It can be - relative or absolute.
101 * @param CRM_Core_Form $form
102 * The form object that we are operating on.
103 * @param string $fieldName
105 * @param string $from
107 * @param string $fromLabel
108 * @param bool $required
109 * @param array $operators
110 * Additional Operator Selections to add.
111 * @param string $dateFormat
112 * @param bool $displayTime
115 * Values for Selector
117 public static function returnDateRangeSelector(
118 &$form, $fieldName, $count = 1,
119 $from = '_from', $to = '_to', $fromLabel = 'From:',
120 $required = FALSE, $operators = [],
121 $dateFormat = 'searchDate', $displayTime = FALSE
123 CRM_Core_Error
::deprecatedFunctionWarning('function will be removed');
126 0 => ts('Choose Date Range'),
128 // CRM-16195 Pull relative date filters from an option group
129 $selector = $selector + CRM_Core_OptionGroup
::values('relative_date_filters');
131 if (is_array($operators)) {
132 $selector = array_merge($selector, $operators);
135 $config = CRM_Core_Config
::singleton();
136 //if fiscal year start on 1 jan then remove fiscal year task
138 if ($config->fiscalYearStart
['d'] == 1 & $config->fiscalYearStart
['M'] == 1) {
139 unset($selector['this.fiscal_year']);
140 unset($selector['previous.fiscal_year']);
146 * Build the date range - relative or absolute.
150 * @param CRM_Core_Form $form
151 * The form object that we are operating on.
152 * @param string $fieldName
153 * @param array $selector
154 * Array of option values to add.
155 * @param string $from
158 * @param string $fromLabel
159 * @param bool $required
160 * @param string $dateFormat
161 * @param bool $displayTime
162 * @param array $attributes
164 public static function addDateRangeToForm(
176 CRM_Core_Error
::deprecatedFunctionWarning('function will be removed');
178 "{$fieldName}_relative",
179 ts('Relative Date Range'),
185 $form->addDateRange($fieldName, $from, $to, $fromLabel, $dateFormat, FALSE, $displayTime);