Changeset 374

Show
Ignore:
Timestamp:
06/15/07 20:02:37 (18 months ago)
Author:
ogawa
Message:

Add premilinary support for EXDATE.

Location:
cybozu2ical/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • cybozu2ical/trunk/cybozu2ical

    r372 r374  
    2020our $VERSION = '0.12'; 
    2121 
     22### TRICK (stop escaping for 'exdate' property) 
     23*Data::ICal::Property::_value_as_string = sub { 
     24    my $self = shift; 
     25    my $key = shift; 
     26    my $value = defined($self->value()) ? $self->value() : ''; 
     27     
     28    unless ($self->vcal10) { 
     29        my $lc_key = lc($key); 
     30        $value =~ s/\\/\\/gs; 
     31        $value =~ s/\Q;/\\;/gs unless ($lc_key eq 'rrule' || $lc_key eq 'exdate'); 
     32        $value =~ s/,/\\,/gs unless ($lc_key eq 'rrule' || $lc_key eq 'exdate'); 
     33        $value =~ s/\n/\\n/gs; 
     34        $value =~ s/\\N/\\N/gs; 
     35    } 
     36 
     37    return $value; 
     38 
     39}; 
     40### END 
     41 
    2242my %opt = (conf => 'config.yaml'); 
    2343GetOptions(\%opt, 'help', 'debug', 'conf=s') or pod2usage(2); 
     
    6080    # handle frequency 
    6181    if ($item->can('frequency')) { 
     82        # rrule 
    6283        my $freq = $item->frequency; 
    6384        my %rrules = $freq ne 'WEEKDAYS' ? 
     
    6788            if $item->until; 
    6889        $args{rrule} = join ';', map { $_ . '=' . $rrules{$_} } keys %rrules; 
     90 
     91        # exdate 
     92#       $args{exdate} = join ',', map { to_icaldate($_, 1) } $item->exdates 
     93#           if $item->exdates; 
     94        if ($item->exdates) { 
     95            if ($item->is_full_day) { 
     96                $args{exdate} = [join(',', map { to_icaldate($_, 1) } $item->exdates), { VALUE => 'DATE' }]; 
     97            } else { 
     98                $args{exdate} = [join(',', map { to_icaldate($_, 0) } $item->exdates), { TZID => $time_zone }]; 
     99            } 
     100        } 
     101 
    69102    } 
    70103 
  • cybozu2ical/trunk/lib/WWW/CybozuOffice6/Calendar.pm

    r373 r374  
    5252            or die 'Failed to parse CSV input'; 
    5353        my @fields = $csv->fields; 
    54         next if $#fields < 13; # num. of fields 
     54        my $num_fields = @fields - 1; 
     55        next if $num_fields < 13; 
    5556        $fields[1] =~ s/^ts\.//; # remove rubbish 
    5657 
     
    5960        # [ 0] id?         | id? 
    6061        # [ 1] created     | created 
    61         # [ 2] <BLANK>     x start_date 
    62         # [ 3] start_date  x end_date 
     62        # [ 2] <BLANK>     x modified start_date 
     63        # [ 3] start_date  x start_date / end_date 
    6364        # [ 4] end_date    x until_date 
    6465        # [ 5] start_time  | start_time 
     
    8182            $item = WWW::CybozuOffice6::Calendar::Event->new(%param); 
    8283        } else { 
    83             @param{qw(start_date end_date until_date)} = @fields[2..4]; 
     84            @param{qw(start_date end_date until_date)} = @fields[3,3,4]; 
     85            if ($num_fields > 13) { 
     86                my @exdates = @fields[14..$num_fields]; 
     87                $param{exdates} = \@exdates; 
     88            } 
    8489            $item = WWW::CybozuOffice6::Calendar::RecurrentEvent->new(%param); 
    8590        } 
     
    194199sub until               { shift->_accessor('until',             @_) } 
    195200 
     201sub exdates { 
     202    my $this = shift; 
     203    return unless $this->{exdates}; 
     204    my $dates = $this->{exdates}; 
     205    wantarray ? @$dates : @$dates[0]; 
     206} 
     207 
    196208our %FREQUENCY = ( y => 'YEARLY', m => 'MONTHLY', w => 'WEEKLY', 
    197209                   d => 'DAILY', n => 'WEEKDAYS' ); 
     
    207219    $this->{frequency_value} = $param{freq_value} || 0; 
    208220 
     221    # until 
    209222    if ($param{until_date} =~ m!^(\d+)/(\d+)/(\d+)$!) { 
    210223        my %args = (year => $1, month => $2, day => $3); 
     
    218231        $this->{until} = $until; 
    219232    } 
     233 
     234    # exdates 
     235    if (defined $param{exdates}) { 
     236        my @dates; 
     237        for (@{$param{exdates}}) { 
     238            push @dates, $this->to_datetime($_, $param{start_time}); 
     239        } 
     240        $this->{exdates} = \@dates; 
     241    } 
     242 
    220243    1; 
    221244}