From 02b9c53fb85b0a87d959e140dc30ae21cccb0902 Mon Sep 17 00:00:00 2001 From: jeff Date: Fri, 15 Dec 2006 05:29:48 +0000 Subject: [PATCH] move use statements to handler.pl, do not show 1/1/70 for new birthdates, and improve error handling --- htetc/handler.pl | 1 + httemplate/edit/process/cust_main.cgi | 12 ++++++++++-- httemplate/elements/tr-input-date-field.html | 5 ++--- 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 @@ % if ( $conf->exists('cust_main-enable_birthdate') ) { -% eval "use DateTime;"; -% die $@ if $@; % my $dt = DateTime->from_epoch(epoch => $cust_main->birthdate, % time_zone=>'floating', % ); Date of Birth - <% $cust_main->birthdate ? $dt->strftime($date_format) : '' %> + <% $cust_main->birthdate ne '' ? $dt->strftime($date_format) : '' %> % } -- 2.11.0