Changeset 518 for cybozu2ical/trunk/lib

Show
Ignore:
Timestamp:
09/01/08 19:33:58 (4 months ago)
Author:
ogawa
Message:

Use accessors instead of directly accessing object fields.
Modify Event constructors' parameters so as to be subjected to Cybozu scripting.

Location:
cybozu2ical/trunk/lib/WWW/CybozuOffice6
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • cybozu2ical/trunk/lib/WWW/CybozuOffice6/Calendar/Event.pm

    r505 r518  
    1919 
    2020__PACKAGE__->mk_accessors( 
    21     qw( id start end summary description created modified is_full_day comment ) 
     21    qw( id start end summary description created time_zone modified is_full_day comment ) 
    2222); 
    2323 
     
    2525    my ( $this, %param ) = @_; 
    2626 
    27     $this->{id}        = $param{id}        || '0'; 
    28     $this->{time_zone} = $param{time_zone} || 'Asia/Tokyo'; 
     27    $this->id( $param{id}               || '0' ); 
     28    $this->time_zone( $param{time_zone} || 'Asia/Tokyo' ); 
    2929 
    30     my $start = $this->to_datetime( $param{start_date}, $param{start_time} ); 
    31     my $end   = $this->to_datetime( $param{end_date},   $param{end_time} ); 
     30    my $start = $this->to_datetime( $param{set_date}, $param{set_time} ); 
     31    my $end   = $this->to_datetime( $param{end_date}, $param{end_time} ); 
    3232    return unless $start && $end; 
    3333 
    34     # (start_time == empty) => A full-day event 
    35     # (start_time != empty) && (end_time == empty) => A malformed event 
    36     if ( $param{start_time} eq ':' ) { 
     34    # (set_time == empty) => A full-day event 
     35    # (set_time != empty) && (end_time == empty) => A malformed event 
     36    if ( $param{set_time} eq ':' ) { 
    3737        $start = $start->truncate( to => 'day' ); 
    3838        $end = $end->add( days => 1 )->truncate( to => 'day' ); 
    39         $this->{is_full_day} = 1; 
     39        $this->is_full_day(1); 
    4040    } 
    4141    elsif ( $param{end_time} eq ':' ) { 
    4242        $end = $start->clone->add( minutes => 10 ); 
    4343    } 
    44     $this->{start} = $start; 
    45     $this->{end}   = $end; 
     44    $this->start($start); 
     45    $this->end($end); 
    4646 
    47     $this->{created} = DateTime->from_epoch( epoch => $param{created} || 0 ); 
     47    $param{timestamp} =~ s/^ts\.//;    # remove rubbish 
     48    $this->created( DateTime->from_epoch( epoch => $param{timestamp} || 0 ) ); 
    4849 
    4950    my $summary = 
    50       ( $param{abbrev} ? $param{abbrev} . ': ' : '' ) . $param{summary}; 
    51     $this->{summary} = $summary; 
    52     $this->{description} = $param{description} || $summary; 
     51      ( $param{event} ? $param{event} . ': ' : '' ) . $param{detail}; 
     52    $this->summary($summary); 
     53    $this->description( $param{memo} || $summary ); 
    5354    1; 
    5455} 
     
    7576    } 
    7677 
    77     $args{time_zone} = $this->{time_zone}; 
     78    $args{time_zone} = $this->time_zone; 
    7879 
    7980    DateTime->new(%args); 
  • cybozu2ical/trunk/lib/WWW/CybozuOffice6/Calendar/RecurrentEvent.pm

    r505 r518  
    2323    n => 'WEEKDAYS' 
    2424); 
     25our @WEEK_STRING = ( 'SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA' ); 
    2526 
    2627sub parse { 
     
    2829    $this->SUPER::parse(%param); 
    2930 
    30     # frequency 
    31     my $freq = $param{freq}; 
    32     return unless $freq && exists $FREQUENCY{$freq}; 
     31    my ( $type, $day ) = ( $param{type}, $param{day} ); 
     32    return 
     33      unless defined $type 
     34          && ( $type =~ /^[1-5]$/ || exists $FREQUENCY{$type} ); 
     35 
     36    ( $type, $day ) = ( 'm', $type . $WEEK_STRING[$day] ) 
     37      if $type =~ /^[1-5]$/; 
    3338 
    3439    # rrule 
    3540    my %rrule = (); 
    36     if ( $FREQUENCY{$freq} eq 'WEEKDAYS' ) { 
     41    if ( $FREQUENCY{$type} eq 'WEEKDAYS' ) { 
    3742        %rrule = ( FREQ => 'WEEKLY', BYDAY => 'MO,TU,WE,TH,FR' ); 
    3843    } 
    3944    else { 
    40         %rrule = ( FREQ => $FREQUENCY{$freq} ); 
     45        %rrule = ( FREQ => $FREQUENCY{$type} ); 
    4146    } 
    42     if ( $param{freq_value} =~ /^\d(SU|MO|TU|WE|TH|FR|SA)$/ ) { 
    43         $rrule{BYDAY}    = $param{freq_value}; 
     47    if ( $param{day} =~ /^\d(SU|MO|TU|WE|TH|FR|SA)$/ ) { 
     48        $rrule{BYDAY}    = $day; 
    4449        $rrule{INTERVAL} = 1; 
    4550    } 
     
    5156        my %args = ( year => $1, month => $2, day => $3 ); 
    5257        my $until; 
    53         if ( $this->{is_full_day} ) { 
     58        if ( $this->is_full_day ) { 
    5459            $until = $this->to_datetime( $param{until_date}, ':' ); 
    5560        } 
    5661        else { 
    57             $until = $this->{end}->clone->set(%args); 
     62            $until = $this->end->clone->set(%args); 
    5863            $until->set_time_zone('UTC');    # timezone must be UTC 
    5964        } 
     
    6166    } 
    6267 
    63     $this->{rrule} = \%rrule; 
     68    $this->rrule( \%rrule ); 
    6469 
    6570    # exdates 
    66     if ( defined $param{exdates} ) { 
     71    if ( defined $param{exception} ) { 
    6772        my @exdates; 
    68         for ( @{ $param{exdates} } ) { 
    69             push @exdates, $this->to_datetime( $_, $param{start_time} ); 
     73        for ( @{ $param{exception} } ) { 
     74            push @exdates, $this->to_datetime( $_, $param{set_time} ); 
    7075        } 
    71         $this->{exdates} = \@exdates; 
     76        $this->exdates( \@exdates ); 
    7277    } 
    7378 
    7479    # for compatibility 
    75     $this->{frequency}       = $FREQUENCY{$freq}; 
    76     $this->{frequency_value} = $param{freq_value} || 0; 
    77     $this->{until}           = $rrule{UNTIL} if exists $rrule{UNTIL}; 
     80    $this->frequency( $FREQUENCY{$type} ); 
     81    $this->frequency_value( $day || 0 ); 
     82    $this->until( $rrule{UNTIL} ) if exists $rrule{UNTIL}; 
    7883 
    7984    1; 
  • cybozu2ical/trunk/lib/WWW/CybozuOffice6/CalendarDriver/ApiCalendar.pm

    r515 r518  
    8686        my $num_fields = @fields - 1; 
    8787        next if $num_fields < 14; 
    88         $fields[1] =~ s/^ts\.//;    # remove rubbish 
    8988 
    9089        # Cybozu Calendar CSV Format 
     
    107106        my %param; 
    108107        @param{ 
    109             qw(id created freq freq_value start_date end_date start_time end_time abbrev summary description) 
     108            qw(id timestamp type day set_date end_date set_time end_time event detail memo) 
    110109          } = @fields[ 0, 1, 4, 5, 8 .. 11, 12 .. 14 ]; 
    111110 
    112111        $param{time_zone} = $cal->{time_zone} || 'Asia/Tokyo'; 
    113112 
     113        if ( $num_fields > 14 ) { 
     114            my @exception = @fields[ 14 .. $num_fields ]; 
     115            $param{exception} = \@exception; 
     116        } 
     117 
    114118        my $item; 
    115         if ( !$param{freq} ) { 
     119        if ( !$param{type} ) { 
    116120            $item = WWW::CybozuOffice6::Calendar::Event->new(%param); 
    117121        } 
    118122        else { 
    119123            @param{qw(end_date until_date)} = @fields[ 8, 9 ]; 
    120             if ( $num_fields > 14 ) { 
    121                 my @exdates = @fields[ 14 .. $num_fields ]; 
    122                 $param{exdates} = \@exdates; 
    123             } 
    124             my $freq = $param{freq}; 
    125             if ( $freq =~ /^[1-5]$/ ) { 
    126                 $param{freq} = 'm'; 
    127                 my @week_str = ( 'SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA' ); 
    128                 $param{freq_value} = $freq . $week_str[ $param{freq_value} ]; 
    129             } 
    130124            $item = WWW::CybozuOffice6::Calendar::RecurrentEvent->new(%param); 
    131125        } 
  • cybozu2ical/trunk/lib/WWW/CybozuOffice6/CalendarDriver/SyncCalendar.pm

    r515 r518  
    5050        my $num_fields = @fields - 1; 
    5151        next if $num_fields < 13; 
    52         $fields[1] =~ s/^ts\.//;    # remove rubbish 
    5352 
    5453        # Cybozu Calendar CSV Format 
    5554        #      GENERIC     | RECCURENT 
    56         # [ 0] id?         | id? 
    57         # [ 1] created     | created 
     55        # [ 0] ID 
     56        # [ 1] TimeStamp 
    5857        # [ 2] <BLANK>     x start_date / end_date 
    59         # [ 3] start_date  x initial start_date? 
    60         # [ 4] end_date    x until_date 
    61         # [ 5] start_time  | start_time 
    62         # [ 6] end_time    | end_time 
    63         # [ 7] <BLANK>     | freq 
    64         # [ 8] <BLANK>     | freq_value 
    65         # [ 9] ???         | ??? 
    66         # [10] ???         | ??? 
    67         # [11] abbrev      | abbrev 
    68         # [12] summary     | summary 
    69         # [13] description | description 
     58        # [ 3] SetDate     x initial start_date? 
     59        # [ 4] EndDate     x until_date 
     60        # [ 5] SetTime 
     61        # [ 6] Endtime 
     62        # [ 7] <BLANK>     | TypeOmit 
     63        # [ 8] <BLANK>     | Day 
     64        # [ 9] Private 
     65        # [10] Banner 
     66        # [11] Event 
     67        # [12] Detail 
     68        # [13] Memo 
    7069 
    7170        my %param; 
    72         @param{ 
    73             qw(id created start_time end_time freq freq_value abbrev summary description) 
     71        @param{ qw(id timestamp set_time end_time type day event detail memo) 
    7472          } = @fields[ 0, 1, 5 .. 8, 11 .. 13 ]; 
     73 
    7574        $param{time_zone} = $cal->{time_zone} || 'Asia/Tokyo'; 
    7675 
     76        if ( $num_fields > 14 ) { 
     77            my @exception = @fields[ 14 .. $num_fields ]; 
     78            $param{exception} = \@exception; 
     79        } 
     80 
    7781        my $item; 
    78         if ( !$param{freq} ) { 
    79             @param{qw(start_date end_date)} = @fields[ 3, 4 ]; 
     82        if ( !$param{type} ) { 
     83            @param{qw(set_date end_date)} = @fields[ 3, 4 ]; 
    8084            $item = WWW::CybozuOffice6::Calendar::Event->new(%param); 
    8185        } 
    8286        else { 
    83             @param{qw(start_date end_date until_date)} = @fields[ 2, 2, 4 ]; 
    84             if ( $num_fields > 13 ) { 
    85                 my @exdates = @fields[ 14 .. $num_fields ]; 
    86                 $param{exdates} = \@exdates; 
    87             } 
    88             my $freq = $param{freq}; 
    89             if ( $freq =~ /^[1-5]$/ ) { 
    90                 $param{freq} = 'm'; 
    91                 my @week_str = ( 'SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA' ); 
    92                 $param{freq_value} = $freq . $week_str[ $param{freq_value} ]; 
    93             } 
     87            @param{qw(set_date end_date until_date)} = @fields[ 2, 2, 4 ]; 
    9488            $item = WWW::CybozuOffice6::Calendar::RecurrentEvent->new(%param); 
    9589        }