Mercurial > hg > Applications > Calcon
changeset 20:3fcdab33e15d
iCal fix
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 11 Oct 2013 11:27:03 +0900 |
parents | 7dfd5644478b |
children | cc4f95f742f7 |
files | Calcon.pm |
diffstat | 1 files changed, 69 insertions(+), 48 deletions(-) [+] |
line wrap: on
line diff
--- a/Calcon.pm Fri Oct 11 09:25:35 2013 +0900 +++ b/Calcon.pm Fri Oct 11 11:27:03 2013 +0900 @@ -2890,25 +2890,30 @@ # if ($record{'date'}->is_allday() && $self->{'-fake-allday'}) { # $record{'date'}=$record{'date'}->add($self->{'-time-for-allday'}); # } - my $dtstart = "\r\nDTSTART;TZID=$timezone:".$self->date($record{'date'}); + my $dtstart = "\nDTSTART;TZID=$timezone:".$self->date($record{'date'}); my $dtend = ''; my $dtstamp = ''; - if (! $record{'date'}->is_allday()) { + if (! $record{'date'}->is_allday() || ! $record{'all-day'} eq 'true') { if (! defined( $record{'end-date'}) || $record{'end-date'} == $record{'date'} ) { # $dtend = "\nDURATION:PT2H"; this is useless for iCal $record{'end-date'} = $record{'date'}->add( $self->{'-add-time-for-allday'}); - $dtend = "\r\nDTEND;TZID=$timezone:".$self->date($record{'end-date'}); + $dtend = "\nDTEND;TZID=$timezone:".$self->date($record{'end-date'}); } else { - $dtend = "\r\nDTEND;TZID=$timezone:".$self->date($record{'end-date'}); + $dtend = "\nDTEND;TZID=$timezone:".$self->date($record{'end-date'}); } } else { - $dtend = ''; - # $dtstart =~ s/T000000$//; + $dtstart = $self->date($record{'date'}); + $dtstart =~ s/T\d+$//; + $dtstart= "\nDTSTART;VALUE=DATE:$dtstart"; + + $dtend = $self->date($record{'date'}->add(24*60*60)); + $dtend =~ s/T\d+$//; + $dtend = "\nDTEND;VALUE=DATE:$dtend"; } if (defined( $record{'modify-date'})) { - $dtstamp = "\r\nDTSTAMP:".$self->date($record{'modify-date'})."Z"; + $dtstamp = "\nDTSTAMP;TZID=$timezone:".$self->date($record{'modify-date'}); } my $summary = ''; @@ -2921,12 +2926,15 @@ $summary =~ s/[\n\r]/ /mg; $summary =~ s/\s*$//; } + if (defined($record{'summary'})) { + $summary = $summary . $record{'summary'}; + } if ($description eq $summary) { $description = ""; } else { if ($description) { - $description = "\r\nDESCRIPTION: $description"; + # $description = "\nDESCRIPTION: $description"; } } return if (! $description && ! $summary ); @@ -2937,11 +2945,11 @@ # SEQUENCE:$i $self->print(<<"EOFEOF"); -BEGIN:VEVENT\r -SUMMARY:$summary$dtstart$dtend$description$dtstamp\r -END:VEVENT\r +BEGIN:VEVENT +SUMMARY:$summary$dtstart$dtend$description$dtstamp +END:VEVENT EOFEOF -# print "\r\n"; +# print "\n"; } sub date { @@ -2978,8 +2986,8 @@ $record{'end-time'} = $2; } - print "BEGIN:VCARD\r\n"; - print "VERSION:3.0\r\n"; + print "BEGIN:VCARD\n"; + print "VERSION:3.0\n"; if(defined $record{'name'}) { $data = $record{'name'}; if(0 && defined $record{'name-yomi'}) { @@ -3012,7 +3020,7 @@ if(defined $record{'section'}) { $data .= ";".$record{'section'}; } - print "ORG:$data\r\n" if($data); + print "ORG:$data\n" if($data); } if(defined $record{'title'}) { $data = "$record{'title'}"; @@ -3033,19 +3041,19 @@ } if(defined $record{'tel'}) { $data = $record{'tel'}; - print "TEL;TYPE=WORK:$data\r\n" if($data); + print "TEL;TYPE=WORK:$data\n" if($data); } if(defined $record{'tel2'}) { $data = $record{'tel2'}; - print "TEL;TYPE=CELL:$data\r\n" if($data); + print "TEL;TYPE=CELL:$data\n" if($data); } if(defined $record{'fax'}) { $data = $record{'fax'}; - print "TEL;TYPE=FAX:$data\r\n" if($data); + print "TEL;TYPE=FAX:$data\n" if($data); } if(defined $record{'mail'}) { $data = $record{'mail'}; - print "EMAIL;INTERNET:$data\r\n" if($data); + print "EMAIL;INTERNET:$data\n" if($data); } if(defined $record{'memo'}) { $data = $record{'memo'}; @@ -3053,18 +3061,18 @@ } if(defined $record{'birth'}) { $data = $record{'birth'}; - print "BDAY:".$data->date()."\r\n" if($data); + print "BDAY:".$data->date()."\n" if($data); } if(defined $record{'name-yomi'}) { $data = $record{'name-yomi'}; - print "X-CUSTOM1:$data\r\n" if($data); + print "X-CUSTOM1:$data\n" if($data); } if(defined $record{'office-yomi'}) { $data = $record{'office-yomi'}; - print "X-CUSTOM2:$data\r\n" if($data); + print "X-CUSTOM2:$data\n" if($data); } - print "END:VCARD\r\n"; - print "\r\n"; + print "END:VCARD\n"; + print "\n"; } #######################################################################/ @@ -3115,25 +3123,25 @@ if(defined($record{'office-yomi'})) { $record{'office-yomi'} =~ s/^ *//; } - $self->print("BEGIN:VCARD\r\n"); - $self->print("VERSION:3.0\r\n"); + $self->print("BEGIN:VCARD\n"); + $self->print("VERSION:3.0\n"); if(defined $record{'name'}) { $data = $record{'name'}; $self->print("FN:$data\n") if($data); if(0 && defined $record{'name-yomi'}) { $data = join(";",split(/ /,$record{'name-yomi'})); - $self->print("N:$data\r\n") if($data); + $self->print("N:$data\n") if($data); } else { $data = join(";",split(/ /,$data)); - $self->print("N:$data\r\n") if($data); + $self->print("N:$data\n") if($data); } if(defined $record{'name-yomi'}) { my ($last , $first , $last_yomi , $first_yomi ); $last = $first = $last_yomi = $first_yomi = ''; ($last,$first) = split(/ /,$record{'name'}); ($last_yomi,$first_yomi) = split(/ /,$record{'name-yomi'}), - $self->print("X-PHONETIC-LAST-NAME:$last_yomi\r\n"); - $self->print("X-PHONETIC-FIRST-NAME:$first_yomi\r\n"); + $self->print("X-PHONETIC-LAST-NAME:$last_yomi\n"); + $self->print("X-PHONETIC-FIRST-NAME:$first_yomi\n"); } # print "fn:$data\n" if($data); @@ -3145,11 +3153,11 @@ # my $cat = 0; if(defined $record{'group'}) { $data = "$record{'group'}"; - $self->print("CATEGORIES:$data\r\n") if($data); + $self->print("CATEGORIES:$data\n") if($data); } if(defined $record{'office'}) { $data = "$record{'office'}"; - $self->print("ORG:$data;\r\n") if($data); + $self->print("ORG:$data;\n") if($data); # if ($cat==0) { # $self->print("CATEGORIES:$data\n") if($data); # } @@ -3159,8 +3167,8 @@ $title = $record{'section'}; } if(defined $record{'title'}) { - $title .= ($title?'\r\n':'')."$record{'title'}"; - $self->print("TITLE:$data\r\n") if($data); + $title .= ($title?'\n':'')."$record{'title'}"; + $self->print("TITLE:$data\n") if($data); } if(defined $record{'address'}) { my $i = $self->{'item'}++; @@ -3177,27 +3185,27 @@ if(defined $record{'tel'}) { # my $i = $self->{'item'}++; $data = $record{'tel'}; - $self->print("TEL;TYPE=WORK:$data\r\n") if($data); + $self->print("TEL;TYPE=WORK:$data\n") if($data); } if(defined $record{'mobile-tel'}) { # my $i = $self->{'item'}++; $data = $record{'mobile-tel'}; - $self->print("TEL;TYPE=CELL:$data\r\n") if($data); + $self->print("TEL;TYPE=CELL:$data\n") if($data); } if(defined $record{'home-tel'}) { # my $i = $self->{'item'}++; $data = $record{'tel'}; - $self->print("TEL;TYPE=HOME:$data\r\n") if($data); + $self->print("TEL;TYPE=HOME:$data\n") if($data); } if(defined $record{'tel2'}) { # my $i = $self->{'item'}++; $data = $record{'tel2'}; - $self->print("TEL;TYPE=CELL:$data\r\n") if($data); + $self->print("TEL;TYPE=CELL:$data\n") if($data); } if(defined $record{'fax'}) { # my $i = $self->{'item'}++; $data = $record{'fax'}; - $self->print( "TEL;TYPE=FAX:$data\r\n") if($data); + $self->print( "TEL;TYPE=FAX:$data\n") if($data); } if(defined $record{'home-address'}) { my $i = $self->{'item'}++; @@ -3215,20 +3223,20 @@ if(defined $record{'mail2'}) { # my $i = $self->{'item'}++; $data = $record{'mail2'}; - $self->print("EMAIL;TYPE=internet;TYPE=HOME:$data\r\n") if($data); + $self->print("EMAIL;TYPE=internet;TYPE=HOME:$data\n") if($data); } if(defined $record{'mail'}) { # my $i = $self->{'item'}++; $data = $record{'mail'}; - $self->print("EMAIL;TYPE=internet;TYPE=PREF:$data\r\n") if($data); + $self->print("EMAIL;TYPE=internet;TYPE=PREF:$data\n") if($data); } if(defined $record{'birth'}) { $data = $record{'birth'}; - $self->print("BDAY:".$data->date()."\r\n") if($data); + $self->print("BDAY:".$data->date()."\n") if($data); } if(defined $record{'memo'}) { $data = $record{'memo'}; - $self->print("NOTE:$data\r\n") if($data); + $self->print("NOTE:$data\n") if($data); } # if(defined $record{'name-yomi'}) { # $data = $record{'name-yomi'}; @@ -3238,8 +3246,8 @@ # $data = $record{'office-yomi'}; # $self->print "x-custom2:$data\n" if($data); # } - $self->print("END:VCARD\r\n"); - $self->print("\r\n"); + $self->print("END:VCARD\n"); + $self->print("\n"); } package Calcon::Vcard_N702iD_write; @@ -4227,6 +4235,9 @@ } elsif (/^X-ABUID:/i) { } elsif (/^note:\s*(.*)/i) { $record->{'memo'} .= $1; } elsif (/^dtend(.*):\s*(.*)/i) { $record->{'end-date'} = $self->date($2,$1?$1:$record->{'timezone'}); + if (//) { + $record->{'all-day'} = 'true'; + } } elsif (/^dtstamp(.*):\s*(.*)/i) { $record->{'modify-date'} = $self->date($2,$1?$1:$record->{'timezone'}); } elsif (/^dtstart(.*):\s*(.*)/i) { $record->{'date'} = $self->date($2,$1?$1:$record->{'timezone'}); } elsif (/^duration:\s*(.*)/i) { $self->duration($record,$1); @@ -4258,10 +4269,14 @@ } elsif (/^item\d+(.*):\s*(.*)/i) { $self->items($record,'address',$1,$2); } else { chop; - if ($record->{'extra'}) { $record->{'extra'} .= "\n "; } - $record->{'extra'} .= $_; + if (/^ /) { + $record->{'memo'} .= $_; + } else { + if ($record->{'extra'}) { $record->{'extra'} .= "\n "; } + $record->{'extra'} .= $_; + } } - } +} $out->end_file(''); } @@ -4288,6 +4303,12 @@ my $out = $self->{'-output'}; my $keys = []; push(@$keys,keys %{$record}); + if (defined $record->{'date'} && defined $record->{'end-date'} ) { + if ($record->{'end-date'}->date_after($record->{'date'} )) { + print STDERR "end-date before start ".$record->{'date'}->date()," end on ",$record->{'end-date'}->date(),"\n"; + undef $record->{'end-date'}; + } + } $out->record($keys,$record); }