9
nnee
4y

Still trying to understand a good old pile of legacy:

function isValidDate($value) {
if ($value == "" || ($value == 0 && is_numeric($value)) {
return true;
}
// goes on to check if value is some number between 2000 and current year
}

Comments
  • 3
    Why does it return true if date is blank? That's just... Odd...

    Also what language is this? Powershell?
  • 1
    The question of the decade. No one knows. I don't. You don't. The guy who wrote it certainly doesn't know.

    Powershell could compete but it's php.
  • 0
    Nope. It checks if value passed matches certain, some pointless, criteria. Nowhere in the chain has such defaults. Not that I've seen, at least. It just makes no sense. And the guy who wrote it no longer works there, of course. It's some 10 years old code
  • 1
    @nnee I guess... It's the usual left over. Maybe checking year 2000 compatiblity.... Maybe checking invalid timestamps... Maybe the rest of an frustrated, sexless, alcohol toxicated night. Noone knows.
  • 3
    If(!strtotime($value)== false){
    // tada! I'm a valid date, let's do some real validations
    }

    I can understand verifying the date is greater then 2000 and less then 2100 but that whole thing you posted is that one line ^^
  • 0
    @C0D4 the most important line, other parts are described as comment and actually make sense so I didn't paste them. The first part that says empty string or 0 is valid date make absolutely no sense.
    Not sure what exactly you meant...
Add Comment