SBECK-github / Date-Manip

Other
10 stars 11 forks source link

getting bogus output #30

Closed foobargeez closed 4 years ago

foobargeez commented 4 years ago
$> perl
use Date::Manip qw(ParseDate);
print ParseDate("Nov, 2020"), "\n";
2020112000:00:00
$>
SBECK-github commented 4 years ago

This is an unfortunate side effect of the flexibility of the Date::Manip parsing. It tries to examine quite a few formats to find a date. In this case, you're parsing Nov 2020 which it decides is equivalent to Nov 20/20 or Nov 20, 2020

I'll have to examine the regexps to see if I can tighten them up a bit to avoid this.

foobargeez commented 4 years ago

Thanks. As this is affecting production, I quickly switched the helper to something like this:

use Time::Moment;
use Time::ParseDate;

my $d = parsedate("22 Aug 1955");
if (defined $d) {
    print Time::Moment->from_epoch($d)->strftime("%Y%m%d"), "\n";
} else {
    print "not valid\n";
}

Not my favorite (double hop) but that's what I quickly found.