Date: Wed, 29 Oct 2014 20:25:09 -0500 From: "B. Estrade" <estrabd@gmail.com> To: Dan Langille <dan@langille.org> Cc: "freebsd-hackers@freebsd.org" <freebsd-hackers@freebsd.org> Subject: Re: perl isvaliddate function Message-ID: <F4064762-2534-47BB-8594-AEBF6D82ABAF@gmail.com> In-Reply-To: <310ADD44-3897-44F6-8D82-49AD66011FFA@langille.org> References: <4EA9EE9C-5049-4C50-B361-07F58FA19896@langille.org> <CALSf6fQ%2BiaXrz9bCe7mZEz8K%2BUsbG5jdgibueNK_dyhMUY2xdg@mail.gmail.com> <E7A7A52F-A54E-4D6D-BC2B-D349E228FCA4@langille.org> <CALSf6fS7-x0UL%2B4g3R9V412cL532uagBd_JVHLgDp8ZQOWWrJg@mail.gmail.com> <310ADD44-3897-44F6-8D82-49AD66011FFA@langille.org>
next in thread | previous in thread | raw e-mail | index | archive | help
It was the very least I could do. All the thanks really goes to YOU :) Cheers, Brett Sent from my iPhone > On Oct 29, 2014, at 6:34 PM, Dan Langille <dan@langille.org> wrote: >=20 > Thank you. This is now in use at http://dev.freshports.org and will move t= o production later. >=20 >> On Oct 27, 2014, at 9:12 AM, B. Estrade <estrabd@gmail.com> wrote: >>=20 >> 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 - 190= 0); >> 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 <dan@langille.org> wrote: >>> On Oct 25, 2014, at 2:21 PM, B. Estrade <estrabd@gmail.com> 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 wou= ld verify that the date you start with is the same date as the one returned a= fter the format. This core function is also very useful for date addition a= nd subtraction. >>> > >>> > I don't have time at this moment to create a proof of concept, but if y= ou'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 a= ppreciate that. >>>=20 >>> FYI: I believe all dates within the ports tree must be YYYY-MM-DD so usi= ng something like that would be useful. >>>=20 >>> Comparing the starting date to the supplied date is good too, to catch e= dge cases like the first example. >>>=20 >>> =E2=80=94 >>> Dan Langille >=20 > =E2=80=94=20 > Dan Langille >=20
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?F4064762-2534-47BB-8594-AEBF6D82ABAF>