Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
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 | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | */ |
17 | ||
18 | /** | |
19 | * Convert the date string "YYYY-MM-DD" to "MM<long> DD, YYYY". | |
20 | * | |
6a0b768e TO |
21 | * @param string $dateString |
22 | * Date which needs to converted to human readable format. | |
6a488035 | 23 | * |
5f95ae68 EM |
24 | * @param string|null $dateFormat |
25 | * A string per https://www.php.net/manual/en/function.strftime.php or | |
26 | * one of our configured formats name - eg | |
27 | * - dateformatDatetime | |
28 | * - dateformatFull | |
29 | * - dateformatPartial | |
30 | * - dateformatTime | |
31 | * - dateformatYear | |
32 | * - dateformatFinancialBatch | |
33 | * - dateformatshortdate | |
34 | * | |
77b97be7 EM |
35 | * @param bool $onlyTime |
36 | * | |
a6c01b45 | 37 | * @return string |
353ffa53 | 38 | * human readable date format | invalid date message |
6a488035 | 39 | */ |
5f95ae68 | 40 | function smarty_modifier_crmDate($dateString, ?string $dateFormat = NULL, bool $onlyTime = FALSE): string { |
6a488035 | 41 | if ($dateString) { |
5f95ae68 EM |
42 | $configuredFormats = [ |
43 | 'Datetime', | |
44 | 'Full', | |
45 | 'Partial', | |
46 | 'Time', | |
47 | 'Year', | |
48 | 'FinancialBatch', | |
49 | 'shortdate', | |
50 | ]; | |
51 | if (in_array($dateFormat, $configuredFormats, TRUE)) { | |
52 | $dateFormat = Civi::settings()->get('dateformat' . $dateFormat); | |
53 | } | |
6a488035 TO |
54 | // this check needs to be type sensitive |
55 | // CRM-3689, CRM-2441 | |
56 | if ($dateFormat === 0) { | |
57 | $dateFormat = NULL; | |
58 | } | |
59 | if ($onlyTime) { | |
60 | $config = CRM_Core_Config::singleton(); | |
61 | $dateFormat = $config->dateformatTime; | |
62 | } | |
63 | ||
64 | return CRM_Utils_Date::customFormat($dateString, $dateFormat); | |
65 | } | |
66 | return ''; | |
67 | } |