]> git.refcnt.org Git - lugs.git/blobdiff - make-ical/make-ical.pl
make-ical: adapt to encoding fix
[lugs.git] / make-ical / make-ical.pl
index 8be3637aa02c3b46249d5ac334795d5cbc84e871..e3a338f6dea9443fedeaae9c662f9f15286dc9a5 100755 (executable)
 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 #
 # Author: Steven Schubiger <stsc@refcnt.org>
-# Last modified: Fri Apr 17 23:12:38 CEST 2015
+# Last modified: Wed 09 Jun 2021 10:05:08 PM CEST
 
 use strict;
 use warnings;
 use lib qw(lib);
 
-my $VERSION = '0.03';
+my $VERSION = '0.06';
 
 my $Config = {
-    base_url => 'http://www.lugs.ch/lugs/termine',
+    base_url => 'https://www.lugs.ch/lugs/termine',
     input    => './termine.txt',
     ical_dir => 'ical',
     offset   => undef,
@@ -45,9 +45,8 @@ use constant false => 0;
 use Data::ICal ();
 use Data::ICal::Entry::Event ();
 use Date::ICal ();
-use Encode qw(encode);
+use DateTime ();
 use File::Spec ();
-use HTML::Entities qw(decode_entities);
 use LUGS::Events::Parser ();
 
 sub new
@@ -106,11 +105,20 @@ sub process_events
         $location =~ s/\(.+?\)//g;
         $more =~ s/<.+?>//g if defined $more;
 
-        sub { decode_entities($_) foreach @_      }->($location, $summary, defined $more ? $more : ());
-        sub { $_ = encode('UTF-8', $_) foreach @_ }->($location, $summary, defined $more ? $more : ());
-
-        my $offset = $Config->{offset} ? $Config->{offset} : ((localtime)[8] ? '+0200' : '+0100');
-
+        my $get_offset = sub
+        {
+            my ($hour, $minute) = @_;
+            return $Config->{offset} if $Config->{offset};
+            my $dt = DateTime->new(
+                year      => $year,
+                month     => $month,
+                day       => $day,
+                hour      => $hour,
+                minute    => $minute,
+                time_zone => 'Europe/Zurich',
+            );
+            return $dt->is_dst() ? '+0200' : '+0100';
+        };
         $ical_event->add_properties(
             dtstamp => Date::ICal->new->ical,
             dtstart => Date::ICal->new(
@@ -120,7 +128,7 @@ sub process_events
                 hour   => $time{start_hour},
                 min    => $time{start_min},
                 sec    => 00,
-                offset => $offset,
+                offset => $get_offset->(@time{qw(start_hour start_min)}),
             )->ical,
             dtend => Date::ICal->new(
                 year   => $year,
@@ -129,7 +137,7 @@ sub process_events
                 hour   => $time{end_hour},
                 min    => $time{end_min},
                 sec    => 00,
-                offset => $offset,
+                offset => $get_offset->(@time{qw(end_hour end_min)}),
             )->ical,
             location    => $location,
             summary     => $summary,