summaryrefslogtreecommitdiff
path: root/GroLUG/lib/HTML/Widget/Constraint/ISODate.pm
blob: 9712d3b7f2e4fb88aceb64686588fcb4207334a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package HTML::Widget::Constraint::ISODate; 
 
use warnings;
use strict;
use base 'HTML::Widget::Constraint';
use DateTime::Format::Strptime;
 
my $format=DateTime::Format::Strptime->new(pattern=>'%F');
 
sub validate {
    my ($self,$value)=@_;
 
    my $ret=eval {
        my $val=$format->parse_datetime($value);
        return unless defined($val);
 
        my $round_tripped=$val->strftime('%F');
 
        return ($value eq $round_tripped);
    };
    return if $@;
    return $ret;
}
 
1;