mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-07 03:44:26 +02:00
make html_select_date work consistently with 0000-00-00 00:00:00 and 0000-00-00 inputs
Thanks to cybot from forums
This commit is contained in:
2
NEWS
2
NEWS
@@ -1,3 +1,5 @@
|
|||||||
|
- make html_select_date work consistently with 0000-00-00 00:00:00 and
|
||||||
|
0000-00-00 inputs (cybot, boots)
|
||||||
- fix wrong handling of insert's name attribute. (messju)
|
- fix wrong handling of insert's name attribute. (messju)
|
||||||
- fix false replacement of "$t" inside double quotes (checat, messju)
|
- fix false replacement of "$t" inside double quotes (checat, messju)
|
||||||
- added support for column headings and caption element to html_table and
|
- added support for column headings and caption element to html_table and
|
||||||
|
@@ -24,9 +24,11 @@
|
|||||||
* day values (Marcus Bointon)
|
* day values (Marcus Bointon)
|
||||||
* - 1.3.2 support negative timestamps, force year
|
* - 1.3.2 support negative timestamps, force year
|
||||||
* dropdown to include given date unless explicitly set (Monte)
|
* dropdown to include given date unless explicitly set (Monte)
|
||||||
|
* - 1.3.4 fix behaviour of 0000-00-00 00:00:00 dates to match that
|
||||||
|
* of 0000-00-00 dates (cybot, boots)
|
||||||
* @link http://smarty.php.net/manual/en/language.function.html.select.date.php {html_select_date}
|
* @link http://smarty.php.net/manual/en/language.function.html.select.date.php {html_select_date}
|
||||||
* (Smarty online manual)
|
* (Smarty online manual)
|
||||||
* @version 1.3.2
|
* @version 1.3.4
|
||||||
* @author Andrei Zmievski
|
* @author Andrei Zmievski
|
||||||
* @author Monte Ohrt <monte at ohrt dot com>
|
* @author Monte Ohrt <monte at ohrt dot com>
|
||||||
* @param array
|
* @param array
|
||||||
@@ -131,19 +133,21 @@ function smarty_function_html_select_date($params, &$smarty)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(preg_match('!^-\d+$!',$time)) {
|
if (preg_match('!^-\d+$!', $time)) {
|
||||||
// negative timestamp, use date()
|
// negative timestamp, use date()
|
||||||
$time = date('Y-m-d',$time);
|
$time = date('Y-m-d', $time);
|
||||||
}
|
}
|
||||||
// If $time is not in format yyyy-mm-dd
|
// If $time is not in format yyyy-mm-dd
|
||||||
if (!preg_match('/^\d{0,4}-\d{0,2}-\d{0,2}$/', $time)) {
|
if (preg_match('/^(\d{0,4}-\d{0,2}-\d{0,2})/', $time, $found)) {
|
||||||
|
$time = $found[1];
|
||||||
|
} else {
|
||||||
// use smarty_make_timestamp to get an unix timestamp and
|
// use smarty_make_timestamp to get an unix timestamp and
|
||||||
// strftime to make yyyy-mm-dd
|
// strftime to make yyyy-mm-dd
|
||||||
$time = strftime('%Y-%m-%d', smarty_make_timestamp($time));
|
$time = strftime('%Y-%m-%d', smarty_make_timestamp($time));
|
||||||
}
|
}
|
||||||
// Now split this in pieces, which later can be used to set the select
|
// Now split this in pieces, which later can be used to set the select
|
||||||
$time = explode("-", $time);
|
$time = explode("-", $time);
|
||||||
|
|
||||||
// make syntax "+N" or "-N" work with start_year and end_year
|
// make syntax "+N" or "-N" work with start_year and end_year
|
||||||
if (preg_match('!^(\+|\-)\s*(\d+)$!', $end_year, $match)) {
|
if (preg_match('!^(\+|\-)\s*(\d+)$!', $end_year, $match)) {
|
||||||
if ($match[1] == '+') {
|
if ($match[1] == '+') {
|
||||||
@@ -159,7 +163,7 @@ function smarty_function_html_select_date($params, &$smarty)
|
|||||||
$start_year = strftime('%Y') - $match[2];
|
$start_year = strftime('%Y') - $match[2];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (strlen($time[0]) > 0) {
|
if (strlen($time[0]) > 0) {
|
||||||
if ($start_year > $time[0] && !isset($params['start_year'])) {
|
if ($start_year > $time[0] && !isset($params['start_year'])) {
|
||||||
// force start year to include given date if not explicitly set
|
// force start year to include given date if not explicitly set
|
||||||
$start_year = $time[0];
|
$start_year = $time[0];
|
||||||
|
Reference in New Issue
Block a user