date — calendar date input widget
This widget allows the user to select a calendar date.
You can adjust the year range with the year_begin
and
year_end
options, which default to UI_DATE_BEGIN
and UI_DATE_END
variables respectively.
Example: Specifying year range
[display type=date name=create_date value="[value create_date]" year_begin=1975 year_end=2020]
Interchange 5.9.0:
Source: code/Widget/date.widget
Lines: 12
# Copyright 2005-2007 Interchange Development Group and others # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. See the LICENSE file for details. # # $Id: date.widget,v 1.3 2007-03-30 23:40:58 pajamian Exp $ CodeDef date Widget 1 CodeDef date Description Date selector CodeDef date MapRoutine Vend::Form::date_widget
Source: lib/Vend/Form.pm
Lines: 634
sub date_widget { my($opt) = @_; my $name = $opt->{name}; my $val = $opt->{value}; if($val =~ /\D/) { $val = Vend::Interpolate::filter_value('date_change', $val); } my $now; if($opt->{time} and $opt->{time_adjust} =~ /([-+]?)(\d+)/) { my $sign = $1 || '+'; my $adjust = $2; $adjust *= 3600; $now = time; $now += $sign eq '+' ? $adjust : -$adjust; } my $sel_extra; my $opt_extra; for(qw/ class style extra /) { my $stag = "select_$_"; my $otag = "option_$_"; my $selapp; my $optapp; if($_ eq 'extra') { $selapp = " $opt->{$stag}"; $optapp = " $opt->{$otag}"; } else { $selapp = qq{ $_="$opt->{$stag}"}; $optapp = qq{ $_="$opt->{$otag}"}; } $sel_extra .= $opt->{$stag} ? $selapp : ''; $opt_extra .= $opt->{$otag} ? $optapp : ''; } my @t = localtime($now || time); my $sel = 0; my $out = qq{<select name="$name"$sel_extra>}; my $o; if ($opt->{blank}) { $out .= qq{<option value="0"$opt_extra>------</option>}; } elsif (not $val) { # use current time with possible adjustments as default value $t[2]++ if $t[2] < 23; $val = POSIX::strftime("%Y%m%d%H00", @t); } for(@Months) { $o = qq{<option value="$_->[0]"$opt_extra>} . errmsg($_->[1]) . '</option>'; ($out .= $o, next) unless ! $sel and $val; $o =~ s/>/ SELECTED>/ && $sel++ if substr($val, 4, 2) eq $_->[0]; $out .= $o; } $sel = 0; $out .= qq{</select>}; $out .= qq{<input type="hidden" name="$name" value="/">}; $out .= qq{<select name="$name"$sel_extra>}; if ($opt->{blank}) { $out .= qq{<option value="0"$opt_extra>--</option>}; } for(@Days) { $o = qq{<option value="$_->[0]"$opt_extra>$_->[1]} . '</option>'; ($out .= $o, next) unless ! $sel and $val; $o =~ s/>/ SELECTED>/ && $sel++ if substr($val, 6, 2) eq $_->[0]; $out .= $o; } $sel = 0; $out .= qq{</select>}; $out .= qq{<input type="hidden" name="$name" value="/">}; $out .= qq{<select name="$name"$sel_extra>}; my $cy = $t[5] + 1900; # If year_begin or year_end are /00+/, make current year for(qw/ year_begin year_end /) { if( length($opt->{$_}) > 1 and $opt->{$_} == 0) { $opt->{$_} = $cy; } } if(my $by = $opt->{year_begin} || $::Variable->{UI_DATE_BEGIN}) { my $ey = $opt->{year_end} || $::Variable->{UI_DATE_END} || ($cy + 10); if($by < 100) { $by = $cy - abs($by); } if($ey < 100) { $ey += $cy; } @Years = $by <= $ey ? ($by .. $ey) : reverse ($ey .. $by); } if ($opt->{blank}) { $out .= qq{<option value="0000"$opt_extra>----</option>}; } for(@Years) { $o = qq{<option$opt_extra>$_} . '</option>'; ($out .= $o, next) unless ! $sel and $val; $o =~ s/>/ SELECTED>/ && $sel++ if substr($val, 0, 4) eq $_; $out .= $o; } $out .= qq{</select>}; return $out unless $opt->{time}; $val =~ s/^(\d{8})//; # If the date is blank (0000-00-00), treat time of 00:00 as blank, # not midnight, in the option selection below my $blank_time = ($opt->{blank} and $1 !~ /[1-9]/); $val =~ s/\D+//g; $val = round_to_fifteen($val); $out .= qq{<input type="hidden" name="$name" value=":">}; $out .= qq{<select name="$name"$sel_extra>}; if ($opt->{blank}) { $out .= qq{<option value="0"$opt_extra>--:--</option>}; } my $ampm = defined $opt->{ampm} ? $opt->{ampm} : 1; my $mod = ''; undef $sel; my %special = qw/ 0 midnight 12 noon /; my @min; $opt->{minutes} ||= ''; if($opt->{minutes} =~ /half/i) { @min = (0,30); } elsif($opt->{minutes} =~ /hourly/i) { @min = (0); } elsif($opt->{minutes} =~ /ten/i) { @min = (0,10,20,30,40,50); } elsif($opt->{minutes} =~ /[\0,]/) { @min = grep /^\d+$/ && $_ <= 59, split /[\0,\s]+/, $opt->{minutes}; } else { @min = (0,15,30,45); } $opt->{start_hour} ||= 0; for(qw/start_hour end_hour/) { $opt->{$_} = int(abs($opt->{$_})); if($opt->{$_} > 23) { $opt->{$_} = 0; } } $opt->{start_hour} ||= 0; $opt->{end_hour} ||= 23; for my $hr ( $opt->{start_hour} .. $opt->{end_hour} ) { next if defined $opt->{start_hour} and $hr < $opt->{start_hour}; next if defined $opt->{end_hour} and $hr > $opt->{end_hour}; for my $min ( @min ) { my $disp_hour = $hr; if($opt->{ampm}) { if( $hr < 12) { $mod = 'am'; } else { $mod = 'pm'; $disp_hour = $hr - 12 unless $hr == 12; } $mod = errmsg($mod); $mod = " $mod"; } if($special{$hr} and $min == 0) { $disp_hour = errmsg($special{$hr}); } elsif($ampm) { $disp_hour = sprintf("%2d:%02d%s", $disp_hour, $min, $mod); } else { $disp_hour = sprintf("%02d:%02d", $hr, $min); } my $time = sprintf "%02d%02d", $hr, $min; $o = sprintf qq{<option value="%s"$opt_extra>%s}, $time, $disp_hour; ($out .= $o, next) unless ! $sel and $val; #::logDebug("prospect=$time actual=$val"); $o =~ s/>/ SELECTED>/ && $sel++ if ! $blank_time and $val eq $time; $out .= $o; } } $out .= "</select>"; return $out; }