#!/usr/bin/perl # The Missing Textutils, Ondrej Bojar, obo@cuni.cz # http://www.cuni.cz/~obo/textutils # # 'hoursum' expects every input line to be in the format # "any-prefix-followed-by-a-colon: hour.min-hour.min hour.min-hour.min" # # All the given time intervals are summed and the total number of hours and # minutes spent on the project is appended. # # $Id: hoursum,v 1.4 2005/10/10 07:33:49 bojar Exp $ while (<>) { print; chomp; ($date, $times) = split /\s*:\s*/, $_, 2; foreach $pair (split /\s+/, $times) { ($from, $to) = split /-/, $pair; if (!$from || !$to) { print "# Skipping unpaired $pair\n"; } else { ($fromh, $fromm) = split /[:.]/, $from; ($toh, $tom) = split /[:.]/, $to; if ($toh < $fromh) { # Assuming overnight! $toh += 24; } if ($tom < $fromm) { $tom += 60; $toh -= 1; } $len = ($toh - $fromh) * 60 + ($tom - $fromm); $total += $len; } } } $toth = int($total / 60); $totm = $total - $toth*60; printf "Total %i.%02i\n", $toth,$totm;