From owner-freebsd-hackers@FreeBSD.ORG Sat Oct 25 17:01:30 2014 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 4851CC7 for ; Sat, 25 Oct 2014 17:01:30 +0000 (UTC) Received: from nyi.unixathome.org (nyi.unixathome.org [64.147.113.42]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client CN "nyi.unixathome.org", Issuer "StartCom Class 2 Primary Intermediate Server CA" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 18C30E2E for ; Sat, 25 Oct 2014 17:01:29 +0000 (UTC) Received: from nyi.unixathome.org (localhost [127.0.0.1]) by nyi.unixathome.org (Postfix) with ESMTP id AD4135084A for ; Sat, 25 Oct 2014 17:01:12 +0000 (UTC) X-Virus-Scanned: amavisd-new at unixathome.org Received: from nyi.unixathome.org ([127.0.0.1]) by nyi.unixathome.org (nyi.unixathome.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 8t7EmLHhWyHG for ; Sat, 25 Oct 2014 17:01:12 +0000 (UTC) Received: from smtp-auth.unixathome.org (smtp-auth.unixathome.org [10.4.7.7]) (Authenticated sender: hidden) by nyi.unixathome.org (Postfix) with ESMTPSA id 12B1650843 for ; Sat, 25 Oct 2014 17:01:11 +0000 (UTC) From: Dan Langille Content-Type: multipart/signed; boundary="Apple-Mail=_C9BFF911-04E2-4BC1-974C-1CC49FA40CF8"; protocol="application/pgp-signature"; micalg=pgp-sha1 Subject: perl isvaliddate function Message-Id: <4EA9EE9C-5049-4C50-B361-07F58FA19896@langille.org> Date: Sat, 25 Oct 2014 12:56:34 -0400 To: freebsd-hackers@freebsd.org Mime-Version: 1.0 (Mac OS X Mail 7.3 \(1878.6\)) X-Mailer: Apple Mail (2.1878.6) X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 25 Oct 2014 17:01:30 -0000 --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--