# returns the development time since the previous version in weeks
# or months
sub development_time {
- my $dates = qx(git log --pretty=format:%ct --summary $since_until);
- my $first_timestamp;
- foreach my $line ( split $/, $dates ) {
- next unless $line;
- next unless $line =~ /^\d+$/;
- $first_timestamp = $line;
- }
+ my $first_timestamp = qx(git log -1 --pretty=format:%ct --summary $since);
+ my $last_timestamp = qx(git log -1 --pretty=format:%ct --summary $until);
die "Missing first timestamp" unless $first_timestamp;
+ die "Missing last timestamp" unless $last_timestamp;
- my $now = localtime;
- my $then = localtime($first_timestamp);
- my $seconds = $now - $then;
- my $weeks = ceil( $seconds / ONE_WEEK );
- my $months = ceil( $seconds / ONE_MONTH );
+ my $seconds = localtime($last_timestamp) - localtime($first_timestamp);
+ my $weeks = _round( $seconds / ONE_WEEK );
+ my $months = _round( $seconds / ONE_MONTH );
my $development_time;
if ( $months < 2 ) {
}
}
+sub _round {
+ my $val = shift;
+
+ my $int = int $val;
+ my $remainder = $val - $int;
+
+ return $remainder >= 0.5 ? $int + 1 : $int;
+}
+
# returns the number of changed lines and files since the previous
# version
sub changes_files {