switch birthdate to DateTime
authorjeff <jeff>
Thu, 16 Nov 2006 06:20:38 +0000 (06:20 +0000)
committerjeff <jeff>
Thu, 16 Nov 2006 06:20:38 +0000 (06:20 +0000)
httemplate/edit/cust_main.cgi
httemplate/edit/process/cust_main.cgi
httemplate/elements/tr-input-date-field.html
httemplate/view/cust_main/misc.html

index 57d4dac..daddd8e 100755 (executable)
               'birthdate',
               $cust_main->birthdate,
               'Date of Birth',
-              $conf->config('date_format') || "%m/%d/%Y")
+              $conf->config('date_format') || "%m/%d/%Y",
+              1)
   %>
 
   </TABLE>
index 33f7bb8..d5d127b 100755 (executable)
 %}
 %
 %if ( $cgi->param('birthdate') && $cgi->param('birthdate') =~ /^([ 0-9\-\/]{0,10})$/ ) {
-%  $new->setfield('birthdate', str2time($1));
+%  eval "use DateTime::Format::Strptime;";
+%  die $@ if $@;
+%  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);
 %}
 %
 %$new->setfield('paid', $cgi->param('paid') )
index 0618fc9..1624df0 100644 (file)
@@ -7,7 +7,7 @@
 <TR>
   <TD ALIGN="right"><% $label %></TD>
   <TD>
-    <INPUT TYPE="text" NAME="<% $name %>" ID="<% $name %>_text" VALUE="<% ($value eq '') ? '' : time2str($format, $value) %>">
+    <INPUT TYPE="text" NAME="<% $name %>" ID="<% $name %>_text" VALUE="<% $value %>">
     <IMG SRC="../images/calendar.png" ID="<% $name  %>_button" STYLE="cursor: pointer" TITLE="Select date">
   </TD>
 </TR>
 
 
 <%init>
-my($name, $value, $label, $format) = @_;
+my($name, $value, $label, $format, $usedatetime) = @_;
 
 $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);
+}else{
+  $value = time2str($format, $value);
+}
+
 </%init>
 
index 414ef44..121c052 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 ? time2str($date_format, $cust_main->birthdate) : '' %></TD>
+    <TD BGCOLOR="#ffffff"><% $cust_main->birthdate ? $dt->strftime($date_format) : '' %></TD>
   </TR>
 
 % }