Allow closing tasks not started today with -D
[infodrom.org/service.infodrom.org] / src / InfoCon / stempel / stempel
index 9c1c92f..7bb7bbc 100755 (executable)
@@ -164,7 +164,9 @@ sub hdiff
 
 sub close_task
 {
+    my $really = shift;
     my ($d_sec,$d_min,$d_hour,$d_mday,$d_mon,$d_year,$d_wday,$d_isdst) = localtime();
+    my $today = 1;
 
     my $query = q{SELECT oid,start FROM stempel WHERE stop IS NULL};
     my $sth = $dbh->prepare ($query);
@@ -174,12 +176,18 @@ sub close_task
            my @d = split(/-/, $arr[0]);
 
            if ($d[0] != $d_year+1900 || $d[1] != $d_mon+1 || $d[2] != $d_mday) {
-               printf "Task not started today, aborting.\n";
-               next;
+               if ($really) {
+                   printf "Task not started today.\n";
+                   $today = 0;
+               } else {
+                   printf "Task not started today, aborting, use -D if this is intentional.\n";
+                   next;
+               }
            }
 
            my @t = split(/:/, $arr[1]);
            my $int = quarter(hdiff($t[0], $t[1], $d_hour, $d_min));
+           $int += 24 * 60 unless $today;
 
            $query = sprintf('UPDATE stempel SET stop=now(),time=%d WHERE oid = %d',
                             $int, $row->{oid});
@@ -216,6 +224,7 @@ sub list_open
     my $exit = shift;
     my ($d_sec,$d_min,$d_hour,$d_mday,$d_mon,$d_year,$d_wday,$d_isdst) = localtime();
     my $query = q{SELECT customer,start,task FROM stempel WHERE time IS NULL ORDER BY start,customer};
+    my $today = 1;
 
     my $sth = $dbh->prepare ($query);
     if ($sth && $sth->execute > 0) {
@@ -226,12 +235,14 @@ sub list_open
 
            if ($d[0] != $d_year+1900 || $d[1] != $d_mon+1 || $d[2] != $d_mday) {
                printf "Task not started today.\n";
-               next if $exit eq 1;
+               $today = 0;
+               next if defined $exit && $exit eq 1;
            }
 
            my @t = split(/:/, $arr[1]);
            my $time = sprintf('%02d:%02d', $t[0], $t[1]);
            my $int = quarter(hdiff($t[0], $t[1], $d_hour, $d_min));
+           $int += 24 * 60 unless $today;
 
            printf "%-15s  %s %s (%s)  %s\n", $row->{customer}, $day, $time, min2hour($int), $row->{task};
        }
@@ -345,6 +356,7 @@ stempel  Copyright (c) 2007,8  Martin Schulze <joey\@infodrom.org>
     --close time   close open task
     --help         this text
     --end|-d       terminate task
+    -D             terminate task not started today
     --delete       delete open task
     --reopen       re-open last task
     --task         alter task content
@@ -364,6 +376,7 @@ my %options = ('list:s' => \$opt_list,
               'reopen' => \&reopen_task,
               'task|t' => \&alter_task,
               'terminate|end|d' => \&close_task,
+              'D' => sub {close_task(1);},
               );
 GetOptions %options;