Skip to content

Instantly share code, notes, and snippets.

@zby
Created October 13, 2009 19:46
Show Gist options
  • Save zby/209482 to your computer and use it in GitHub Desktop.
Save zby/209482 to your computer and use it in GitHub Desktop.
has_field 'date_time' => (
type => 'Compound',
apply => [
{
transform => sub { DateTime->new( shift ) },
message => 'This is not a correct date',
}
{
check => sub { shift->day_of_week == 1 },
message => 'Only Mondays allowed',
}
],
);
has_field 'date_time.year' => (
type => 'Integer',
);
has_field 'date_time.month' => (
type => 'Integer',
apply => [ { check => sub { my $month = shift; return $month > 0 && $month <= 12 } ]
);
has_field 'date_time.day' => (
type => 'Integer',
apply => [ { check => sub { my $day = shift; return $day > 0 && $day <= 31 } ]
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment