summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLester Caine <lester@lsces.co.uk>2026-05-20 15:33:22 +0100
committerLester Caine <lester@lsces.co.uk>2026-05-20 15:33:22 +0100
commitc46f0d990ac840fc48d59c6cbc119664d56a7dca (patch)
tree9879ba4db40edaffc9ef775b2fa63494af7f0b05
parent86f43bb327ea9e4fe0a3e7548a74e6faecab878a (diff)
downloadsmarty-c46f0d990ac840fc48d59c6cbc119664d56a7dca.tar.gz
smarty-c46f0d990ac840fc48d59c6cbc119664d56a7dca.tar.bz2
smarty-c46f0d990ac840fc48d59c6cbc119664d56a7dca.zip
Replace deprecated strftime() with IntlDateFormatter in HtmlSelectDate
strftime() was removed in PHP 8.2; use IntlDateFormatter('en_GB') with a regex to extract the month name, for PHP 8.5 compatibility. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
-rw-r--r--src/FunctionHandler/HtmlSelectDate.php14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/FunctionHandler/HtmlSelectDate.php b/src/FunctionHandler/HtmlSelectDate.php
index a6acfb7b..83d512fa 100644
--- a/src/FunctionHandler/HtmlSelectDate.php
+++ b/src/FunctionHandler/HtmlSelectDate.php
@@ -273,6 +273,7 @@ class HtmlSelectDate extends Base {
}
// generate month <select> or <input>
if ($display_months) {
+ $dateFormatter = new \IntlDateFormatter('en_GB', \IntlDateFormatter::LONG, \IntlDateFormatter::NONE);
$_extra = '';
$_name = $field_array ? ($field_array . '[' . $prefix . 'Month]') : ($prefix . 'Month');
if ($all_extra) {
@@ -301,12 +302,17 @@ class HtmlSelectDate extends Base {
for ($i = 1; $i <= 12; $i++) {
$_val = sprintf('%02d', $i);
$_text = isset($month_names) ? smarty_function_escape_special_chars($month_names[$i]) :
- ($month_format === '%m' ? $_val : @strftime($month_format, $_month_timestamps[$i]));
- $_value = $month_value_format === '%m' ? $_val : @strftime($month_value_format, $_month_timestamps[$i]);
+ ($month_format === '%m' ? $_val : $dateFormatter->format($_month_timestamps[$i]));
+ $pattern = '/\d{1,2}\s+([a-zA-ZáéíóúüñÁÉÍÓÚÜÑ]+)\s+\d{4}/u';
+ // Match the pattern
+ if (preg_match($pattern, $_text, $matches)) {
+ // The month part is in the first capturing group
+ $_text = $matches[1] ?? $_val;
+ }
+ $_value = $month_value_format === '%m' ? $_val : $dateFormatter->format($_month_timestamps[$i]);
$_html_months .= '<option value="' . $_value . '"' . ($_val == $_month ? ' selected="selected"' : '') .
'>' . $_text . '</option>' . $option_separator;
- }
- $_html_months .= '</select>';
+ } $_html_months .= '</select>';
}
// generate day <select> or <input>
if ($display_days) {