diff options
Diffstat (limited to 'lib/Object/Groupware/Calendar.pm')
-rw-r--r-- | lib/Object/Groupware/Calendar.pm | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/lib/Object/Groupware/Calendar.pm b/lib/Object/Groupware/Calendar.pm new file mode 100644 index 0000000..7226782 --- /dev/null +++ b/lib/Object/Groupware/Calendar.pm @@ -0,0 +1,51 @@ +use v5.36; +use Feature::Compat::Class 0.07; + +package Object::Groupware::Calendar 0.01; + +class Object::Groupware::Calendar; + +use utf8; + +use Log::Any qw( ); +use Data::ICal::DateTime; + +use Object::Groupware::Event; + +field $log = Log::Any->get_logger; + +# borrow from Data::ICal::new() signature +field $data : param = undef; +field $filename : param = undef; + +ADJUST { + if ($data) { + if ( $data isa Data::ICal ) { } + else { $data = Data::ICal->new( data => $data ) } + } + elsif ($filename) { $data = Data::ICal->new( filename => $filename ) } + + if ( $log->is_trace ) { + use DDP; + p $data; + } +} + +# mimick Data::ICal::DateTime::events() signature +method events ( $set = undef, $period = undef ) +{ + $log->infof( + 'will pick events between %s and %s', + $set->start, $set->end + ) if $set; + + my @events = map { Object::Groupware::Event->new( entry => $_ ) } sort { + $a->start->compare( $b->start ) + || $a->start->compare( $b->start ) + || $a->summary cmp $b->summary + } $data->events( $set || (), $period || () ); + + return @events; +} + +1; |