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