1 # Copyright 2005-2007 Interchange Development Group and others
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version. See the LICENSE file for details.
8 # $Id: time.widget,v 1.3 2007-03-30 23:40:58 pajamian Exp $
11 CodeDef time Description Time selector
12 CodeDef time Routine <<EOR
16 my $name = $opt->{name};
17 my $val = $opt->{value};
20 if($opt->{time} and $opt->{time_adjust} =~ /([-+]?)(\d+)/) {
25 $now += $sign eq '+' ? $adjust : -$adjust;
30 for(qw/ class style extra /) {
31 my $stag = "select_$_";
32 my $otag = "option_$_";
37 $selapp = " $opt->{$stag}";
38 $optapp = " $opt->{$otag}";
41 $selapp = qq{ $_="$opt->{$stag}"};
42 $optapp = qq{ $_="$opt->{$otag}"};
44 $sel_extra .= $opt->{$stag} ? $selapp : '';
45 $opt_extra .= $opt->{$otag} ? $optapp : '';
48 my @t = localtime($now || time);
50 $t[2]++ if $t[2] < 23;
51 $val = POSIX::strftime("%H00", @t);
55 my $out = qq{<SELECT NAME="$name"$sel_extra>};
58 $out .= '<OPTION VALUE="0"$opt_extra>------</OPTION>';
61 $val = Vend::Form::round_to_fifteen($val);
64 $out .= '<OPTION VALUE="0"$opt_extra>--:--</OPTION>';
67 my $ampm = defined $opt->{ampm} ? $opt->{ampm} : 1;
70 my %special = qw/ 0 midnight 12 noon /;
74 $opt->{minutes} ||= '';
76 if($opt->{minutes} =~ /half/i) {
79 elsif($opt->{minutes} =~ /hourly/i) {
82 elsif($opt->{minutes} =~ /ten/i) {
83 @min = (0,10,20,30,40,50);
85 elsif($opt->{minutes} =~ /[\0,]/) {
86 @min = grep /^\d+$/ && $_ <= 59, split /[\0,\s]+/, $opt->{minutes};
92 $opt->{start_hour} ||= 0;
93 for(qw/start_hour end_hour/) {
94 $opt->{$_} = int(abs($opt->{$_}));
99 $opt->{start_hour} ||= 0;
100 $opt->{end_hour} ||= 23;
102 for my $hr ( $opt->{start_hour} .. $opt->{end_hour} ) {
103 next if defined $opt->{start_hour} and $hr < $opt->{start_hour};
104 next if defined $opt->{end_hour} and $hr > $opt->{end_hour};
105 for my $min ( @min ) {
113 $disp_hour = $hr - 12 unless $hr == 12;
118 if($special{$hr} and $min == 0) {
119 $disp_hour = errmsg($special{$hr});
122 $disp_hour = sprintf("%2d:%02d%s", $disp_hour, $min, $mod);
125 $disp_hour = sprintf("%02d:%02d", $hr, $min);
127 my $time = sprintf "%02d%02d", $hr, $min;
128 $o = sprintf qq{<OPTION VALUE="%s"$opt_extra>%s}, $time, $disp_hour;
129 ($out .= $o, next) unless ! $sel and $val;
130 #::logDebug("prospect=$time actual=$val");
131 $o =~ s/>/ SELECTED>/ && $sel++