From: Joey Schulze Date: Wed, 25 May 2016 11:58:43 +0000 (+0200) Subject: Accept short German dates as well X-Git-Url: https://git.infodrom.org/?p=infodrom.org%2Fservice.infodrom.org;a=commitdiff_plain;h=666057f6cf71a66ef10127eb8d4d9963a1844fa5 Accept short German dates as well --- diff --git a/src/InfoCon/buch/infocon b/src/InfoCon/buch/infocon index d049fd6..08e7f4f 100755 --- a/src/InfoCon/buch/infocon +++ b/src/InfoCon/buch/infocon @@ -87,6 +87,25 @@ sub date_to_string return sprintf("%4d%02d%02d", $year,$mon,$day); } +sub valid_isodate +{ + my $date = shift; + my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); + + return sprintf('%04d-%02d-%02d', $year+1900, $mon+1, $mday) unless defined $date; + + if ($date =~ /^(\d+)\.(\d+)\.?$/) { + if ($mon == 0 && $2 > 9) { + $date = sprintf('%04d-%02d-%02d', $year+1900-1, $2, $1); + } else { + $date = sprintf('%04d-%02d-%02d', $year+1900, $2, $1); + } + } elsif ($date !~ /^(\d+)-(\d+)-(\d+)$/) { + return undef; + } + return $date; +} + sub pay_invoice { my $nr = shift; @@ -95,8 +114,12 @@ sub pay_invoice my $sth; if ($pay) { + my $date = valid_isodate $opt_date; + + die "Invalid date\n" unless defined $date; + $query = sprintf("UPDATE sales SET paid=1,billing_date=%s WHERE nr = %d", - defined $opt_date ? $dbh->quote($opt_date) : 'now()', $nr); + defined $date ? $dbh->quote($date) : 'now()', $nr); } else { $query = sprintf("UPDATE sales SET paid=0,billing_date=NULL WHERE nr = %d", $nr); } @@ -511,7 +534,7 @@ sub usage print " --buchung-input|-bi\n"; print " --buchung-unpaid\n"; print " --buchung-hidden\n"; - print " --date yyyy-mm-dd (for --pay)\n"; + print " --date [yyyy-mm-dd|dd.mm.] (for --pay)\n"; print " --pay | --unpay \n"; print " --hide | --unhide \n"; print " --list-categories|-lc\n";