From owner-freebsd-hackers@FreeBSD.ORG Mon Oct 27 13:13:10 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 7AA93E14 for ; Mon, 27 Oct 2014 13:13:10 +0000 (UTC) Received: from mail-qc0-x233.google.com (mail-qc0-x233.google.com [IPv6:2607:f8b0:400d:c01::233]) (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 3805863A for ; Mon, 27 Oct 2014 13:13:10 +0000 (UTC) Received: by mail-qc0-f179.google.com with SMTP id o8so1852114qcw.10 for ; Mon, 27 Oct 2014 06:13:09 -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=y5MZIq6JMHpQimIxmjGY2TfCq7pvkrG8eeX2Guh6fDI=; b=cqLAm/W8iZEm7F0u7kbwewfjjV0L/MQ6AOeEepHrdiL585HUWiuNm6mN9fM11kI1Sk GQGNhLrgV1JBQXIG61p+LMC7JpCetief28S+kzqh8PcuFSyaROcPlI+1syooG9yaewN3 kGT7dfgebKCbVs/p6BNaHygbWj867HKlARcLsCZpEyEXPAAvZ02NhxaZmnzhJBFQqGTF sO9EPpJLSV+akns17S/aOKGrvdViKp8LS2xcV5lFNAQ2LcnVcMP2WIGlcb5uOO59Dg+t I2TE7obefZWDm5HWQPmuWOcahUF7mF8NpscmoDLShynd6UwINjmXvHKhZkadPN2WeoP2 KRnA== X-Received: by 10.140.98.234 with SMTP id o97mr31569215qge.49.1414415589221; Mon, 27 Oct 2014 06:13:09 -0700 (PDT) MIME-Version: 1.0 Received: by 10.229.89.133 with HTTP; Mon, 27 Oct 2014 06:12:48 -0700 (PDT) In-Reply-To: References: <4EA9EE9C-5049-4C50-B361-07F58FA19896@langille.org> From: "B. Estrade" Date: Mon, 27 Oct 2014 08:12:48 -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: Mon, 27 Oct 2014 13:13:10 -0000 use POSIX qw/strftime/; 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; } 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"; } On Sat, Oct 25, 2014 at 2:50 PM, Dan Langille wrote: > On Oct 25, 2014, at 2:21 PM, B. Estrade wrote: > > > 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 wou= ld > 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 additi= on > 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. > > Yes, please, when you have time, please try that proof for me. I would > appreciate that. > > FYI: I believe all dates within the ports tree must be YYYY-MM-DD so usin= g > something like that would be useful. > > Comparing the starting date to the supplied date is good too, to catch > edge cases like the first example. > > =E2=80=94 > Dan Langille > >