aboutsummaryrefslogtreecommitdiff
path: root/lib/Object/Groupware/Calendar.pm
blob: 3d46032667f2bf15d4b2012f5685b8000ac5d1ac (plain)
  1. use v5.36;
  2. use Feature::Compat::Class 0.07;
  3. package Object::Groupware::Calendar 0.01;
  4. class Object::Groupware::Calendar : isa(Object::Groupware);
  5. use utf8;
  6. use Log::Any qw( );
  7. use Data::ICal::DateTime;
  8. use Object::Groupware::Event;
  9. field $log = Log::Any->get_logger;
  10. # borrow from Data::ICal::new() signature
  11. field $data : param = undef;
  12. field $filename : param = undef;
  13. ADJUST {
  14. if ($data) {
  15. if ( $data isa Data::ICal ) { }
  16. else { $data = Data::ICal->new( data => $data ) }
  17. }
  18. elsif ($filename) { $data = Data::ICal->new( filename => $filename ) }
  19. if ( $log->is_trace ) {
  20. use DDP;
  21. p $data;
  22. }
  23. }
  24. # mimick Data::ICal::DateTime::events() signature
  25. method events ( $set = undef, $period = undef )
  26. {
  27. $log->infof(
  28. 'will pick events between %s and %s',
  29. $set->start, $set->end
  30. ) if $set;
  31. my $dt_locale = $self->dt_locale;
  32. my $dt_time_zone = $self->dt_time_zone;
  33. my @events = map {
  34. Object::Groupware::Event->new(
  35. entry => $_,
  36. dt_locale => $dt_locale,
  37. dt_time_zone => $dt_time_zone,
  38. )
  39. } sort {
  40. $a->start->compare( $b->start )
  41. || $a->end ? $a->end->compare( $b->end ) : 0
  42. || $a->summary cmp $b->summary
  43. } $data->events( $set || (), $period || () );
  44. return @events;
  45. }
  46. 1;