From 931cb703bf4f9a33fc0521218e9c1c912974da2b Mon Sep 17 00:00:00 2001 From: Joey Schulze Date: Tue, 12 Aug 2008 17:37:26 +0000 Subject: [PATCH] Support month specification for task lists --- src/InfoCon/stempel/stempel | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/InfoCon/stempel/stempel b/src/InfoCon/stempel/stempel index 97903a6..b5e0646 100755 --- a/src/InfoCon/stempel/stempel +++ b/src/InfoCon/stempel/stempel @@ -171,10 +171,26 @@ sub list_open exit 0; } -sub list_all +sub list { - # my $query = q{SELECT customer,sum(time) FROM stempel GROUP BY customer ORDER BY customer}; - my $query = q{SELECT start,customer,time,task FROM stempel WHERE time IS NOT NULL ORDER BY customer,start}; + my $month = shift; + my ($d_sec,$d_min,$d_hour,$d_mday,$d_mon,$d_year,$d_wday,$d_isdst) = localtime(); + my $query = q{SELECT start,customer,time,task FROM stempel WHERE time IS NOT NULL }; + + if ($month =~ /^(\d{4})-?(\d\d?)$/) { + my $pivot = $1 . '-' . $2 . '-01'; + $query .= "AND start >= '$pivot' AND start <= '$pivot'::date + interval '1 month' "; + } elsif ($month =~ /^(\d{4})$/) { + my $pivot = $1 . '-01-01'; + $query .= "AND start >= '$pivot' AND start <= '$pivot'::date + interval '1 year' "; + } elsif ($month =~ /^(\d\d?)$/) { + my $pivot = $d_year+1900 . '-' . $1 . '-01'; + $query .= "AND start >= '$pivot' AND start <= '$pivot'::date + interval '1 month' "; + } elsif ($month !~ /^all$/) { + my $pivot = sprintf('%04d-%02d-01', $d_year+1900, $d_mon+1); + $query .= "AND start >= '$pivot' AND start <= '$pivot'::date + interval '1 month' "; + } + $query .= "ORDER BY customer,start"; my $sth = $dbh->prepare ($query); @@ -216,7 +232,7 @@ sub help { print <<"END"; stempel Copyright (c) 2007,8 Martin Schulze - --list list all + --list [month] list month [default=current|all] --open list open --close time close open task --help this text @@ -226,7 +242,8 @@ END } my $opt_close = undef; -my %options = ('list' => \&list_all, +my $opt_list = undef; +my %options = ('list:s' => \$opt_list, 'open' => \&list_open, 'help' => \&help, 'close=i' => \$opt_close, @@ -236,6 +253,8 @@ GetOptions %options; if ($opt_close) { late_close_task $opt_close; +} elsif (defined $opt_list) { + list $opt_list; } else { toggle_task; } -- 2.20.1