move use statements to handler.pl, do not show 1/1/70 for new birthdates, and improve...
authorjeff <jeff>
Fri, 15 Dec 2006 05:29:48 +0000 (05:29 +0000)
committerjeff <jeff>
Fri, 15 Dec 2006 05:29:48 +0000 (05:29 +0000)
htetc/handler.pl
httemplate/edit/process/cust_main.cgi
httemplate/elements/tr-input-date-field.html
httemplate/view/cust_main/misc.html

index cce39be..0da7a80 100644 (file)
@@ -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;
index 752bc95..38821c3 100755 (executable)
 %  );
 %}
 %
-%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') )
index 1624df0..2320a95 100644 (file)
@@ -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);
 }
index 121c052..9528db2 100644 (file)
   </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>
 
 % }