From: Nigel McNie <nigel@catalyst.net.nz>
Date: Tue, 3 Jun 2008 23:10:46 +0000 (+1200)
Subject: If a line hasn't got a finishing time yet, print an error and exit.
X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=a4daffe14fd9755beea0eaf8b8450eb9e5199342;p=tks.git

If a line hasn't got a finishing time yet, print an error and exit.

Make sure that the line_needs_closing flag is set to 0 correctly at all times when we know we've done the closing time for it.
---

diff --git a/tks.pl b/tks.pl
index 1979166..6ed5c57 100755
--- a/tks.pl
+++ b/tks.pl
@@ -164,6 +164,17 @@ sub load_timesheet_file {
         }
     }
 
+    foreach my $date ( keys %{$result} ) {
+        my $found_error = 0;
+        if ( my @errors = grep { $_->{needs_closing_time} } @{$result->{$date}} ) {
+            $found_error = 1;
+            foreach my $error ( @errors ) {
+                print "Error on line ", $error->{linenumber}, ": no closing time found\n";
+            }
+        }
+        exit 1 if $found_error;
+    }
+
     return $result;
 }
 
@@ -224,6 +235,7 @@ sub parse_line {
         }
         else {
             $lastline->{time} = (convert_to_minutes($time) - $lastline->{time}) / 60 if $lastline->{needs_closing_time};
+            $lastline->{needs_closing_time} = 0;
 
             # We have a starting date only - need to wait for the next line
             $result->{needs_closing_time} = 1;