From owner-freebsd-hackers@FreeBSD.ORG Wed Oct 29 23:35:11 2014 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id E77037F6 for ; Wed, 29 Oct 2014 23:35:11 +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 A1B29AD5 for ; Wed, 29 Oct 2014 23:35:11 +0000 (UTC) Received: from nyi.unixathome.org (localhost [127.0.0.1]) by nyi.unixathome.org (Postfix) with ESMTP id CE9FB5084A; Wed, 29 Oct 2014 23:34:52 +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 tdttCUNM1HHg; Wed, 29 Oct 2014 23:34:52 +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 1D8345082B ; Wed, 29 Oct 2014 23:34:51 +0000 (UTC) Mime-Version: 1.0 (Mac OS X Mail 7.3 \(1878.6\)) Subject: Re: perl isvaliddate function From: Dan Langille In-Reply-To: Date: Wed, 29 Oct 2014 19:34:59 -0400 Message-Id: <310ADD44-3897-44F6-8D82-49AD66011FFA@langille.org> References: <4EA9EE9C-5049-4C50-B361-07F58FA19896@langille.org> To: "B. Estrade" X-Mailer: Apple Mail (2.1878.6) Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.18-1 Cc: freebsd-hackers@freebsd.org 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: Wed, 29 Oct 2014 23:35:12 -0000 Thank you. This is now in use at http://dev.freshports.org and will = move to production later. On Oct 27, 2014, at 9:12 AM, B. Estrade wrote: > use POSIX qw/strftime/; >=20 > sub IsValidDate($) { > my $string =3D shift; > my ($year, $mon, $mday) =3D split /-/, $string; > my $test =3D strftime("%Y-%m-%d", 0, 0, 0, $mday, $mon - 1, $year - = 1900); > return ($test eq $string) ? $string : undef; > } >=20 > my $a =3D '2014-11-30 unless *coin ports remain unfixed'; >=20 > if (IsValidDate($a)) { > print "'$a' is a valid date\n"; > } else { > print "'$a' is NOT a valid date\n"; > } >=20 > my $b =3D '2014-02-30'; >=20 > if (IsValidDate($b)) { > print "'$b' is a valid date\n"; > } else { > print "'$b' is NOT a valid date\n"; > } >=20 > my $c =3D '2014-02-28'; >=20 > if (IsValidDate($c)) { > print "'$c' is a valid date\n"; > } else { > print "'$c' is NOT a valid date\n"; > } >=20 >=20 > On Sat, Oct 25, 2014 at 2:50 PM, Dan Langille = wrote: > On Oct 25, 2014, at 2:21 PM, B. Estrade wrote: >=20 > > Looks fine to just get it working. If you wanted to be more = efficient, I believe there is a way to use the core POSIX::strfmtime in = a way that would verify that the date you start with is the same date as = the one returned after the format. This core function is also very = useful for date addition and subtraction. > > > > I don't have time at this moment to create a proof of concept, but = if you're interested let me know and I will when I have a minute. >=20 > Yes, please, when you have time, please try that proof for me. I = would appreciate that. >=20 > FYI: I believe all dates within the ports tree must be YYYY-MM-DD so = using something like that would be useful. >=20 > Comparing the starting date to the supplied date is good too, to catch = edge cases like the first example. >=20 > =97 > Dan Langille >=20 >=20 =97=20 Dan Langille