aboutsummaryrefslogtreecommitdiff
path: root/lib/Object/Groupware/Calendar.pm
blob: 332324ba0cc4dbe57a02fb2e32b745e2e56442f6 (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 = Log::Any->get_logger;
  12. # borrow from Data::ICal::new() signature
  13. field $data : param = undef;
  14. field $filename : param = undef;
  15. ADJUST {
  16. if ($data) {
  17. if ( $data isa Data::ICal ) { }
  18. else { $data = Data::ICal->new( data => $data ) }
  19. }
  20. elsif ($filename) { $data = Data::ICal->new( filename => $filename ) }
  21. $log->tracef(
  22. "Object %s contents:\n%s", __CLASS__,
  23. decode_utf8 $data->as_string
  24. );
  25. }
  26. # mimick Data::ICal::DateTime::events() signature
  27. method events ( $set = undef, $period = undef )
  28. {
  29. $log->infof(
  30. 'will pick events between %s and %s',
  31. $set->start, $set->end
  32. ) if $set;
  33. my $dt_locale = $self->dt_locale;
  34. my $dt_time_zone = $self->dt_time_zone;
  35. my @events = map {
  36. Object::Groupware::Event->new(
  37. entry => $_,
  38. dt_locale => $dt_locale,
  39. dt_time_zone => $dt_time_zone,
  40. )
  41. } sort {
  42. $a->start->compare( $b->start )
  43. || $a->end ? $a->end->compare( $b->end ) : 0
  44. || $a->summary cmp $b->summary
  45. } $data->events( $set || (), $period || () );
  46. return @events;
  47. }
  48. 1;