Changeset 320

Show
Ignore:
Timestamp:
05/29/06 17:28:49 (2 years ago)
Author:
ogawa
Message:

Support $ENCODE_NCR option for outputing as Numerical Character Reference.
And now support events which don't have endtime.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • cybozu2ical/trunk/cybozu2ical

    r318 r320  
    77use YAML; 
    88use LWP::UserAgent; 
    9 use Encode
     9use Encode qw/from_to decode_utf8 encode_utf8/
    1010use Text::CSV_XS; 
    1111use Data::ICal; 
     
    1919 
    2020our $VERSION = '0.04'; 
     21our $ENCODE_NCR = 1; 
    2122 
    2223my %opt = (conf => 'config.yaml'); 
     
    4243 
    4344my $content = $res->content; 
    44 Encode::from_to($content, 'shiftjis', 'utf8'); 
     45from_to($content, 'shiftjis', 'utf8'); 
    4546my @lines = grep /^\d+,ts\.\d+,/, split(/\r?\n/, $content); 
    4647 
     
    6970        warn "Recurrent events[$freq] cannot be handled."; 
    7071    } 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        } 
    7883        $vevent->add_properties(dtstart => $dtstart, dtend => $dtend); 
    7984    } 
     
    8388 
    8489    $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] || ''), 
    8792        dtstamp => $dtstamp, 
    8893        created => $created 
     
    112117$vcalendar->add_entry($vtimezone); 
    113118 
    114 print Encode::encode_utf8($vcalendar->as_string); 
     119print $ENCODE_NCR ? 
     120    encode_ncr($vcalendar->as_string) : 
     121    encode_utf8($vcalendar->as_string); 
     122 
     123sub encode_ncr { 
     124    my $text = shift; 
     125    $text =~ s/(\P{ASCII})/sprintf("&#%d;", ord($1))/eg; 
     126    $text; 
     127
    115128 
    116129sub cydate2dt {