Changeset 320
- Timestamp:
- 05/29/06 17:28:49 (2 years ago)
- Files:
-
- cybozu2ical/trunk/cybozu2ical (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
cybozu2ical/trunk/cybozu2ical
r318 r320 7 7 use YAML; 8 8 use LWP::UserAgent; 9 use Encode ;9 use Encode qw/from_to decode_utf8 encode_utf8/; 10 10 use Text::CSV_XS; 11 11 use Data::ICal; … … 19 19 20 20 our $VERSION = '0.04'; 21 our $ENCODE_NCR = 1; 21 22 22 23 my %opt = (conf => 'config.yaml'); … … 42 43 43 44 my $content = $res->content; 44 Encode::from_to($content, 'shiftjis', 'utf8');45 from_to($content, 'shiftjis', 'utf8'); 45 46 my @lines = grep /^\d+,ts\.\d+,/, split(/\r?\n/, $content); 46 47 … … 69 70 warn "Recurrent events[$freq] cannot be handled."; 70 71 } else { 71 my $dt = cydate2dt($fields[3], $fields[5], $tz); 72 my $dtstart = ($fields[5] !~ /^:$/) ? 73 dt2ical($dt) : $dt->ymd(''); 74 $dt = cydate2dt($fields[4], $fields[6], $tz); 75 my $dtend = ($fields[6] !~ /^:$/) ? 76 dt2ical($dt) : $dt->add(days => 1)->ymd(''); 77 72 my ($dtstart, $dtend); 73 my $dt0 = cydate2dt($fields[3], $fields[5], $tz); 74 my $dt1 = cydate2dt($fields[4], $fields[6], $tz); 75 if ($fields[5] =~ /^:$/) { 76 $dtstart = $dt0->ymd(''); 77 $dtend = $dt1->add(days => 1)->ymd(''); 78 } else { 79 $dtstart = dt2ical($dt0); 80 $dtend = ($fields[6] =~ /^:$/) ? 81 $dt0->add(minutes => 10) : dt2ical($dt1); 82 } 78 83 $vevent->add_properties(dtstart => $dtstart, dtend => $dtend); 79 84 } … … 83 88 84 89 $vevent->add_properties( 85 summary => Encode::decode_utf8($fields[12] || ''),86 description => Encode::decode_utf8($fields[13] || $fields[12] || ''),90 summary => decode_utf8($fields[12] || ''), 91 description => decode_utf8($fields[13] || $fields[12] || ''), 87 92 dtstamp => $dtstamp, 88 93 created => $created … … 112 117 $vcalendar->add_entry($vtimezone); 113 118 114 print Encode::encode_utf8($vcalendar->as_string); 119 print $ENCODE_NCR ? 120 encode_ncr($vcalendar->as_string) : 121 encode_utf8($vcalendar->as_string); 122 123 sub encode_ncr { 124 my $text = shift; 125 $text =~ s/(\P{ASCII})/sprintf("&#%d;", ord($1))/eg; 126 $text; 127 } 115 128 116 129 sub cydate2dt {
