Skip site navigation (1)Skip section navigation (2)
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

--Apple-Mail=_C9BFF911-04E2-4BC1-974C-1CC49FA40CF8
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
	charset=windows-1252

I=92m 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=92m =
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) =3D @_;
 =20
  my $Date =3D str2time($string);
 =20
  return defined($Date);
}

my $a =3D '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 =3D '2014-02-30';

if (IsValidDate($b)) {
  print "'$b' is a valid date\n";
} else {
  print "'$b' is NOT a valid date\n";
}

my $c =3D '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
$=20

=97=20
Dan Langille


--Apple-Mail=_C9BFF911-04E2-4BC1-974C-1CC49FA40CF8
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename=signature.asc
Content-Type: application/pgp-signature;
	name=signature.asc
Content-Description: Message signed with OpenPGP using GPGMail

-----BEGIN PGP SIGNATURE-----
Comment: GPGTools - http://gpgtools.org

iKYEARECAGYFAlRL1kJfFIAAAAAALgAoaXNzdWVyLWZwckBub3RhdGlvbnMub3Bl
bnBncC5maWZ0aGhvcnNlbWFuLm5ldDA3REZBQjJGRUQ3NEE5QkE0NTNGOUJCNzBB
MEIxNzE0Q0ZGQjlEM0MACgkQCgsXFM/7nTyhfgCg/SK0coJwLJQpv31L++hagpWF
+hEAoM5eEXn29a2nUOYH9AE8NU7ouBVa
=xqxU
-----END PGP SIGNATURE-----

--Apple-Mail=_C9BFF911-04E2-4BC1-974C-1CC49FA40CF8--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4EA9EE9C-5049-4C50-B361-07F58FA19896>