From ad289d23b089793cd0a43f7c145bf0846a827257 Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Wed, 28 Aug 2024 16:26:53 +0200 Subject: simplify vCalendar format juggling, thanks to Data::ICal::DateTime --- bin/events2md.pl | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/bin/events2md.pl b/bin/events2md.pl index 6ca7d0d..c7cf572 100755 --- a/bin/events2md.pl +++ b/bin/events2md.pl @@ -11,7 +11,6 @@ use FindBin qw($Bin); use POSIX qw(locale_h); use locale; -use Encode qw(decode_utf8); # TODO: modernize CalDAV access instead use Net::Netrc; use List::Util qw(first); @@ -71,20 +70,17 @@ class Calendar { $set->start, $set->end ) if $set; - my @events = sort { - DateTime->compare( $a->begin, $b->begin ) - || DateTime->compare( $a->end, $b->end ) + my @events = map { Event->new( entry => $_ ) } sort { + $a->start->compare( $b->start ) + || $a->start->compare( $b->start ) || $a->summary cmp $b->summary - } map { Event->new( entry => $_ ) } - $data->events( $set || (), $period || () ); + } $data->events( $set || (), $period || () ); return @events; } } class Event { - use Encode qw(decode_utf8); # TODO: modernize CalDAV access instead - field $log = Log::Any->get_logger; field $entry : param; @@ -98,18 +94,9 @@ class Event { field $datespan : reader; field $timespan : reader; field $time_brief : reader; - field $summary : reader - = $entry->property('summary') - ? decode_utf8 $entry->property('summary')->[0]->value - : ''; - field $description : reader - = $entry->property('description') - ? decode_utf8 $entry->property('description')->[0]->value - : ''; - field $location : reader - = $entry->property('location') - ? decode_utf8 $entry->property('location')->[0]->value - : ''; + field $summary : reader = $entry->summary; + field $description : reader = $entry->description; + field $location : reader = $entry->_simple_property('location'); field $price : reader; field @attendees; field @attachments; @@ -136,7 +123,7 @@ class Event { if ( $entry->property('attendee') ) { for ( @{ $entry->property('attendee') } ) { - push @attendees, decode_utf8 $_->parameters->{'CN'} + push @attendees, $_->parameters->{'CN'} || $_->value =~ s/^mailto://r; } } -- cgit v1.2.3