*/
class CRM_Activity_Import_Form_DataSource extends CRM_Import_Form_DataSource {
+ /**
+ * Should the text describing date formats include the time.
+ *
+ * This is used to alter the displayed text to that perceived to be more useful.
+ * For activities it is likely the user wants to know how to format time.
+ *
+ * @var bool
+ */
+ protected $isDisplayTimeInDateFormats = TRUE;
+
/**
* Get the name of the type to be stored in civicrm_user_job.type_id.
*
*/
/**
+ *
+ * @deprecated since 5.69 will be removed around 5.79
*
* @package CRM
* @copyright CiviCRM LLC https://civicrm.org/licensing
/**
* Various Date Formats.
+ *
+ * @deprecated since 5.69 will be removed around 5.79
*/
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;
/**
* Build the date-format form.
*
+ * @deprecated since 5.69 will be removed around 5.79
+ *
* @param CRM_Core_Form $form
* The form object that we are operating on.
*/
public static function buildAllowedDateFormats(&$form) {
-
+ CRM_Core_Error::deprecatedFunctionWarning('function & entire class will be removed');
$dateOptions = [];
if (CRM_Utils_System::getClassName($form) == 'CRM_Activity_Import_Form_DataSource') {
/**
* Build the date range array that will provide the form option values.
*
- * @deprecated
+ * @deprecated since 5.28 will be removed around 5.79
*
* It can be - relative or absolute.
*
$required = FALSE, $operators = [],
$dateFormat = 'searchDate', $displayTime = FALSE
) {
- CRM_Core_Error::deprecatedFunctionWarning('function will be removed');
+ CRM_Core_Error::deprecatedFunctionWarning('function has been deprecated since 5.28 & will be removed around 5.79');
$selector = [
'' => ts('- any -'),
0 => ts('Choose Date Range'),
/**
* Build the date range - relative or absolute.
*
- * @deprecated
+ * @deprecated since 5.28 will be removed around 5.79
*
* @param CRM_Core_Form $form
* The form object that we are operating on.
$displayTime,
$attributes
) {
- CRM_Core_Error::deprecatedFunctionWarning('function will be removed');
+ CRM_Core_Error::deprecatedFunctionWarning('function has been deprecated since 5.28 & will be removed around 5.79');
$form->add('select',
"{$fieldName}_relative",
ts('Relative Date Range'),
*/
abstract class CRM_Import_Form_DataSource extends CRM_Import_Forms {
+ /**
+ * Should the text describing date formats include the time.
+ *
+ * This is used to alter the displayed text to that perceived to be more useful.
+ * e.g. for contacts it might be birthdate so including time is confusing
+ * but activities would more likely use them.
+ *
+ * @var bool
+ */
+ protected $isDisplayTimeInDateFormats = FALSE;
+
/**
* Values loaded from a saved UserJob template.
*
}
//build date formats
- CRM_Core_Form_Date::buildAllowedDateFormats($this);
+ $this->buildAllowedDateFormats();
// When we call buildDataSourceFields we add them to the form both for purposes of
// initial display, but also so they are available during `postProcess`. Hence
// we need to add them to the form when first displaying it, or when a csv has been
]);
}
+ /**
+ * Build the date-format form.
+ */
+ protected function buildAllowedDateFormats(): void {
+ $formats = CRM_Utils_Date::getAvailableInputFormats($this->isDisplayTimeInDateFormats);
+ $this->addRadio('dateFormats', ts('Date Format'), $formats, [], '<br/>');
+ $this->setDefaults(['dateFormats' => array_key_first($formats)]);
+ }
+
public function setDefaultValues() {
return array_merge($this->dataSourceDefaults, [
'dataSource' => $this->getDefaultDataSource(),
*/
class CRM_Utils_Date {
+ /**
+ * Date input formats.
+ *
+ * For example a user selecting `DATE_dd_mm_yyyy` in the context of an import is
+ * saying that they want the dates they are importing to be converted from dd_mm_yyy format.
+ */
+ public 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;
+
/**
* Format a date by padding it with leading '0'.
*
return \Civi::$statics[__CLASS__][$key];
}
+ /**
+ * Get the available input formats.
+ *
+ * These are the formats that this class is able to convert into a standard format
+ * provided it knows the input format. These are used when doing an import.
+ *
+ * @param bool $isShowTime
+ *
+ * @return array
+ */
+ public static function getAvailableInputFormats(bool $isShowTime): array {
+ if ($isShowTime) {
+ $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)');
+ }
+ else {
+ $dateText = ts('yyyy-mm-dd OR yyyymmdd (1998-12-25 OR 19981225) OR (2008-9-1 OR 20080901)');
+ }
+ return [
+ CRM_Utils_Date::DATE_yyyy_mm_dd => $dateText,
+ CRM_Utils_Date::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)'),
+ CRM_Utils_Date::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)'),
+ CRM_Utils_Date::DATE_Month_dd_yyyy => ts('Month dd, yyyy (December 12, 1998)'),
+ CRM_Utils_Date::DATE_dd_mon_yy => ts('dd-mon-yy OR dd/mm/yy (25-Dec-98 OR 25/12/98 OR 1-09-98)'),
+ CRM_Utils_Date::DATE_dd_mm_yyyy => ts('dd/mm/yyyy (25/12/1998 OR 1/9/2008 OR 1-Sep-2008)'),
+ ];
+ }
+
/**
* Return abbreviated month names according to the locale.
*
* @param $date
* Date string as entered.
* @param $dateType
- * One of the constants like CRM_Core_Form_Date::DATE_yyyy_mm_dd.
+ * One of the constants like CRM_Utils_Date::DATE_yyyy_mm_dd.
*
* @return null|string
*/
'dataSource' => 'CRM_Import_DataSource_SQL',
'onDuplicate' => CRM_Import_Parser::DUPLICATE_SKIP,
'dedupe_rule_id' => NULL,
- 'dateFormats' => CRM_Core_Form_Date::DATE_yyyy_mm_dd,
+ 'dateFormats' => CRM_Utils_Date::DATE_yyyy_mm_dd,
],
'import_mappings' => [
['name' => 'external_identifier'],
'sqlQuery' => 'SELECT first_name FROM civicrm_contact',
'onDuplicate' => CRM_Import_Parser::DUPLICATE_SKIP,
'dedupe_rule_id' => NULL,
- 'dateFormats' => CRM_Core_Form_Date::DATE_yyyy_mm_dd,
+ 'dateFormats' => CRM_Utils_Date::DATE_yyyy_mm_dd,
], $submittedValues),
],
'status_id:name' => 'draft',
*/
public function dateDataProvider(): array {
return [
- 'type_1' => ['csv' => 'individual_dates_type1.csv', 'dateType' => CRM_Core_Form_Date::DATE_yyyy_mm_dd],
- 'type_2' => ['csv' => 'individual_dates_type2.csv', 'dateType' => CRM_Core_Form_Date::DATE_mm_dd_yy],
- 'type_4' => ['csv' => 'individual_dates_type4.csv', 'dateType' => CRM_Core_Form_Date::DATE_mm_dd_yyyy],
- 'type_8' => ['csv' => 'individual_dates_type8.csv', 'dateType' => CRM_Core_Form_Date::DATE_Month_dd_yyyy],
- 'type_16' => ['csv' => 'individual_dates_type16.csv', 'dateType' => CRM_Core_Form_Date::DATE_dd_mon_yy],
- 'type_32' => ['csv' => 'individual_dates_type32.csv', 'dateType' => CRM_Core_Form_Date::DATE_dd_mm_yyyy],
+ 'type_1' => ['csv' => 'individual_dates_type1.csv', 'dateType' => CRM_Utils_Date::DATE_yyyy_mm_dd],
+ 'type_2' => ['csv' => 'individual_dates_type2.csv', 'dateType' => CRM_Utils_Date::DATE_mm_dd_yy],
+ 'type_4' => ['csv' => 'individual_dates_type4.csv', 'dateType' => CRM_Utils_Date::DATE_mm_dd_yyyy],
+ 'type_8' => ['csv' => 'individual_dates_type8.csv', 'dateType' => CRM_Utils_Date::DATE_Month_dd_yyyy],
+ 'type_16' => ['csv' => 'individual_dates_type16.csv', 'dateType' => CRM_Utils_Date::DATE_dd_mon_yy],
+ 'type_32' => ['csv' => 'individual_dates_type32.csv', 'dateType' => CRM_Utils_Date::DATE_dd_mm_yyyy],
];
}
'sqlQuery' => 'SELECT first_name FROM civicrm_contact',
'onDuplicate' => CRM_Import_Parser::DUPLICATE_SKIP,
'dedupe_rule_id' => NULL,
- 'dateFormats' => CRM_Core_Form_Date::DATE_yyyy_mm_dd,
+ 'dateFormats' => CRM_Utils_Date::DATE_yyyy_mm_dd,
], $submittedValues),
],
'status_id:name' => 'draft',
'mapper' => $mapper,
'dataSource' => 'CRM_Import_DataSource_CSV',
'file' => ['name' => $csv],
- 'dateFormats' => CRM_Core_Form_Date::DATE_yyyy_mm_dd,
+ 'dateFormats' => CRM_Utils_Date::DATE_yyyy_mm_dd,
'onDuplicate' => CRM_Import_Parser::DUPLICATE_UPDATE,
'groups' => [],
], $submittedValues);
'contactType' => 'Organization',
'mapper' => $this->getMapperFromFieldMappings($importMappings),
'dataSource' => 'CRM_Import_DataSource_CSV',
- 'dateFormats' => CRM_Core_Form_Date::DATE_yyyy_mm_dd,
+ 'dateFormats' => CRM_Utils_Date::DATE_yyyy_mm_dd,
'onDuplicate' => CRM_Import_Parser::DUPLICATE_SKIP,
];
$this->submitDataSourceForm('soft_credit_extended.csv', $submittedValues);
'mapper' => $this->getMapperFromFieldMappings($fieldMappings),
'dataSource' => 'CRM_Import_DataSource_CSV',
'file' => ['name' => 'contributions_bad_campaign.csv'],
- 'dateFormats' => CRM_Core_Form_Date::DATE_yyyy_mm_dd,
+ 'dateFormats' => CRM_Utils_Date::DATE_yyyy_mm_dd,
'onDuplicate' => CRM_Import_Parser::DUPLICATE_UPDATE,
'groups' => [],
];
'sqlQuery' => 'SELECT first_name FROM civicrm_contact',
'onDuplicate' => CRM_Import_Parser::DUPLICATE_SKIP,
'dedupe_rule_id' => NULL,
- 'dateFormats' => CRM_Core_Form_Date::DATE_yyyy_mm_dd,
+ 'dateFormats' => CRM_Utils_Date::DATE_yyyy_mm_dd,
], $submittedValues),
],
'status_id:name' => 'draft',
'mapper' => $this->getMapperFromFieldMappings($fieldMappings),
'dataSource' => 'CRM_Import_DataSource_CSV',
'file' => ['name' => $csv],
- 'dateFormats' => CRM_Core_Form_Date::DATE_yyyy_mm_dd,
+ 'dateFormats' => CRM_Utils_Date::DATE_yyyy_mm_dd,
'onDuplicate' => CRM_Import_Parser::DUPLICATE_UPDATE,
'groups' => [],
'saveMapping' => TRUE,
'sqlQuery' => 'SELECT first_name FROM civicrm_contact',
'onDuplicate' => CRM_Import_Parser::DUPLICATE_SKIP,
'dedupe_rule_id' => NULL,
- 'dateFormats' => CRM_Core_Form_Date::DATE_yyyy_mm_dd,
+ 'dateFormats' => CRM_Utils_Date::DATE_yyyy_mm_dd,
], $submittedValues),
],
'status_id:name' => 'draft',
'sqlQuery' => 'SELECT first_name FROM civicrm_contact',
'onDuplicate' => CRM_Import_Parser::DUPLICATE_SKIP,
'dedupe_rule_id' => NULL,
- 'dateFormats' => CRM_Core_Form_Date::DATE_yyyy_mm_dd,
+ 'dateFormats' => CRM_Utils_Date::DATE_yyyy_mm_dd,
], $submittedValues),
],
'status_id:name' => 'draft',
'mapper' => $this->getMapperFromFieldMappings($fieldMappings),
'dataSource' => 'CRM_Import_DataSource_CSV',
'file' => ['name' => $csv],
- 'dateFormats' => CRM_Core_Form_Date::DATE_yyyy_mm_dd,
+ 'dateFormats' => CRM_Utils_Date::DATE_yyyy_mm_dd,
'onDuplicate' => CRM_Import_Parser::DUPLICATE_UPDATE,
'groups' => [],
], $submittedValues);
*/
public function dateDataProvider(): array {
return [
- ['date' => '2022-10-01', 'format' => CRM_Core_Form_Date::DATE_yyyy_mm_dd, 'expected' => '20221001'],
- ['date' => '2022-10-01 15:54', 'format' => CRM_Core_Form_Date::DATE_yyyy_mm_dd, 'expected' => '20221001155400'],
- ['date' => '2022-10-01 15:54:56', 'format' => CRM_Core_Form_Date::DATE_yyyy_mm_dd, 'expected' => '20221001155456'],
+ ['date' => '2022-10-01', 'format' => CRM_Utils_Date::DATE_yyyy_mm_dd, 'expected' => '20221001'],
+ ['date' => '2022-10-01 15:54', 'format' => CRM_Utils_Date::DATE_yyyy_mm_dd, 'expected' => '20221001155400'],
+ ['date' => '2022-10-01 15:54:56', 'format' => CRM_Utils_Date::DATE_yyyy_mm_dd, 'expected' => '20221001155456'],
];
}
'mapper' => $this->getMapperFromFieldMappings($fieldMappings),
'dataSource' => 'CRM_Import_DataSource_CSV',
'file' => ['name' => $csv],
- 'dateFormats' => CRM_Core_Form_Date::DATE_yyyy_mm_dd,
+ 'dateFormats' => CRM_Utils_Date::DATE_yyyy_mm_dd,
'onDuplicate' => CRM_Import_Parser::DUPLICATE_SKIP,
'groups' => [],
], $submittedValues);
'contactType' => 'Individual',
'dataSource' => 'CRM_Import_DataSource_CSV',
'file' => ['name' => $csv],
- 'dateFormats' => CRM_Core_Form_Date::DATE_yyyy_mm_dd,
+ 'dateFormats' => CRM_Utils_Date::DATE_yyyy_mm_dd,
'onDuplicate' => CRM_Import_Parser::DUPLICATE_SKIP,
'groups' => [],
], $submittedValues);