diff options
author | jeff <jeff> | 2006-12-15 05:29:48 +0000 |
---|---|---|
committer | jeff <jeff> | 2006-12-15 05:29:48 +0000 |
commit | 02b9c53fb85b0a87d959e140dc30ae21cccb0902 (patch) | |
tree | 56d1edfd2ee7a2f92fe830b8e55a6db84d214b0f | |
parent | ba1f19e48ec2f2ac293b07a41042de59e744db1e (diff) |
move use statements to handler.pl, do not show 1/1/70 for new birthdates, and improve error handling
-rw-r--r-- | htetc/handler.pl | 1 | ||||
-rwxr-xr-x | httemplate/edit/process/cust_main.cgi | 12 | ||||
-rw-r--r-- | httemplate/elements/tr-input-date-field.html | 5 | ||||
-rw-r--r-- | httemplate/view/cust_main/misc.html | 4 |
4 files changed, 14 insertions, 8 deletions
diff --git a/htetc/handler.pl b/htetc/handler.pl index cce39be1f..0da7a80fe 100644 --- a/htetc/handler.pl +++ b/htetc/handler.pl @@ -97,6 +97,7 @@ sub handler use Date::Parse; use Time::Local; use Time::Duration; + use DateTime; use DateTime::Format::Strptime; use Lingua::EN::Inflect qw(PL); use Tie::IxHash; diff --git a/httemplate/edit/process/cust_main.cgi b/httemplate/edit/process/cust_main.cgi index 752bc9502..38821c36a 100755 --- a/httemplate/edit/process/cust_main.cgi +++ b/httemplate/edit/process/cust_main.cgi @@ -56,13 +56,21 @@ % ); %} % -%if ( $cgi->param('birthdate') && $cgi->param('birthdate') =~ /^([ 0-9\-\/]{0,10})$/ ) { +%if ( $cgi->param('birthdate') && $cgi->param('birthdate') =~ /^([ 0-9\-\/]{0,10})$/) { % my $conf = new FS::Conf; % my $format = $conf->config('date_format') || "%m/%d/%Y"; % my $parser = DateTime::Format::Strptime->new(pattern => $format, % time_zone => 'floating', % ); -% $new->setfield('birthdate', $parser->parse_datetime($1)->epoch); +% my $dt = $parser->parse_datetime($1); +% if ($dt) { +% $new->setfield('birthdate', $dt->epoch); +% $cgi->param('birthdate', $dt->epoch); +% } else { +%# $error ||= $cgi->param('birthdate') . " is an invalid birthdate:" . $parser->errmsg; +% $error ||= "Invalid birthdate: " . $cgi->param('birthdate') . "."; +% $cgi->param('birthdate', ''); +% } %} % %$new->setfield('paid', $cgi->param('paid') ) diff --git a/httemplate/elements/tr-input-date-field.html b/httemplate/elements/tr-input-date-field.html index 1624df05c..2320a9552 100644 --- a/httemplate/elements/tr-input-date-field.html +++ b/httemplate/elements/tr-input-date-field.html @@ -29,10 +29,9 @@ $format = "%m/%d/%Y" unless $format; $label = $name unless $label; if ($usedatetime) { - eval "use DateTime;"; - die $@ if $@; my $dt = DateTime->from_epoch(epoch => $value, time_zone => 'floating'); - $value = $dt->strftime($format); + $value = $dt->strftime($format) + unless $value eq ''; }else{ $value = time2str($format, $value); } diff --git a/httemplate/view/cust_main/misc.html b/httemplate/view/cust_main/misc.html index 121c0522a..9528db243 100644 --- a/httemplate/view/cust_main/misc.html +++ b/httemplate/view/cust_main/misc.html @@ -97,15 +97,13 @@ </TR> % if ( $conf->exists('cust_main-enable_birthdate') ) { -% eval "use DateTime;"; -% die $@ if $@; % my $dt = DateTime->from_epoch(epoch => $cust_main->birthdate, % time_zone=>'floating', % ); <TR> <TD ALIGN="right">Date of Birth</TD> - <TD BGCOLOR="#ffffff"><% $cust_main->birthdate ? $dt->strftime($date_format) : '' %></TD> + <TD BGCOLOR="#ffffff"><% $cust_main->birthdate ne '' ? $dt->strftime($date_format) : '' %></TD> </TR> % } |