Data-ICal-DateTime
view release on metacpan or search on metacpan
lib/Data/ICal/DateTime.pm view on Meta::CPAN
$self->add_property( dtend => $self->_make_dt_param($update) );
$self->property('dtend')->[0]->parameters->{VALUE} = 'DATE' if $all_day;
}
my $dtend = $self->property('dtend') || return undef;
my $ret = DateTime::Format::ICal->parse_datetime($dtend->[0]->value);
eval { $ret->set_time_zone($dtend->[0]->parameters->{TZID}) } if ($dtend->[0]->parameters->{TZID});
$ret->truncate(to => 'day' )->subtract( nanoseconds => 1 ) if $all_day;
return $ret;
}
=head2 all_day
Returns 1 if event is all day or 0 if not.
If no end has been set and 1 is passed then will set end to be a
nanosecond before midnight the next day.
The have multi-day all-day events simply set the end time to be
nanosecond before midnight on the last day of the event.
=cut
sub all_day {
my $self = shift;
my $new = shift;
# TODO - should be able to make all day with just the start
my $dtend = $self->property('dtend');
if (!$dtend) {
return 0 unless $new;
$dtend = $self->start->clone->add( days => 1 )->truncate(to => 'day' )->subtract( nanoseconds => 1 );
$self->end($dtend);
$dtend = $self->property('dtend');
}
my $cur = (defined $dtend && defined $dtend->[0]->parameters->{VALUE} && $dtend->[0]->parameters->{VALUE} eq 'DATE') || 0;
if (defined $new && $new != $cur) {
my $end = $self->end;
if ($new == 0) {
delete $self->property('dtend')->[0]->parameters->{VALUE};
} else {
$self->property('dtend')->[0]->parameters->{VALUE} = 'DATE';
}
$self->end($end);
$cur = $new;
}
return $cur;
}
=head2 floating
An event is considered floating if it has a start but no end. It is intended
to represent an event that is associated with a given calendar date and time
of day, such as an anniversary and should not be considered as taking up any
amount of time.
Returns 1 if the evnt is floating and 0 if it isn't.
If passed a 1 then will set the event to be floating by deleting the end time.
If passed a 0 and no end is currently set then it will set end to be a
nanosecond before midnight the next day.
=cut
sub floating {
my $self = shift;
my $new = shift;
my $end = $self->end;
my $cur = (defined $end)? 0 : 1;
if (defined $new && $new != $cur) {
# it is floating - delete the end
if ($new) {
delete $self->{properties}->{dtend};
# it's not floating - simulate end as 1 nanosecond before midnight after the start
} else {
my $dtend = $self->start->clone->add( days => 1 )->truncate(to => 'day' )->subtract( nanoseconds => 1 );
$self->end($dtend);
}
$cur = $new;
}
return $cur;
}
=head2 duration
Returns a L<DateTime::Duration> object representing the duration of this
event.
May return undef.
If passed a L<DateTime::Duration> object will set that to be the new
duration.
=cut
sub duration {
my $self = shift;
my $new = shift;
if ($new) {
delete $self->{properties}->{duration};
$self->add_property( duration => DateTime::Format::ICal->format_duration($new) );
}
my $duration = $self->property('duration') || return undef;
return DateTime::Format::ICal->parse_duration($duration->[0]->value);
}
( run in 0.834 second using v1.01-cache-2.11-cpan-39bf76dae61 )