Subject: | events timezone is ignored |
Date: | Fri, 15 Oct 2010 16:55:21 +0200 |
To: | bug-iCal-Parser [...] rt.cpan.org |
From: | Vladimir Marek <Vladimir.Marek [...] oracle.com> |
Hi,
Thanks for iCal::Parser!
After some investigation I have found out that timezone of an event is
being ignored while passing the date to DateTime::Format::ICal in the
convert_value function.
The event looks like this:
TYPE: DTEND
$VAR1 = {
'value' => '20100903T093000',
'param' => {
'TZID' => 'America/Los_Angeles'
}
};
DateTime::Format::ICal can parse strings containing timezone in the
format "TZID=America/Los_Angeles:20100903T093000".
I fixed the issue locally via this patch:
--- /tmp/vm156888/x/perl-5.12.2/lib/site_perl/5.12.2/iCal/Parser.pm pá říj 15 16:45:29 2010
+++ /tmp/vm156888/x/perl-5.12.2/lib/site_perl/5.12.2/iCal/Parser.pm.good2 pá říj 15 16:42:12 2010
@@ -229,10 +229,13 @@
my($self,$type,$hash)=@_;
my $value=$hash->{value};
+ my $this_tz="";
+ $this_tz="TZID=$hash->{param}{TZID}:" if defined $hash->{param}{TZID};
return $value unless $value; #should protect from invalid datetimes
if ($type eq 'TRIGGER') {
#can be date or duration!
+ $value="$this_tz$value";
return $dfmt->parse_duration($value) if $value =~/^[-+]?P/;
return $dfmt->parse_datetime($value)->set_time_zone($self->{tz});
}
@@ -241,7 +244,9 @@
map { $h{$_}=$hash->{param}{$_} } keys %{ $hash->{param} };
return \%h;
}
- return $dfmt->parse_duration($value) if $TYPES{durations}{$type};
+ if ($TYPES{durations}{$type}) {
+ return $dfmt->parse_duration($this_tz.$value);
+ }
return $value unless $TYPES{dates}{$type};
#mozilla calendar bug: negative dates on todos!
@@ -255,10 +260,11 @@
# so, handle the exception
my $date;
eval {
- $date=$dfmt->parse_datetime($s)->set_time_zone($self->{tz});
+ $date=$dfmt->parse_datetime($this_tz.$s)->set_time_zone($self->{tz});
};
push @dates, $date and next unless $@;
die $@ if $@ && $type ne 'DTEND';
+ $value="$this_tz$value";
push @dates,
$dfmt->parse_datetime(--$value)->set_time_zone($self->{tz});
}
But I am not convinced that it's completely correct fix.
a) ... if $value =~/^[-+]?P/; will be broken if timezone is prepended
to $value
b) I do not uderstand what $dfmt->parse_datetime(--$value) does, resp.
the --$value ...
So with the hope that you'll be able to fix it properly I'm sending what
I currently have :)
Thank you
--
Vlad