diff lib/Benzin/Bugzilla/Bug.pm @ 11:4eb9fdf4efa9

refactoring, non-working bookings
author cin
date Mon, 07 Sep 2015 19:18:21 +0300
parents 14a966369278
children 52b34ea50eff
line wrap: on
line diff
--- a/lib/Benzin/Bugzilla/Bug.pm	Mon Sep 07 01:37:11 2015 +0300
+++ b/lib/Benzin/Bugzilla/Bug.pm	Mon Sep 07 19:18:21 2015 +0300
@@ -45,9 +45,7 @@
 
 use constant { BUG_FIELDS => \@fields };
 
-use IMPL::declare {
-	base    => [ 'IMPL::Object::Fields' => undef ]
-};
+use IMPL::declare { base => [ 'IMPL::Object::Fields' => undef ] };
 use fields @fields;
 
 sub CTOR {
@@ -67,14 +65,25 @@
 sub GetTimeReports {
 	my SELF $this = shift;
 	my $resolution = shift || 0.25;
+	my $span = $resolution * 60;
 
 	my @bookings;
 	my $actual = 0;
 
 	for my $history ( @{ $this->{history} || [] } ) {
-		my $who = $history->{who};
+		my $who     = $history->{who};
 		my $when    = $history->{when};
 		my $changes = $history->{changes};
+		
+		my $minutes = coarsen( $when->minute(), $span );
+		
+		if ($minutes >= 60 ) {
+			$when->add(hours => 1);
+			$minutes -= 60;
+		}
+		$when->set_second(0);
+		$when->set_minute($minutes);
+		
 
 		for my $change ( @{ $changes || [] } ) {
 			if ( $change->{field_name} eq 'work_time' ) {
@@ -86,11 +95,10 @@
 					if ($dt) {
 						push @bookings,
 						  {
-							end       => $who,
-							when      => $when->iso8601(),
+							who       => $who,
+							end      => $when,
 							work_time => $dt,
 							start => $when->clone()->subtract( hours => $dt )
-							  ->iso8601()
 						  };
 						$actual += $dt;
 					}
@@ -99,10 +107,12 @@
 		}
 	}
 
+	my $remaining = coarsen( $this->{remaining_time}, $resolution );
 	return {
-		reports   => \@bookings,
+		report    => \@bookings,
 		actual    => $actual,
-		remaining => coarsen( $this->{remaining_time}, $resolution )
+		remaining => $remaining,
+		estimated => $actual + $remaining
 	};
 }