[ic] dropdown with week of the year ...

Kevin Walsh interchange-users@icdevgroup.org
Sun Aug 11 23:57:00 2002


> 
> I need to make a dropdown box showing the week of the year and the year. It
> needs to show the next 30 weeks starting at the actual one. The problem ist
> when the year changes it should start over at week one again showing
> someting like 01-2003 for example.
> 
How about something like this?

    <select name="date_week">
    [calc]
        my $buf;
        my ($week,$year) = split(':',$Tag->time({body => '%W:%Y'}));
        $week ||= 1;

        for (0 .. 29){
            $week = '0' . $week if length($week) == 1;
            $buf .= qq{<option value="$week">$week-$year</option>\n};
            if (++$week > 52){
                $week = 1;
                $year++;
            }
        }
        $buf;
    [/calc]
    </select>

(Untested)

That code won't take "week 53" into account, for years where the last
Monday creates a "53rd week" (31st December 2007).  If that's important
to you then you should be able to tweak the code accordingly.

-- 
   _/   _/  _/_/_/_/  _/    _/  _/_/_/  _/    _/
  _/_/_/   _/_/      _/    _/    _/    _/_/  _/   K e v i n   W a l s h
 _/ _/    _/          _/ _/     _/    _/  _/_/    kevin@cursor.biz
_/   _/  _/_/_/_/      _/    _/_/_/  _/    _/