diff options
author | Daniel Friesel <derf@finalrewind.org> | 2016-06-13 23:35:25 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2016-06-13 23:35:25 +0200 |
commit | e99da818f0f389e51585f88e40f104e56c4685a0 (patch) | |
tree | fbf760b17e155675a8da8ec3bcea149589de11cf /bin | |
parent | 53d29534b951e3717d67de1a11ac072140127c0c (diff) |
db-iris: Add input validation for --date and --time
DateTime also validates these parameters, but forwarding its exceptions
to the user isn't exactly user friendly
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/db-iris | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/bin/db-iris b/bin/db-iris index 81c8081..d49b313 100755 --- a/bin/db-iris +++ b/bin/db-iris @@ -69,7 +69,18 @@ if ($track_via) { } if ($date) { - my ( $day, $month, $year ) = split( qr{ [.] }ox, $date ); + my ( $day, $month, $year ) = split( qr{ [.] }x, $date ); + + if ( not( defined $day and defined $month ) + or ( $day < 1 ) + or ( $day > 31 ) + or ( $month < 1 ) + or ( $month > 12 ) ) + { + say STDERR "-d/--date: Please specify a valid date"; + exit(3); + } + $datetime->set( day => $day, month => $month, @@ -77,7 +88,20 @@ if ($date) { ); } if ($time) { - my ( $hour, $minute, $second ) = split( qr{ : }ox, $time ); + my ( $hour, $minute, $second ) = split( qr{ : }x, $time ); + + if ( not defined $hour + or not defined $minute + or ( $hour < 0 ) + or ( $hour > 23 ) + or ( $minute < 0 ) + or ( $minute > 59 ) + or ( defined $second and ( ( $second < 0 ) or ( $second > 59 ) ) ) ) + { + say STDERR "-t/--time: Please specify a valid time"; + exit(3); + } + $datetime->set( hour => $hour, minute => $minute, |