| 1 | use strict; |
| 2 | |
| 3 | |
| 4 | use Test::More tests => 24; |
| 5 | |
| 6 | |
| 7 | use Data::ICal::DateTime; |
| 8 | use Data::ICal::Entry::Event; |
| 9 | use DateTime; |
| 10 | use DateTime::Set; |
| 11 | use DateTime::TimeZone; |
| 12 | |
| 13 | my $cal; |
| 14 | ok($cal = Data::ICal->new( filename => 't/ics/all_day.ics'), "parse all_day ics"); |
| 15 | |
| 16 | |
| 17 | my $date1 = DateTime->new( year => 2005, month => 8, day => 1, hour => 23, minute => 59, second => 59 ); |
| 18 | my $date2 = DateTime->new( year => 2005, month => 10, day => 27, hour => 23, minute => 59, second => 59); |
| 19 | |
| 20 | my @events = $cal->events; |
| 21 | is (@events, 2, "2 total events"); |
| 22 | my ($e1, $e2) = @events; |
| 23 | |
| 24 | is ($e1->summary,"Event 1"); |
| 25 | is ($e2->summary,"Event 2"); |
| 26 | |
| 27 | is("".$e1->end, "".$date1, "E1's end is the correct date"); |
| 28 | is("".$e2->end, "".$date1, "E2's end is the correct date"); |
| 29 | is($e1->all_day,0, "E1 is not all day"); |
| 30 | is($e2->all_day,1, "E2 is all day"); |
| 31 | |
| 32 | $e1->end($date2); |
| 33 | $e2->end($date2); |
| 34 | |
| 35 | is("".$e1->end, "".$date2, "E1's end is the correct new date"); |
| 36 | is("".$e2->end, "".$date2, "E2's end is the correct new date"); |
| 37 | is($e1->all_day, 0, "E1 is not all day"); |
| 38 | is($e2->all_day, 1, "E2 is all day"); |
| 39 | |
| 40 | $e2->all_day(0); |
| 41 | is($e2->all_day, 0, "E2 is not all day"); |
| 42 | is("".$e2->end, "".$date2, "E2's end is the correct new date"); |
| 43 | $e2->all_day(1); |
| 44 | is($e2->all_day, 1, "E2 is now all day again "); |
| 45 | is("".$e2->end, "".$date2, "E2's end is the correct new date"); |
| 46 | |
| 47 | $e1->end($date1); |
| 48 | $e2->end($date1); |
| 49 | |
| 50 | my @e1 = $e1->split_up('hour'); |
| 51 | my @e2 = $e2->split_up('hour'); |
| 52 | |
| 53 | is(@e1, 14, "e1 14 exploded"); |
| 54 | is(@e2, 14, "e2 14 exploded"); |
| 55 | is($e1[0]->all_day, 0, "e1 exploded is not all day"); |
| 56 | is($e2[0]->all_day, 0, "e2 exploded is all day"); |
| 57 | is($e1[0]->original->all_day, 0, "e1 exploded wasn't originally all day"); |
| 58 | is($e2[0]->original->all_day, 1, "e2 exploded was originally all day"); |
| 59 | |
| 60 | |
| 61 | # test setting all day without end |
| 62 | my $new = Data::ICal::Entry::Event->new(); |
| 63 | |
| 64 | my $new_date = $date1->clone->truncate( to => 'day' ); |
| 65 | $new->start($new_date); |
| 66 | $new->all_day(1); |
| 67 | |
| 68 | is ($new->all_day, 1, "New is all day"); |
| 69 | is ("".$new->end, "".$date1, "New end is the same as start"); |