HTML::DateSelector - Generate HTML for date selector.


HTML-DateSelector documentation Contained in the HTML-DateSelector distribution.

Index


Code Index:

NAME

Top

HTML::DateSelector - Generate HTML for date selector.

SYNOPSIS

Top

    use HTML::DateSelector;
    HTML::DateSelector->ymd('start_on');

DESCRIPTION

Top

generate HTML for date selector.

CLASS METHODS

Top

ymd

ym

    my $html = HTML::DateSelector->ymd('start_on');
    my $html = HTML::DateSelector->ym('start_on');

date selector.

ymd => year, month, day. ym => year, month.

year

    my $html = HTML::DateSelector->year('start_on');
    my $html = HTML::DateSelector->year('start_on', {start_on => 2000, end_on => 2005});

Year selector.You can set the span of year.

month

day

hour

minute

  my $html = HTML::DateSelector->hour('start_on');
  my $html = HTML::DateSelector->minute('start_on');
  # and...

primitive selector.month, day, hour, minute.

OPTIONS

Top

include_blank

you can select the blank.

AUTHOR

Top

Tokuhiro Matsuno <tokuhiro __at__ mobilefactory.jp>

SEE ALSO

Top

http://dev.rubyonrails.org/browser/trunk/actionpack/lib/action_view/helpers/date_helper.rb

LICENSE AND COPYRIGHT

Top


HTML-DateSelector documentation Contained in the HTML-DateSelector distribution.

package HTML::DateSelector;
use strict;
use warnings;
use Carp;
use 5.008001;
our $VERSION = '0.04';

sub _this_year {
    my ($class, ) = @_;

    my @localtime = localtime;
    return $localtime[5] + 1900;
}

sub year {
    my ($class, $prefix, $options) = @_;

    my $start = $options->{start_year} || $class->_this_year - 5;
    my $end   = $options->{end_year}   || $class->_this_year + 5;

    return $class->_select_html($prefix, 'year', $start, $end, $options);
}

sub month {
    my ($class, $prefix, $options) = @_;

    return $class->_select_html($prefix, 'month', 1, 12, $options);
}

sub day {
    my ($class, $prefix, $options) = @_;

    return $class->_select_html($prefix, 'day', 1, 31, $options);
}

sub hour {
    my ($class, $prefix, $options) = @_;

    return $class->_select_html($prefix, 'hour', 0, 23, $options);
}

sub minute {
    my ($class, $prefix, $options) = @_;

    return $class->_select_html($prefix, 'minute', 0, 59, $options);
}

sub _select_html {
    my ($class, $prefix, $type, $start, $end, $options) = @_;

    my $result = '';
    $result .= qq{<select name="${prefix}_$type" id="${prefix}_$type">\n};
    $result .= qq{<option value=""></option>\n} if $options->{include_blank};
    for my $i ($start..$end) {
        $result .= qq{<option value="$i">$i</option>\n};
    }
    $result .= qq{</select>};
    return $result;
}

sub ymd {
    my ( $class, $prefix, $options ) = @_;

    return join( "\n\n",
                 $class->ym($prefix, $options),
                 $class->day( $prefix, $options ) );
}

sub ym {
    my ( $class, $prefix, $options ) = @_;

    return join( "\n\n",
                 $class->year( $prefix, $options ),
                 $class->month( $prefix, $options ),
             );
}

1;
__END__