fix daily sales/credits/receipts summary vs DST boundaries, RT#26199
[freeside.git] / FS / FS / Report / Table / Daily.pm
index 5bbd6e4..c668016 100644 (file)
@@ -3,7 +3,9 @@ package FS::Report::Table::Daily;
 use strict;
 use vars qw( @ISA );
 use FS::Report::Table;
-use Time::Local qw( timelocal );
+use FS::Conf;
+use Time::Local qw( timelocal timelocal_nocheck ); # eventually replace with DateTime
+use Date::Format qw( time2str );
 
 @ISA = qw( FS::Report::Table );
 
@@ -58,19 +60,21 @@ sub data {
   my $sdate = timelocal(0,0,0,$sday,$smonth-1,$syear);
   my $edate = timelocal(0,0,0,$eday,$emonth-1,$eyear);
 
-  warn "daily range $sdate $edate\n";
+  my $conf = FS::Conf->new;
+  my $date_format = $conf->config('date_format') || '%d/%m/%Y';
+
+  #warn "daily range $sdate $edate\n";
 
   # XXX: use date_format config for the labels since we have day in the labels now?
-  # XXX: leap seconds / DST 
   while ( $sdate < $edate ) {
-    my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($sdate);
-    $mon++;
-    $year += 1900;
-    warn "label=$mday/$mon/$year\n";
-    push @{$data{label}}, "$mday/$mon/$year";
+    push @{$data{label}}, time2str($date_format, $sdate);
 
     my $speriod = $sdate;
-    $sdate += 86400;
+
+    #ala part_pkg->add_freq, to deal with local DST.  DateTime also a good idea
+    my ($mday,$mon,$year) = (localtime($sdate) )[3,4,5];
+    $sdate = timelocal_nocheck(0,0,0,$mday+1,$mon,$year);
+
     my $eperiod = $sdate;
 
     push @{$data{speriod}}, $speriod;