summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbin/events2md.pl66
1 files changed, 12 insertions, 54 deletions
diff --git a/bin/events2md.pl b/bin/events2md.pl
index afef569..d7a4eb4 100755
--- a/bin/events2md.pl
+++ b/bin/events2md.pl
@@ -19,8 +19,7 @@ use Log::Any::Adapter;
use URI;
use IO::Prompter;
use Cal::DAV;
-use Data::ICal;
-use iCal::Parser;
+use Data::ICal::DateTime;
use DateTime;
use Try::Tiny;
use Path::Tiny;
@@ -112,25 +111,6 @@ if ( $log->is_trace ) {
p $calendar;
}
-# index calendar entries
-$log->debug('index calendar entries...');
-my %calendar_entries;
-for ( @{ $calendar->entries } ) {
- if ( 'VEVENT' eq $_->ical_entry_type ) {
- my $uid = try { $_->property('uid')->[0]->value };
- $uid ||= Data::ICal::Entry::Event->new()->property('uid')->[0]->value;
- $calendar_entries{VEVENT}{$uid} = $_;
- }
- else {
- # TODO
- next;
- }
-}
-if ( $log->is_trace ) {
- use DDP;
- p %calendar_entries;
-}
-
# TODO: if list is empty and no calendar uri was explicitly supplied,
# warn on stdout with list of abailable collections using this sequence:
# 1. PROPFIND on base-URL for {DAV:}current-user-principal
@@ -142,11 +122,16 @@ if ( $log->is_trace ) {
$log->debug('serialize calendar events...');
my $start = DateTime->now;
my $end = $start->clone->add( months => 6 );
-my $parser = iCal::Parser->new( start => $start, end => $end );
-my $events = $parser->parse_strings( $calendar->as_string );
+my $span = DateTime::Span->from_datetimes( start => $start, end => $end );
+my @events = sort {
+ DateTime->compare( $a->start, $b->start )
+ || DateTime->compare( $a->end, $b->end )
+ || get_property_string( $a, 'summary' )
+ cmp get_property_string( $b, 'summary' )
+} $calendar->events($span);
if ( $log->is_trace ) {
use DDP;
- p $events;
+ p @events;
}
my $output_path;
if ($OUTPUT_FILE) {
@@ -154,36 +139,9 @@ if ($OUTPUT_FILE) {
$output_path->parent->mkpath;
$output_path->remove;
}
-for my $year (
- map { $events->{events}{$_} }
- sort { $a <=> $b } keys %{ $events->{events} }
- )
-{
- for my $month (
- map { $year->{$_} }
- sort { $a <=> $b } keys %$year
- )
- {
- for my $day (
- map { $month->{$_} }
- sort { $a <=> $b } keys %$month
- )
- {
- my @events = sort {
- DateTime->compare( $a->[1], $b->[1] )
- || DateTime->compare( $a->[2], $b->[2] )
- || get_property_string( $a->[0], 'summary' )
- cmp get_property_string( $b->[0], 'summary' )
- } map {
- [ $calendar_entries{VEVENT}{$_},
- $day->{$_}{DTSTART}, $day->{$_}{DTEND}
- ]
- } keys %$day;
- for (@events) {
- print_event( $_->[0], $_->[1], $_->[2], $output_path, );
- }
- }
- }
+
+for (@events) {
+ print_event( $_, $_->start, $_->end, $output_path, );
}
sub print_event