diff options
author | Jonas Smedegaard <dr@jones.dk> | 2021-06-29 12:59:57 +0200 |
---|---|---|
committer | Jonas Smedegaard <dr@jones.dk> | 2021-06-29 12:59:57 +0200 |
commit | 4c88c47a4bac711f57c2fd7f8f7a2302a334b9c2 (patch) | |
tree | 891aeaf3b7de32c43e481f7e0d0d500e9b3297b7 | |
parent | ff72593bf6b3e55b3543d804a9ec0e4d601992fb (diff) |
simplify event sorting using the Schwartzian Transform
-rwxr-xr-x | bin/events2md.pl | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/bin/events2md.pl b/bin/events2md.pl index 84880af..847b7b9 100755 --- a/bin/events2md.pl +++ b/bin/events2md.pl @@ -22,7 +22,7 @@ use Cal::DAV; use Data::ICal; use iCal::Parser; use List::Util qw(first); -use List::MoreUtils qw(nsort_by sort_by); +use List::MoreUtils qw(nsort_by qsort); use DateTime; use Try::Tiny; use Path::Tiny; @@ -161,21 +161,20 @@ for my $year ( map { $_->value } { for my $month ( map { $_->value } nsort_by { $_->key } pairs %$year ) { for my $day ( map { $_->value } nsort_by { $_->key } pairs %$month ) { - for ( - sort_by { - $_->value->{DTSTART} - . $_->value->{DTEND} - . ( $_->value->{SUMMARY} || '' ) - } - pairs %$day - ) - { - print_event( - $calendar_entries{VEVENT}{ $_->key }, - $_->value->{DTSTART}, - $_->value->{DTEND}, - $output_path, - ); + my @events = map { + [ $calendar_entries{VEVENT}{$_}, + $day->{$_}{DTSTART}, $day->{$_}{DTEND} + ] + } keys %$day; + qsort { + 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' ) + } + @events; + for (@events) { + print_event( $_->[0], $_->[1], $_->[2], $output_path, ); } } } |