Date: Sat, 25 Oct 2014 12:56:34 -0400 From: Dan Langille <dan@langille.org> To: freebsd-hackers@freebsd.org Subject: perl isvaliddate function Message-ID: <4EA9EE9C-5049-4C50-B361-07F58FA19896@langille.org>
next in thread | raw e-mail | index | archive | help
[-- Attachment #1 --] I’m coding up a sanity check for FreshPorts. It will verify that field that should be dates are dates. Feedback welcome. The system is already using the DATE module, so I’m leveraging that. Pasted at http://dpaste.com/1H0Q8RR.txt but included below, because. $ cat test-date.pl #!/usr/bin/perl use Date::Parse qw( str2time ); sub IsValidDate($) { my ($string) = @_; my $Date = str2time($string); return defined($Date); } my $a = '2014-11-30 unless *coin ports remain unfixed'; if (IsValidDate($a)) { print "'$a' is a valid date\n"; } else { print "'$a' is NOT a valid date\n"; } my $b = '2014-02-30'; if (IsValidDate($b)) { print "'$b' is a valid date\n"; } else { print "'$b' is NOT a valid date\n"; } my $c = '2014-02-28'; if (IsValidDate($c)) { print "'$c' is a valid date\n"; } else { print "'$c' is NOT a valid date\n"; } $ perl test-date.pl '2014-11-30 unless *coin ports remain unfixed' is NOT a valid date '2014-02-30' is NOT a valid date '2014-02-28' is a valid date $ — Dan Langille [-- Attachment #2 --] -----BEGIN PGP SIGNATURE----- Comment: GPGTools - http://gpgtools.org iKYEARECAGYFAlRL1kJfFIAAAAAALgAoaXNzdWVyLWZwckBub3RhdGlvbnMub3Bl bnBncC5maWZ0aGhvcnNlbWFuLm5ldDA3REZBQjJGRUQ3NEE5QkE0NTNGOUJCNzBB MEIxNzE0Q0ZGQjlEM0MACgkQCgsXFM/7nTyhfgCg/SK0coJwLJQpv31L++hagpWF +hEAoM5eEXn29a2nUOYH9AE8NU7ouBVa =xqxU -----END PGP SIGNATURE-----
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4EA9EE9C-5049-4C50-B361-07F58FA19896>
