From owner-freebsd-hackers@FreeBSD.ORG Sat Oct 25 18:21:56 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 DED77CFD for ; Sat, 25 Oct 2014 18:21:56 +0000 (UTC) Received: from mail-qa0-x236.google.com (mail-qa0-x236.google.com [IPv6:2607:f8b0:400d:c00::236]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 9F0377F3 for ; Sat, 25 Oct 2014 18:21:56 +0000 (UTC) Received: by mail-qa0-f54.google.com with SMTP id u7so874718qaz.27 for ; Sat, 25 Oct 2014 11:21:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=aRZ9QO5sCi9vo3mI41Ox0uaWr3E0mgMXDouCNds6VgA=; b=xE7VgWaLe4aCvgYe5+FztP00S9OjfJE1drirpyEsl0og3FjDMQbvtepZPR1PhPGJKo uDTb03+tCe4KkgOYfy9mqnL3lVwEyxnc+kJRqfSY2/FCj2sucnQxek3khDruOk//M7a8 o0UFiladfmh75Qrgr8erx3cE2NnZ8WJEYTdOk/P+7RbS4MKZdD0AgVltKN3kcR95mYjR LXw1P6RyqD0OX7E2TIjzqfxgWX+TIqDMCxvkXFmQrdGAmA/+5vlIefjtB/fsux5bczaV 7IfpSANbGGboh74kOu75TvczP2JTN+U+OaCsJFIVu3Gz3GUVxoonBEXZ4/3ULtlkq1Hu 4WAQ== X-Received: by 10.140.92.37 with SMTP id a34mr16649293qge.103.1414261315252; Sat, 25 Oct 2014 11:21:55 -0700 (PDT) MIME-Version: 1.0 Received: by 10.229.89.133 with HTTP; Sat, 25 Oct 2014 11:21:35 -0700 (PDT) In-Reply-To: <4EA9EE9C-5049-4C50-B361-07F58FA19896@langille.org> References: <4EA9EE9C-5049-4C50-B361-07F58FA19896@langille.org> From: "B. Estrade" Date: Sat, 25 Oct 2014 13:21:35 -0500 Message-ID: Subject: Re: perl isvaliddate function To: Dan Langille Content-Type: text/plain; charset=UTF-8 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: Sat, 25 Oct 2014 18:21:57 -0000 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. Cheers, Brett On Sat, Oct 25, 2014 at 11:56 AM, Dan Langille wrote: > I=E2=80=99m 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=E2= =80=99m > 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 @_; > > my $Date =3D str2time($string); > > 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 > $ > > =E2=80=94 > Dan Langille > >