-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

>> Has anyone successfully parsed a iCal.app .ics file using Net::ICal?
>> (Date::Ical does not address the entire file format, Net::ICal does)
>>
>> This script:
>>
>> #!/usr/bin/perl
>> use Net::ICal;
>> $icalStr = `cat /Users/alex/Library/Calendars/ARCtime.ics`;
>> my $cal = Net::ICal::Calendar->new_from_ical($icalStr) || die $!;
>>
>> Dies with output:  [slightly cleaned up -- c.d.]
>>
>> Invalid duration: seconds at /Library/Perl/Net/ICal/Component.pm
>>     line 697
>> Invalid duration: seconds at /Library/Perl/Net/ICal/Component.pm
>>     line 697
>> Invalid duration: seconds at /Library/Perl/Net/ICal/Component.pm
>>     line 697

I had a look at the t/time.t in the Net::ICal distribution. It looks 
like it's giving the above error because Net::ICal::Time is a subclass 
of Date::ICal but does not seem to handle the ::add method properly. It 
assumes that it's only ever going to receive one argument (a duration), 
when in fact Date::ICal::add assumes a list of key-value pairs.

I patched my copy of Net::ICal::Time to handle this properly (by my 
quickly-determined, probably-wrong version of "properly" :), but then 
some other tests broke, because Date::ICal was now applying the 
timezone offset to the date format given in Net::ICal::Time::new, but 
the tests expect it not to. This contradicts the documentation, which 
says that Net::ICal::Time, if called like

     my $time = Net::ICal::Time->new(ical => $ical_format_str);

should treat $ical_format_str as if it's in UTC, unless specified 
otherwise. But it's not treating it as UTC unless it ends in 'Z'.

Anyway, that's about when I gave up, because obviously I have no idea 
of the history of these modules. But the patch to "fix" 
Net::ICal::Time::add is below--it's by no means perfect, because 
Date::ICal::add can conceivably take just one parameter as an argument, 
and it would mean something entirely different than an ICal duration... 
it almost seems like Net::ICal::Time::add might be better renamed 
Net::ICal::Time::add_duration to make it clear what's happening. But 
maybe it needs to override Date::ICal::add. I don't know.

bye,
Ben


- --- Time.pm.orig        Wed Sep 18 00:23:10 2002
+++ Time.pm     Wed Sep 18 00:31:01 2002
@@ -193,19 +193,23 @@

  =cut
  sub add {
- -  my ($self, $param) = @_;
- -
- -  # FIXME: need input validation here
- -  my $duration = $param;
+  my $self = shift;
+
+  if (@_ == 1) {
+    # FIXME: need input validation here
+    my $duration = shift;

- -  # be backwards-compatible for now.
- -  if (UNIVERSAL::isa($param,'Net::ICal::Duration')) {
- -    #probably the Wrong Way, but it works for now.
- -    $duration = $param->as_ical_value;
- -  };
+    # be backwards-compatible for now.
+    if (UNIVERSAL::isa($duration,'Net::ICal::Duration')) {
+      #probably the Wrong Way, but it works for now.
+      $duration = $duration->as_ical_value;
+    };

- -  # at this point, assume that duration is an iCalendar string.
- -  return $self->SUPER::add(duration=>$duration);
+    # at this point, assume that duration is an iCalendar string.
+    return $self->SUPER::add(duration=>$duration);
+  } else {
+    return $self->SUPER::add(@_);
+  }

  }
  
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (Darwin)

iD8DBQE9iC9MzGeEk2uv818RAq0cAKC77huAQ4SZi0130heWGeK4QRVOPACfW1S6
lF0ALvJIesFGX2+3qm6TqhU=
=EVBI
-----END PGP SIGNATURE-----

Reply via email to