Skip to content

Instantly share code, notes, and snippets.

@dexterbt1
Created September 16, 2016 09:15
Show Gist options
  • Save dexterbt1/0b52dfc0eb0a1be2ebc6a290940c318a to your computer and use it in GitHub Desktop.
Save dexterbt1/0b52dfc0eb0a1be2ebc6a290940c318a to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use Date::Parse::Lite;
## See this module: http://search.cpan.org/~gbarr/TimeDate-2.30/lib/Date/Parse.pm
my @user_inputs = (
'9-14-2016',
'9 14 2016',
'9.14.2016',
'2016/9-14',
'2016,9-14',
'2016,9,14',
'2016/9/14',
'2016.9.14',
'2016.14.9',
'2016.12.9',
'sep 14-2016',
's 14-2016',
'sep142016',
'september 14, 2016',
'2016-09-14',
'2016-9-14',
'16-9-14',
'sept14 2016',
'sep14 2016',
'sep14.2016',
'sep14-2016',
'sep14,2016',
'sep14',
);
my $parser = Date::Parse::Lite->new();
for my $ui (@user_inputs) {
$parser->parse($ui);
if ($parser->parsed()) {
my $day = $parser->day();
print STDOUT sprintf("Parsed %-20s == %d-%d-%d\n", $ui, $parser->year, $parser->month, $parser->day);
}
else {
print STDERR "Unable to parse: $ui\n";
}
}
__END__
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment