Mercurial > pub > buggler
diff lib/Benzin/Bugzilla/XmlWriter.pm @ 12:52b34ea50eff default tip
sync: work time projection doesn't seem to be working anyway
author | cin |
---|---|
date | Sun, 13 Sep 2015 19:37:16 +0300 |
parents | 4eb9fdf4efa9 |
children |
line wrap: on
line diff
--- a/lib/Benzin/Bugzilla/XmlWriter.pm Mon Sep 07 19:18:21 2015 +0300 +++ b/lib/Benzin/Bugzilla/XmlWriter.pm Sun Sep 13 19:37:16 2015 +0300 @@ -9,12 +9,14 @@ -default => 'WriteValue' ); +use IMPL::lang qw(coarsen coarsen_dt is); use IMPL::Const qw(:prop); use IMPL::declare { require => { XMLWriter => 'XML::Writer', Bug => 'Benzin::Bugzilla::Bug', BugComment => 'Benzin::Bugzilla::BugComment', + Duration => 'DateTime::Duration', }, base => [ 'IMPL::Transform' => sub { %Transform } @@ -42,9 +44,55 @@ $writer->xmlDecl("UTF-8"); $writer->startTag("bugzilla"); + my %timesheets; + foreach my $bug (@$bugs) { $writer->startTag("bug"); $this->WriteBug($bug); + + if ( $this->timereports ) { + my $time = $bug->GetTimeReports( $this->timeresolution ); + + my $prevReportDate = $bug->{creation_time}; + + foreach my $item ( @{ $time->{report} || [] } ) { + $timesheets{ $item->{who} }{bugs}{ $bug->{id} }{work} += + $item->{work_time}; + $timesheets{ $item->{who} }{bugs}{ $bug->{id} }{remaining} = + $time->{remaining}; + + $timesheets{ $item->{who} }{start} = $prevReportDate + unless $timesheets{ $item->{who} }{start} + and $timesheets{ $item->{who} }{start} <= $prevReportDate; + $timesheets{ $item->{who} }{end} = $item->{when} + unless $timesheets{ $item->{who} }{end} + and $timesheets{ $item->{who} }{end} >= $item->{when}; + + $prevReportDate = $item->{when}; + } + + $this->WriteElement( 'time', $time ); + } + + $writer->endTag(); + } + + while ( my ( $who, $sheet ) = each %timesheets ) { + + $writer->startTag( + 'timesheet', + resource => $who, + start => $this->FormatTJ3DateTime( $sheet->{start} ), + end => $this->FormatTJ3DateTime( $sheet->{end} ) + ); + + while ( my ( $bug, $info ) = each %{ $sheet->{bugs} } ) { + $writer->startTag( 'bug', id => $bug ); + $this->WriteElement( 'work', $info->{work} ); + $this->WriteElement( 'remaining', $info->{remaining} ); + $writer->endTag(); + } + $writer->endTag(); } @@ -61,9 +109,6 @@ next unless $value->{$field}; $this->WriteElement( $field, $value->{$field} ); } - $this->WriteElement( 'time', - $value->GetTimeReports( $this->timeresolution ) ) - if $this->timereports; } sub WriteBugComment { @@ -113,9 +158,22 @@ sub WriteTJ3DateTime { my SELF $this = shift; - my $value = shift; + my $value = shift; + + $this->_writer->characters( $this->FormatTJ3DateTime($value) ) + if defined $value; +} - $this->_writer->characters($value->strftime('%F-%T')) if defined $value; +sub FormatTJ3DateTime { + my SELF $this = shift; + my $value = shift; + + my $duration = + is( $this->timeresolution, Duration ) + ? $this->timeresolution + : Duration->new( %{ $this->timeresolution } ); + + return coarsen_dt( $value, $duration )->strftime('%F-%T'); } 1;