diff options
author | cos <cos> | 2011-08-08 19:43:02 +0200 |
---|---|---|
committer | cos <cos> | 2011-08-08 19:43:02 +0200 |
commit | 11c1de92f5d6b5757cc96fba0a17c63dd9617c70 (patch) | |
tree | 0f7fa115dcdee3d8bd2379eb48cb0a2ba14e9272 | |
parent | fbff367b5e3177507b83d721265b6222a12ad051 (diff) | |
download | mat-11c1de92f5d6b5757cc96fba0a17c63dd9617c70.zip |
Added postpone command.
-rwxr-xr-x | mat | 58 |
1 files changed, 46 insertions, 12 deletions
@@ -126,6 +126,30 @@ sub cmd_randmeal { return cmd_setmeal($date, $recipe_id); } +sub cmd_postpone { + my ( $date, $gap ) = @_; + my $mealtype = "lunch"; + my $startdate; + + if($date) { + return -1 unless $date =~ "^[0-9]{4}-[0-9]{2}-[0-9]{2}\$"; + $startdate = DateTime::Format::ISO8601->parse_datetime( $date ); + } else { + $startdate = DateTime->now(); + } + $gap = 1; + + my $entries = $db->selectall_arrayref("SELECT date FROM plan WHERE date ". + "BETWEEN '".$startdate."' and '2999-01-01' ORDER BY date DESC", + { Slice => {} }); + for my $entry ( @$entries ) { + my $nextdate = DateTime::Format::ISO8601->parse_datetime($entry->{date}); + $nextdate->add(days => $gap); + $db->do("UPDATE plan SET date='".$nextdate->ymd()."' WHERE date='". + $entry->{date}."';\n"); + } +} + sub cmd_showplan { my ( $date ) = @_; my $mealtype = "lunch"; @@ -151,19 +175,23 @@ sub cmd_showplan { } sub cmd_randweek { - for (my $i = 0; $i < 5; $i++) { - $schedule[$i]->{'recipe'} = get_random_recipe; - } +# for (my $i = 0; $i < 5; $i++) { +# $schedule[$i]->{'recipe'} = get_random_recipe; +# } +# +# for (my $i = 0; $i < 5; $i++) { +# print $schedule[$i]->{'day'}.": "; +# print get_recipe_name($schedule[$i]->{'recipe'})."\n"; +# my $contents = $db->selectall_arrayref("SELECT * FROM contents WHERE ". +# "recipe_id=".$schedule[$i]->{'recipe'}); +# unless (@$contents) { +# print "OBSERVERA: Ingredienslista saknas för denna rätt!\n\n"; +# } +# } +} - for (my $i = 0; $i < 5; $i++) { - print $schedule[$i]->{'day'}.": "; - print get_recipe_name($schedule[$i]->{'recipe'})."\n"; - my $contents = $db->selectall_arrayref("SELECT * FROM contents WHERE ". - "recipe_id=".$schedule[$i]->{'recipe'}); - unless (@$contents) { - print "OBSERVERA: Ingredienslista saknas för denna rätt!\n\n"; - } - } +sub cmd_help() { + print "Help yet to be implemented\n"; } # MAIN PROGRAM ################################################################ @@ -171,6 +199,9 @@ sub cmd_randweek { read_recipe_db; if ($ARGV[0]) { + if ( $ARGV[0] eq "help") { + print "Command failed!\n" unless (cmd_help >= 0); + } if ( $ARGV[0] eq "setmeal") { print "Command failed!\n" unless (cmd_setmeal($ARGV[1], $ARGV[2]) >= 0); } @@ -180,6 +211,9 @@ if ($ARGV[0]) { if ( $ARGV[0] eq "showplan") { print "Command failed!\n" unless (cmd_showplan($ARGV[1]) >= 0); } + if ( $ARGV[0] eq "postpone") { + print "Command failed!\n" unless (cmd_postpone($ARGV[1]) >= 0); + } } else { cmd_showplan; } |