*/
public static function getAbbrWeekdayNames() {
$key = 'abbrDays_' . \CRM_Core_I18n::getLocale();
- $days = &\Civi::$statics[__CLASS__][$key];
- if (!$days) {
- $days = [];
+ if (empty(\Civi::$statics[__CLASS__][$key])) {
+ $intl_formatter = IntlDateFormatter::create(CRM_Core_I18n::getLocale(), IntlDateFormatter::MEDIUM, IntlDateFormatter::MEDIUM, NULL, IntlDateFormatter::GREGORIAN, 'E');
+ $days = [
+ 0 => $intl_formatter->format(strtotime('Sunday')),
+ 1 => $intl_formatter->format(strtotime('Monday')),
+ 2 => $intl_formatter->format(strtotime('Tuesday')),
+ 3 => $intl_formatter->format(strtotime('Wednesday')),
+ 4 => $intl_formatter->format(strtotime('Thursday')),
+ 5 => $intl_formatter->format(strtotime('Friday')),
+ 6 => $intl_formatter->format(strtotime('Saturday')),
+ ];
// First day of the week
$firstDay = Civi::settings()->get('weekBegins');
- // set LC_TIME and build the arrays from locale-provided names
- // June 1st, 1970 was a Monday
- CRM_Core_I18n::setLcTime();
- for ($i = $firstDay; count($days) < 7; $i = $i > 5 ? 0 : $i + 1) {
- $days[$i] = strftime('%a', mktime(0, 0, 0, 6, $i, 1970));
+ \Civi::$statics[__CLASS__][$key] = [];
+ for ($i = $firstDay; count(\Civi::$statics[__CLASS__][$key]) < 7; $i = $i > 5 ? 0 : $i + 1) {
+ \Civi::$statics[__CLASS__][$key][$i] = $days[$i];
}
}
- return $days;
+ return \Civi::$statics[__CLASS__][$key];
}
/**
*/
public static function getFullWeekdayNames() {
$key = 'fullDays_' . \CRM_Core_I18n::getLocale();
- $days = &\Civi::$statics[__CLASS__][$key];
- if (!$days) {
- $days = [];
+ if (empty(\Civi::$statics[__CLASS__][$key])) {
+ $intl_formatter = IntlDateFormatter::create(CRM_Core_I18n::getLocale(), IntlDateFormatter::MEDIUM, IntlDateFormatter::MEDIUM, NULL, IntlDateFormatter::GREGORIAN, 'EEEE');
+ $days = [
+ 0 => $intl_formatter->format(strtotime('Sunday')),
+ 1 => $intl_formatter->format(strtotime('Monday')),
+ 2 => $intl_formatter->format(strtotime('Tuesday')),
+ 3 => $intl_formatter->format(strtotime('Wednesday')),
+ 4 => $intl_formatter->format(strtotime('Thursday')),
+ 5 => $intl_formatter->format(strtotime('Friday')),
+ 6 => $intl_formatter->format(strtotime('Saturday')),
+ ];
// First day of the week
$firstDay = Civi::settings()->get('weekBegins');
- // set LC_TIME and build the arrays from locale-provided names
- // June 1st, 1970 was a Monday
- CRM_Core_I18n::setLcTime();
- for ($i = $firstDay; count($days) < 7; $i = $i > 5 ? 0 : $i + 1) {
- $days[$i] = strftime('%A', mktime(0, 0, 0, 6, $i, 1970));
+ \Civi::$statics[__CLASS__][$key] = [];
+ for ($i = $firstDay; count(\Civi::$statics[__CLASS__][$key]) < 7; $i = $i > 5 ? 0 : $i + 1) {
+ \Civi::$statics[__CLASS__][$key][$i] = $days[$i];
}
}
- return $days;
+ return \Civi::$statics[__CLASS__][$key];
}
/**
*/
public static function &getAbbrMonthNames($month = FALSE) {
$key = 'abbrMonthNames_' . \CRM_Core_I18n::getLocale();
- $abbrMonthNames = &\Civi::$statics[__CLASS__][$key];
- if (!isset($abbrMonthNames)) {
-
- // set LC_TIME and build the arrays from locale-provided names
- CRM_Core_I18n::setLcTime();
- for ($i = 1; $i <= 12; $i++) {
- $abbrMonthNames[$i] = strftime('%b', mktime(0, 0, 0, $i, 10, 1970));
- }
+ if (empty(\Civi::$statics[__CLASS__][$key])) {
+ $intl_formatter = IntlDateFormatter::create(CRM_Core_I18n::getLocale(), IntlDateFormatter::MEDIUM, IntlDateFormatter::MEDIUM, NULL, IntlDateFormatter::GREGORIAN, 'MMM');
+ \Civi::$statics[__CLASS__][$key] = [
+ 1 => $intl_formatter->format(strtotime('January')),
+ 2 => $intl_formatter->format(strtotime('February')),
+ 3 => $intl_formatter->format(strtotime('March')),
+ 4 => $intl_formatter->format(strtotime('April')),
+ 5 => $intl_formatter->format(strtotime('May')),
+ 6 => $intl_formatter->format(strtotime('June')),
+ 7 => $intl_formatter->format(strtotime('July')),
+ 8 => $intl_formatter->format(strtotime('August')),
+ 9 => $intl_formatter->format(strtotime('September')),
+ 10 => $intl_formatter->format(strtotime('October')),
+ 11 => $intl_formatter->format(strtotime('November')),
+ 12 => $intl_formatter->format(strtotime('December')),
+ ];
}
if ($month) {
- return $abbrMonthNames[$month];
+ return \Civi::$statics[__CLASS__][$key][$month];
}
- return $abbrMonthNames;
+ return \Civi::$statics[__CLASS__][$key];
}
/**
/**
* Create a date and time string in a provided format.
- *
+ * %A - Full day name ('Saturday'..'Sunday')
+ * %a - abbreviated day name ('Sat'..'Sun')
* %b - abbreviated month name ('Jan'..'Dec')
* %B - full month name ('January'..'December')
* %d - day of the month as a decimal number, 0-padded ('01'..'31')
// 1-based (January) month names arrays
$abbrMonths = self::getAbbrMonthNames();
$fullMonths = self::getFullMonthNames();
+ $fullWeekdayNames = self::getFullWeekdayNames();
+ $abbrWeekdayNames = self::getAbbrWeekdayNames();
+
+ // backwards compatability with %D being the equivilant of %m/%d/%y
+ $format = str_replace('%D', '%m/%d/%y', $format);
if (!$format) {
$config = CRM_Core_Config::singleton();
$second = (int) substr($dateString, 12, 2);
}
+ $dayInt = date('w', strtotime($dateString));
+
if ($day % 10 == 1 and $day != 11) {
$suffix = 'st';
}
}
$date = [
+ '%A' => $fullWeekdayNames[$dayInt] ?? NULL,
+ '%a' => $abbrWeekdayNames[$dayInt] ?? NULL,
'%b' => $abbrMonths[$month] ?? NULL,
'%B' => $fullMonths[$month] ?? NULL,
'%d' => $day > 9 ? $day : '0' . $day,
'%i' => $minute > 9 ? $minute : '0' . $minute,
'%p' => strtolower($type),
'%P' => $type,
- '%A' => $type,
'%Y' => $year,
+ '%y' => substr($year, 2),
'%s' => str_pad($second, 2, 0, STR_PAD_LEFT),
'%S' => str_pad($second, 2, 0, STR_PAD_LEFT),
+ '%Z' => date('T', strtotime($dateString)),
];
return strtr($format, $date);