This came out of discovering a place in the code was 'accidentally formatted correctly'
and finding it far too hard to figure out the right way to specify the date formatting -
something that seems confirmed by finding various places with hard-coded date formattin
rather than using the setting
foreach ($form->_lineItem[$form->_priceSetId] as & $priceFieldOp) {
if (!empty($priceFieldOp['membership_type_id']) && $membership->membership_type_id == $priceFieldOp['membership_type_id']) {
$membershipOb = $membership;
- $priceFieldOp['start_date'] = $membershipOb->start_date ? CRM_Utils_Date::customFormat($membershipOb->start_date, '%B %E%f, %Y') : '-';
- $priceFieldOp['end_date'] = $membershipOb->end_date ? CRM_Utils_Date::customFormat($membershipOb->end_date, '%B %E%f, %Y') : '-';
+ $priceFieldOp['start_date'] = $membershipOb->start_date ? CRM_Utils_Date::formatDateOnlyLong($membershipOb->start_date) : '-';
+ $priceFieldOp['end_date'] = $membershipOb->end_date ? CRM_Utils_Date::formatDateOnlyLong($membershipOb->end_date) : '-';
}
else {
$priceFieldOp['start_date'] = $priceFieldOp['end_date'] = 'N/A';
$form->assign('formValues', $formValues);
if (empty($lineItem)) {
- $form->assign('mem_start_date', CRM_Utils_Date::customFormat($membership->start_date, '%B %E%f, %Y'));
+ $form->assign('mem_start_date', CRM_Utils_Date::formatDateOnlyLong($membership->start_date));
if (!CRM_Utils_System::isNull($membership->end_date)) {
- $form->assign('mem_end_date', CRM_Utils_Date::customFormat($membership->end_date, '%B %E%f, %Y'));
+ $form->assign('mem_end_date', CRM_Utils_Date::formatDateOnlyLong($membership->end_date));
}
$form->assign('membership_name', CRM_Member_PseudoConstant::membershipType($membership->membership_type_id));
}
$totalTaxAmount = 0;
foreach ($lineItem[$this->_priceSetId] as & $priceFieldOp) {
if (!empty($priceFieldOp['membership_type_id'])) {
- $priceFieldOp['start_date'] = $membershipTypeValues[$priceFieldOp['membership_type_id']]['start_date'] ? CRM_Utils_Date::customFormat($membershipTypeValues[$priceFieldOp['membership_type_id']]['start_date'], '%B %E%f, %Y') : '-';
- $priceFieldOp['end_date'] = $membershipTypeValues[$priceFieldOp['membership_type_id']]['end_date'] ? CRM_Utils_Date::customFormat($membershipTypeValues[$priceFieldOp['membership_type_id']]['end_date'], '%B %E%f, %Y') : '-';
+ $priceFieldOp['start_date'] = $membershipTypeValues[$priceFieldOp['membership_type_id']]['start_date'] ? CRM_Utils_Date::formatDateOnlyLong($membershipTypeValues[$priceFieldOp['membership_type_id']]['start_date']) : '-';
+ $priceFieldOp['end_date'] = $membershipTypeValues[$priceFieldOp['membership_type_id']]['end_date'] ? CRM_Utils_Date::formatDateOnlyLong($membershipTypeValues[$priceFieldOp['membership_type_id']]['end_date']) : '-';
}
else {
$priceFieldOp['start_date'] = $priceFieldOp['end_date'] = 'N/A';
}
if ($memEndDate && $memEndDate !== 'null') {
- $memEndDate = CRM_Utils_Date::customFormat($memEndDate);
+ $memEndDate = CRM_Utils_Date::formatDateOnlyLong($memEndDate);
$statusMsg[$memType] .= ' ' . ts('The new membership End Date is %1.', [1 => $memEndDate]);
}
}
$membership->membership_type_id
));
$this->assign('customValues', $customValues);
- $this->assign('mem_start_date', CRM_Utils_Date::customFormat($membership->start_date));
- $this->assign('mem_end_date', CRM_Utils_Date::customFormat($membership->end_date));
+ $this->assign('mem_start_date', CRM_Utils_Date::formatDateOnlyLong($membership->start_date));
+ $this->assign('mem_end_date', CRM_Utils_Date::formatDateOnlyLong($membership->end_date));
if ($this->_mode) {
$this->assign('address', CRM_Utils_Address::getFormattedBillingAddressFieldsFromParameters(
$this->_params,
}
}
+ /**
+ * Format the field according to the site's preferred date format.
+ *
+ * This is likely to look something like December 31st, 2020.
+ *
+ * @param string $date
+ *
+ * @return string
+ */
+ public static function formatDateOnlyLong(string $date):string {
+ return CRM_Utils_Date::customFormat($date, Civi::settings()->get('dateformatFull'));
+ }
+
/**
* Wrapper for customFormat that takes a timestamp
*
$this->createLoggedInUser();
$params = [
'cid' => $this->_individualId,
- 'join_date' => date('2/d/Y'),
+ 'join_date' => date('Y-m-d'),
'start_date' => '',
'end_date' => '',
// This format reflects the organisation & then the type.
], 1);
$this->assertEquals([
[
- 'text' => 'AnnualFixed membership for Mr. Anthony Anderson II has been added. The new membership End Date is ' . date('F jS, Y', strtotime('last day of this month')) . ' 12:00 AM.',
+ 'text' => 'AnnualFixed membership for Mr. Anthony Anderson II has been added. The new membership End Date is ' . date('F jS, Y', strtotime('last day of this month')) . '.',
'title' => 'Complete',
'type' => 'success',
'options' => NULL,