Move back task by n minutes via -b parameter
authorJoey Schulze <joey@infodrom.org>
Wed, 15 May 2013 13:22:37 +0000 (13:22 +0000)
committerJoey Schulze <joey@infodrom.org>
Wed, 15 May 2013 13:22:37 +0000 (13:22 +0000)
src/InfoCon/stempel/stempel

index 8754200..17c5400 100755 (executable)
@@ -2,7 +2,7 @@
 
 #  Time Tracker
 #
-#  Copyright (c) 2007,8  Martin Schulze <joey@infodrom.org>
+#  Copyright (c) 2007,8,13  Martin Schulze <joey@infodrom.org>
 #
 #  This program is free software; you can redistribute it and/or modify
 #  it under the terms of the GNU General Public License as published by
@@ -29,10 +29,7 @@ my $table = "stempel";
 my $engine = "dbi:Pg:dbname=infocon";
 
 my $dbh = DBI->connect($engine);
-if (!$dbh) {
-    print "Access to database denied!\n";
-    return 1;
-}
+die "Access to database denied!\n" unless $dbh;
 $dbh->do("SET DateStyle = 'ISO'");
 
 sub min2hour
@@ -236,6 +233,16 @@ sub late_close_task
     $dbh->do($query);
 }
 
+sub move_task
+{
+    my $minutes = shift;
+
+    return unless is_open;
+
+    my $query = sprintf("UPDATE stempel SET start = start - interval '%d minutes' WHERE stop IS NULL", $minutes);
+    $dbh->do($query);
+}
+
 sub alter_task
 {
     return unless is_open;
@@ -259,6 +266,7 @@ sub help
     print <<"END";
 stempel  Copyright (c) 2007,8  Martin Schulze <joey\@infodrom.org>
     --list [month] list month [default=current|all]
+    --back n       move start of current task back by n minutes
     --open         list open
     --close time   close open task
     --help         this text
@@ -271,7 +279,9 @@ END
 
 my $opt_close = undef;
 my $opt_list = undef;
+my $opt_back = undef;
 my %options = ('list:s' => \$opt_list,
+              'back=i' => \$opt_back,
               'open' => \&list_open,
               'help' => \&help,
               'close=i' => \$opt_close,
@@ -285,6 +295,8 @@ if ($opt_close) {
     late_close_task $opt_close;
 } elsif (defined $opt_list) {
     list $opt_list;
+} elsif (defined $opt_back) {
+    move_task $opt_back;
 } else {
     toggle_task;
 }