| HTML-DateSelector documentation | Contained in the HTML-DateSelector distribution. |
HTML::DateSelector - Generate HTML for date selector.
use HTML::DateSelector;
HTML::DateSelector->ymd('start_on');
generate HTML for date selector.
my $html = HTML::DateSelector->ymd('start_on');
my $html = HTML::DateSelector->ym('start_on');
date selector.
ymd => year, month, day. ym => year, month.
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.
my $html = HTML::DateSelector->hour('start_on');
my $html = HTML::DateSelector->minute('start_on');
# and...
primitive selector.month, day, hour, minute.
you can select the blank.
Tokuhiro Matsuno <tokuhiro __at__ mobilefactory.jp>
Copyright (c) 2006, Tokuhiro Matsuno <tokuhiro __at__ mobilefactory.jp>. All rights reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Ruby on Rails itself.
| 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__