diff --git a/NEWS b/NEWS index b57abcb8..93e0322d 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,6 @@ + - make html_select_date work with negative timestamps, also + force year range to include given date unless explicitly + set (Garo, Monte) - fix bug with fetch, passing user/pass in url did not work (Monte) - fix occasional wrong error messages on mismatched tags when diff --git a/libs/plugins/function.html_select_date.php b/libs/plugins/function.html_select_date.php index 3de7f532..9f1978ac 100644 --- a/libs/plugins/function.html_select_date.php +++ b/libs/plugins/function.html_select_date.php @@ -122,6 +122,10 @@ function smarty_function_html_select_date($params, &$smarty) } } + if(preg_match('!^-\d+$!',$time)) { + // negative timestamp, use date() + $time = date('Y-m-d',$time); + } // If $time is not in format yyyy-mm-dd if (!preg_match('/^\d{0,4}-\d{0,2}-\d{0,2}$/', $time)) { // then $time is empty or unix timestamp or mysql timestamp @@ -131,7 +135,7 @@ function smarty_function_html_select_date($params, &$smarty) } // Now split this in pieces, which later can be used to set the select $time = explode("-", $time); - + // make syntax "+N" or "-N" work with start_year and end_year if (preg_match('!^(\+|\-)\s*(\d+)$!', $end_year, $match)) { if ($match[1] == '+') { @@ -147,6 +151,14 @@ function smarty_function_html_select_date($params, &$smarty) $start_year = strftime('%Y') - $match[2]; } } + if($start_year > $time[0] && !isset($params['start_year'])) { + // force start year to include given date if not explicitly set + $start_year = $time[0]; + } + if($end_year < $time[0] && !isset($params['end_year'])) { + // force end year to include given date if not explicitly set + $end_year = $time[0]; + } $field_order = strtoupper($field_order);