more accurate calculation of package start delays, #20686
[freeside.git] / FS / FS / part_pkg.pm
index 15c29c4..9e3b67e 100644 (file)
@@ -5,7 +5,8 @@ use strict;
 use vars qw( %plans $DEBUG $setup_hack $skip_pkg_svc_hack );
 use Carp qw(carp cluck confess);
 use Scalar::Util qw( blessed );
-use Time::Local qw( timelocal timelocal_nocheck );
+use DateTime;
+use Time::Local qw( timelocal timelocal_nocheck ); # eventually replace with DateTime
 use Tie::IxHash;
 use FS::Conf;
 use FS::Record qw( qsearch qsearchs dbh dbdef );
@@ -1089,32 +1090,16 @@ sub can_discount { 0; }
 # whether the plan allows changing the start date
 sub can_start_date { 1; }
   
-# the default start date; takes an FS::cust_main as an argument
-sub default_start_date {
+# the delay start date if present
+sub delay_start_date {
   my $self = shift;
-  my $cust_main = shift;
-  my $conf = FS::Conf->new;
 
-  if ( $self->delay_start ) {
-    my $delay = $self->delay_start;
-    
-    my ($mday,$mon,$year) = (localtime(time))[3,4,5];
-    my $start_date = timelocal(0,0,0,$mday,$mon,$year) + 86400 * $delay;
-    return $start_date;
-
-  } elsif ( $conf->exists('order_pkg-no_start_date') ) {
-
-    return '';
+  my $delay = $self->delay_start or return '';
 
-  } elsif ( $cust_main ) {
-    
-    return $cust_main->next_bill_date;
-  
-  } else {
-    
-    return '';
-
-  }
+  # avoid timelocal silliness  
+  my $dt = DateTime->today(time_zone => 'local');
+  $dt->add(days => $delay);
+  $dt->epoch;
 }
 
 sub can_currency_exchange { 0; }