diff options
author | Jonas Smedegaard <dr@jones.dk> | 2021-06-29 12:59:57 +0200 |
---|---|---|
committer | Jonas Smedegaard <dr@jones.dk> | 2024-08-27 23:39:36 +0200 |
commit | 687b7dfed82d0c7aa9aaaee72265e451f2f39240 (patch) | |
tree | 82df4a97d7f92f362d8e83e0f31b5207f0c63ce8 | |
parent | ab4c1e0b149a31e819ad6f1513ce14e6325cf566 (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, ); } } } |