diff --git a/phosta.pl b/phosta.pl

index 0f80acfa13c46199617fc978fe38d3c10a917d45..3a0aad6111cf906046810c3e4d0afa594bedc5e0 100755

--- a/phosta.pl

+++ b/phosta.pl

@@ -27,13 +27,14 @@

# read commandline switches

our $opt_D=getcwd . "/photo_stats.db";

our $opt_p='';

+our $opt_t='';

our $opt_c=0;

our $opt_s='';

our $opt_g='';

getconfig($configfile);

-getopts('cp:g:s:D:') or die "Invalid parameters provided! See 'phosta --help' for more details.";

+getopts('cp:g:s:t:D:') or die "Invalid parameters provided! See 'phosta --help' for more details.";

validate() or die "Invalid parameters provided! See 'phosta --help' for more details.";

my $dsn = "DBI:SQLite:dbname=$opt_D";

@@ -61,6 +62,8 @@ foreach (split (/,/, $opt_s))

{

if ( ! ($_ ~~ @select_params) ) { return 0; }

}

+

+ if ($opt_t ne '' && $opt_t !~ /^([0-9]{8}){0,1}\-([0-9]{8}){0,1}$/) { return 0; }

return 1;

}

@@ -128,6 +131,7 @@

my $fieldlist = '';

my $grouplist = '';

my $orderlist = '';

+ my $wherelist = '';

given ($grouping)

{

when ('month')

@@ -150,7 +154,7 @@

if ($selected ne '')

{

$fieldlist = $fieldlist . $selected . ', ';

- $grouplist = $grouplist . ($grouplist ne '' ? ',' : '') . $selected;

+ $grouplist .= ($grouplist ne '' ? ',' : '') . $selected;

}

if ($selected ne '')

@@ -163,16 +167,30 @@ {

$orderlist = $orderlist . ' 1 DESC,';

$lastcolumn++;

}

- $orderlist = $orderlist . " $lastcolumn DESC";

+ $orderlist .= " $lastcolumn DESC";

}

elsif ($grouping ne '')

{

$orderlist = 'ORDER BY 1 DESC';

}

- if ( $grouplist ne '' ) { $grouplist = 'GROUP BY '. $grouplist; }

+ if ($opt_t ne '')

+ {

+ my ($from, $to) = split (/\-/, $opt_t);

+ if ($from ne '')

+ {

+ $wherelist = 'datetimeoriginal >= \''. substr($from, 0, 4) .'-'. substr($from, 4, 2) .'-'. substr($from, 6, 2) .'\'';

+ }

+ if ($to ne '')

+ {

+ $wherelist .= ($wherelist ne '' ? ' AND ' : '') . 'datetimeoriginal <= \''. substr($to, 0, 4) .'-'. substr($to, 4, 2) .'-'. substr($to, 6, 2) .'\'';

+ }

+ }

- return "SELECT $fieldlist count(file) as count FROM photos $grouplist $orderlist";

+ if ($grouplist ne '') { $grouplist = 'GROUP BY '. $grouplist; }

+ if ($wherelist ne '') { $wherelist = 'WHERE ' . $wherelist; }

+

+ return "SELECT $fieldlist count(file) as count FROM photos $wherelist $grouplist $orderlist";

}

sub query_db

@@ -232,4 +250,6 @@ say ' allowed values: year, month, week';

say ' -s : (query mode) specify the information you want to select, defaults to none (just show number of images)';

say ' allowed values: maker, model, lens, aperture, exposuretime, iso, focallength, focallength35mm';

say ' multiple fields should be listed comma-separated';

+ say ' -t <range> : only take images into account which have been taken in the given timerange';

+ say ' <range> must be specified as \'YYYYMMDD-YYYYMMDD\', you can omit one value';

}