[freeside-commits] freeside/rt/share/html/Search Results.csv, 1.1.2.3, 1.1.2.4 Results.xls, 1.1.2.3, 1.1.2.4

Mark Wells mark at wavetail.420.am
Sat Apr 30 13:29:05 PDT 2011


Update of /home/cvs/cvsroot/freeside/rt/share/html/Search
In directory wavetail.420.am:/tmp/cvs-serv19927/share/html/Search

Modified Files:
      Tag: FREESIDE_2_1_BRANCH
	Results.csv Results.xls 
Log Message:
Excel date formatting, #12659

Index: Results.csv
===================================================================
RCS file: /home/cvs/cvsroot/freeside/rt/share/html/Search/Results.csv,v
retrieving revision 1.1.2.3
retrieving revision 1.1.2.4
diff -u -w -d -r1.1.2.3 -r1.1.2.4
--- Results.csv	22 Apr 2011 02:24:05 -0000	1.1.2.3
+++ Results.csv	30 Apr 2011 20:29:03 -0000	1.1.2.4
@@ -81,6 +81,7 @@
           Format        => $Format,
           WriteHeader   => $WriteHeader,
           WriteRow      => $WriteRow,
+          FormatDate    => sub { $_[0]->AsString(Format => 'ISO') },
 );
 
 $m->flush_buffer;

Index: Results.xls
===================================================================
RCS file: /home/cvs/cvsroot/freeside/rt/share/html/Search/Results.xls,v
retrieving revision 1.1.2.3
retrieving revision 1.1.2.4
diff -u -w -d -r1.1.2.3 -r1.1.2.4
--- Results.xls	22 Apr 2011 02:24:05 -0000	1.1.2.3
+++ Results.xls	30 Apr 2011 20:29:03 -0000	1.1.2.4
@@ -55,6 +55,7 @@
 
 use Spreadsheet::WriteExcel;
 use List::Util qw( max );
+use Date::Format qw( time2str );
 
 $r->content_type('application/vnd.ms-excel');
 $r->header_out('Content-Disposition' => 'attachment;filename="Results.xls"');
@@ -69,6 +70,11 @@
     color   =>  'black',
     size    =>  10,
 );
+my $date_format = $workbook->add_format(
+    color   => 'black',
+    size    => 10,
+    num_format => 'YYYY-MM-DD', #configurable?
+);
 my $title_format = $workbook->add_format(
     color   => 'black',
     size    => 10,
@@ -97,12 +103,26 @@
         # record row/column sizes
         $height = max( $height, scalar(@lines) );
         $width[$item] = max( $width[$item], map {length} @lines );
+
+        if ( scalar(@lines) == 1 and 
+            $lines[0] =~ /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}$/ ) {
+
+            $worksheet->write_date_time($row, $item, $lines[0], $date_format);
+            next;
+        }
+
         $worksheet->write($row, $item, join("\n", @lines), $default_format);
     }
     $worksheet->set_row($row, $height * 14);
     $row++;
 };
 
+my $FormatDate = sub {
+    my $DateObj = shift;
+    return '' if $DateObj->Unix == 0;
+    return time2str('%Y-%m-%dT%H:%M', $DateObj->Unix);
+};
+
 # Write everything to the worksheet
 $m->comp('Elements/ResultsStructuredView',
           Query         => $Query,
@@ -111,6 +131,7 @@
           Format        => $Format,
           WriteHeader   => $WriteHeader,
           WriteRow      => $WriteRow,
+          FormatDate    => $FormatDate,
 );
 
 # Set column widths



More information about the freeside-commits mailing list