7 use ok 'MooseX::Types::DateTime';
9 use Moose::Util::TypeConstraints;
11 isa_ok( find_type_constraint($_), "Moose::Meta::TypeConstraint" ) for qw(DateTime DateTime::TimeZone DateTime::Locale);
27 my $coerced = Foo->new( date => $epoch )->date;
29 isa_ok( $coerced, "DateTime", "coerced epoch into datetime" );
31 is( $coerced->epoch, $epoch, "epoch is correct" );
33 isa_ok( Foo->new( date => { year => 2000, month => 1, day => 1 } )->date, "DateTime" );
35 isa_ok( Foo->new( date => 'now' )->date, "DateTime" );
37 throws_ok { Foo->new( date => "junk1!!" ) } qr/DateTime/, "constraint";
46 isa => "DateTime::Duration",
52 my $coerced = Quxx->new( duration => 10 )->duration;
54 isa_ok( $coerced, "DateTime::Duration", "coerced from seconds" );
58 my $now = DateTime->from_epoch( epoch => $time );
60 my $future = $now + $coerced;
62 is( $future->epoch, ( $time + 10 ), "coerced value" );
64 isa_ok( Quxx->new( duration => { minutes => 2 } )->duration, "DateTime::Duration", "coerced from hash" );
66 throws_ok { Quxx->new( duration => "ahdstkljhat" ) } qr/DateTime/, "constraint";
75 isa => "DateTime::TimeZone",
81 my $tz = Bar->new( time_zone => "Africa/Timbuktu" )->time_zone;
83 isa_ok( $tz, "DateTime::TimeZone", "coerced string into time zone object" );
85 like( $tz->name, qr/^Africa/, "correct time zone" );
87 dies_ok { Bar->new( time_zone => "Space/TheMoon" ) } "bad time zone";
96 isa => "DateTime::Locale",
102 my $loc = Gorch->new( loc => "he_IL" )->loc;
104 isa_ok( $loc, "DateTime::Locale::he", "coerced from string" );
106 dies_ok { Gorch->new( loc => "not_a_place_or_a_locale" ) } "bad locale name";
109 skip "No Locale::Maketext", 2 unless eval { require Locale::Maketext };
113 our @ISA = qw(Locale::Maketext);
115 package Some::L10N::ja;
116 our @ISA = qw(Some::L10N);
119 goodbye => "sayonara",
123 my $handle = Some::L10N->get_handle("ja");
125 isa_ok( $handle, "Some::L10N", "maketext handle" );
127 isa_ok( Gorch->new( loc => $handle )->loc, "DateTime::Locale::ja", "coerced from maketext" );;
136 use MooseX::Types::DateTime qw(DateTime Duration);
138 has 'date' => (is=>'rw', isa=>DateTime, coerce=>1);
139 has 'duration' => (is=>'rw', isa=>Duration, coerce=>1);
145 ok my $gondor = Gondor->new(date=>$epoch, duration=>10)
146 => 'Instantiated object using export types';