moved to DateTime (from Date::Manip), and using ISO8601 timestamps
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 23 Sep 2005 15:44:27 +0000 (15:44 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 23 Sep 2005 15:44:27 +0000 (15:44 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@1860 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/reporter/report_base.example.xml
Open-ILS/src/reporter/reporter.schema-gen.pl

index 300fb83..52b4b98 100644 (file)
@@ -22,8 +22,8 @@
 
                        <partition>
                                <field>said_when</field>
-                               <!-- Valid options:  month, year, woy (week of year), doy (day of year) -->
-                               <chunk>month</chunk>
+                               <!-- Valid options:  years, months, weeks, days, hours, minutes, seconds  -->
+                               <chunk>months</chunk>
                                <start>2005-09-01</start>
                                <end>2005-12-31</end>
                        </partition>
index d9f4bc9..f6b4c74 100755 (executable)
@@ -1,7 +1,14 @@
 #!/usr/bin/perl
 use strict; use warnings;
 use XML::LibXML;
-use Date::Manip;
+use OpenSRF::Utils qw/:datetime/;
+use DateTime;
+use DateTime::Duration;
+use DateTime::Format::ISO8601;
+
+my $dt_parser = DateTime::Format::ISO8601->new;
+my $log = 'OpenSRF::Utils::Logger';
+
 
 my %chunkmap =
        (       doy => '%j',
@@ -64,22 +71,34 @@ for my $table ($doc->findnodes('/reporter/tables/table')) {
 
                $field = $field->textContent;
                $chunk = $chunk->textContent;
-               $start = UnixDate(ParseDate($start->textContent),$chunkmap{$chunk});
-               $end = UnixDate(ParseDate($end->textContent),$chunkmap{$chunk});
+               $start = $dt_parser->parse_datetime( $start->textContent );
+               $end = $dt_parser->parse_datetime( $end->textContent );
+
+
+               while ( $start->epoch < $end->epoch ) {
+
+                       my $chunk_end = $start->clone;
+                       $chunk_end->add( DateTime::Duration->new( $chunk => 1 ) );
+                       $chunk_end->subtract( DateTime::Duration->new( seconds => 1 ) );
+
+                       my $tpart = $start->epoch;
+
+                       my $where = "BETWEEN '".$start->strftime('%FT%T%z').
+                                       "' AND '".$chunk_end->strftime('%FT%T%z')."'";
 
-               for my $tpart ( $start .. $end ) {
                        print   "CREATE TABLE ${tname}_${chunk}_$tpart () INHERITS ($tname);\n";
                        print   "ALTER TABLE ${tname}_${chunk}_$tpart\n".
                                "\tADD CONSTRAINT \"${tname}_${chunk}_${tpart}_test\"\n".
-                               "\tCHECK (EXTRACT('$chunk' FROM $field) = $tpart);\n";
+                               "\tCHECK ($field $where);\n";
                        print   "CREATE RULE \"${tname}_${chunk}_${tpart}_ins_rule\" AS\n\tON INSERT TO ".
-                               "$tname \n\tWHERE EXTRACT('$chunk' FROM NEW.$field) = $tpart ".
+                               "$tname \n\tWHERE NEW.$field $where".
                                "\n\tDO INSTEAD INSERT INTO ${tname}_${chunk}_$tpart VALUES (NEW.*);\n";
                        for my $i (@indexed) {
                                print   "CREATE INDEX \"${tname}_${chunk}_${tpart}_$$i[0]_idx\" ".
                                        "ON ${tname}_${chunk}_$tpart USING $$i[1] ($$i[0]);\n";
                        }
                        print "\n";
+                       $start->add( DateTime::Duration->new( $chunk => 1 ) );
                }
        } else {
                for my $i (@indexed) {