Re: [SMARTY-DEV] function.html_select_date.php bug?

[email protected] ("messju mohr")
Newsgroups php.smarty.dev
Message-ID <20050325113937.GA26129@dune>
On Fri, Mar 25, 2005 at 10:27:54AM +0100, Yuri Weseman wrote:
> Hi,
> 
> http://cvs.php.net/co.php/smarty/libs/plugins/function.html_select_date.php?r=1.29#201
> 
> I think there's a bug in this line. It now reads:
> 'selected'   => $a=$time[1] ? strftime($month_value_format, mktime(0,
> 0, 0, (int)$time[1], 1, 2000)) : '',
> 
> I think this would be better:
> 
> 'selected'   => $time[1]>0 ? strftime($month_value_format, mktime(0,
> 0, 0, (int)$time[1], 1, 2000)) : '',
> 
> I don't understand why $a should be assigned as it is isn't used later
> on in the code. And because $time[1] doesn't always have to be 0 (as
> is the case when your date comes out of the database like 0000-00-00)
> this results in december to be selected.
> To explain this: The value of $time[1] is 00 then, which results in
> true for the check $a=$time[1], which results in
> strftime($month_value_format, mktime(0, 0, 0, (int)$time[1], 1, 2000))
> being executed. And because mktime sees (int)$time[1] as 0, it thinks
> it should selected the last month of the previous year resulting in
> december to be selected.

this sounds very reasonable to me. if nobody objects i like to commit
your suggested fix.

greetings
messju

> You could also use (int) $time[1] instead of $time[1] > 0
> 
> Greetings,
> 
> Yuri
> 
> -- 
> Smarty Development Mailing List (http://smarty.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.