make time param work with negative timestamps, force year range to include

given date unless explicitly set
This commit is contained in:
mohrt
2004-08-20 13:48:46 +00:00
parent 59ba8f5b33
commit e430d63e56
2 changed files with 16 additions and 1 deletions

3
NEWS
View File

@@ -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

View File

@@ -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);