diff options
author | Jonas Smedegaard <dr@jones.dk> | 2024-08-28 16:26:53 +0200 |
---|---|---|
committer | Jonas Smedegaard <dr@jones.dk> | 2024-08-28 17:13:39 +0200 |
commit | ad289d23b089793cd0a43f7c145bf0846a827257 (patch) | |
tree | d480b832acce3385ec1b5d99454c3e93a84c088e | |
parent | 567f3470bd2d825e1af39ae6db398936c61486ed (diff) |
simplify vCalendar format juggling, thanks to Data::ICal::DateTime
-rwxr-xr-x | bin/events2md.pl | 29 |
1 files 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; } } |