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