]> git.mjollnir.org Git - tks.git/commitdiff
Add a method to load timesheet information in a simpler format than yaml.
authorNigel McNie <nigel@catalyst.net.nz>
Mon, 26 May 2008 08:55:40 +0000 (20:55 +1200)
committerNigel McNie <nigel@catalyst.net.nz>
Mon, 26 May 2008 08:55:40 +0000 (20:55 +1200)
The format looks like:

date
WR   time   description
WR   time   description
...

date
WR   time   description
WR   time   description
...

lib/WRMS.pm

index c360b2e36ac0d16ea4cdaf69f70c03047fd80e30..077755bfc2dfe3d76ecce53926e9bd4b19185005 100644 (file)
@@ -226,6 +226,50 @@ sub parse_page {
     croak q{Couldn't parse '} . $self->{mech}->uri() . q{'};
 }
 
+sub load_timesheet_file {
+    my ($file) = @_;
+
+    my ($DATE, $WR, $TIME, $DESC);
+    my @result;
+
+    open(FH, "<$file");
+    while (my $line = <FH>) {
+        # Strip comments
+        next if $line =~ m/^ \s* \#/xms;
+
+        if (
+            $line =~ m{^ ( \d+ / \d+ / \d\d (\d\d)? ) }xms or  # dd/mm/yy or dd/mm/yyyy
+            $line =~ m{^ ( \d{4} / \d+ / \d+ ) }xms            # yyyy/mm/dd
+        ) {
+            $DATE = $1;
+            next;
+        }
+
+        if ( $line =~ m{\A
+                ( \d+ | [a-zA-Z0-9_-]+ ) \s+   # Work request number OR alias
+                ( \d+ | \d* \. \d+ ) \s+       # Time in integer or decibal
+                ( .* ) \z}xms ) {
+            $WR   = $1;
+            $TIME = $2;
+            $DESC = $3;
+            chomp $DESC;
+
+            my $row = {
+                'wr'      => $WR,
+                'date'    => $DATE,
+                'comment' => $DESC,
+                'time'    => $TIME,
+            };
+
+            push @result, $row;
+        }
+
+    }
+    close FH;
+
+    return @result;
+}
+
 sub last_error {
     my ($self) = @_;