New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make parameter validation in rand_time more consistent #10

Merged
merged 1 commit into from Apr 18, 2018

Conversation

Projects
None yet
2 participants
@jjatria
Contributor

jjatria commented Mar 9, 2018

The rand_time function validates the parameters passed to min and max, producing useful warnings when the input is not valid:

rand_time( min => "31:2:1" )
# minimum time is not in valid time format HH:MM:SS at lib/Data/Random.pm line 321.

But it only catches certain kinds of "bad" input:

rand_time( min => "foo" )
# Argument "foo" isn't numeric in numeric gt (>) at lib/Data/Random.pm line 321.
# Use of uninitialized value $min_min in numeric gt (>) at lib/Data/Random.pm line 323.
# Use of uninitialized value $min_min in numeric lt (<) at lib/Data/Random.pm line 323.
# Use of uninitialized value $min_sec in numeric gt (>) at lib/Data/Random.pm line 325.
# Use of uninitialized value $min_sec in numeric lt (<) at lib/Data/Random.pm line 325.
# Use of uninitialized value $min_min in multiplication (*) at lib/Data/Random.pm line 356.
# Use of uninitialized value $min_sec in addition (+) at lib/Data/Random.pm line 356.

Furthermore, the first case will return undef (as is the common behaviour when input was bad). But the second case happily ignores the (bad) value passed in, and returns a random time.

This patch fixes this using Time::Piece, which is already loaded.

@barefootcoder barefootcoder merged commit 6dc8315 into barefootcoder:master Apr 18, 2018

@jjatria jjatria deleted the jjatria:time-validation branch Apr 22, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment