X-Git-Url: http://git.refcnt.org/?p=lugs.git;a=blobdiff_plain;f=make-ical%2Fmake-ical.pl;h=8d6855ed49b84106fffa3ebdcb69c18836ee026d;hp=2510d09ad78eaf1e6cca6a1cd6c5a35417cc232c;hb=46037c5e006f506768674a0b5f2bc2fd75e65153;hpb=f03ccc18f5ea460ffe5f6be40f422e5fd05b5e7a diff --git a/make-ical/make-ical.pl b/make-ical/make-ical.pl index 2510d09..8d6855e 100755 --- a/make-ical/make-ical.pl +++ b/make-ical/make-ical.pl @@ -15,16 +15,16 @@ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # # Author: Steven Schubiger -# Last modified: Sun Jul 21 22:23:31 CEST 2013 +# Last modified: Wed Dec 27 21:42:20 CET 2017 use strict; use warnings; use lib qw(lib); -my $VERSION = '0.02'; +my $VERSION = '0.05'; 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,6 +45,7 @@ use constant false => 0; use Data::ICal (); use Data::ICal::Entry::Event (); use Date::ICal (); +use DateTime (); use Encode qw(encode); use File::Spec (); use HTML::Entities qw(decode_entities); @@ -109,26 +110,40 @@ sub process_events 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( - year => $year, - month => $month, - day => $day, - hour => $time{start_hour}, - min => $time{start_min}, - sec => 00, - )->ical(offset => $offset), + year => $year, + month => $month, + day => $day, + hour => $time{start_hour}, + min => $time{start_min}, + sec => 00, + offset => $get_offset->(@time{qw(start_hour start_min)}), + )->ical, dtend => Date::ICal->new( - year => $year, - month => $month, - day => $day, - hour => $time{end_hour}, - min => $time{end_min}, - sec => 00, - )->ical(offset => $offset), + year => $year, + month => $month, + day => $day, + hour => $time{end_hour}, + min => $time{end_min}, + sec => 00, + offset => $get_offset->(@time{qw(end_hour end_min)}), + )->ical, location => $location, summary => $summary, defined $more ? (