| 23 | | sub url { shift->_accessor('url', @_) } |
| 24 | | sub host { shift->_accessor('host', @_) } |
| 25 | | sub username { shift->_accessor('username', @_) } |
| 26 | | sub userid { shift->_accessor('userid', @_) } |
| 27 | | sub password { shift->_accessor('password', @_) } |
| 28 | | sub ua { shift->_accessor('ua', @_) } |
| 29 | | sub input_encoding { shift->_accessor('input_encoding', @_) } |
| | 23 | sub url { shift->_accessor( 'url', @_ ) } |
| | 24 | sub host { shift->_accessor( 'host', @_ ) } |
| | 25 | sub username { shift->_accessor( 'username', @_ ) } |
| | 26 | sub userid { shift->_accessor( 'userid', @_ ) } |
| | 27 | sub password { shift->_accessor( 'password', @_ ) } |
| | 28 | sub ua { shift->_accessor( 'ua', @_ ) } |
| | 29 | sub input_encoding { shift->_accessor( 'input_encoding', @_ ) } |
| | 30 | |
| 93 | | for my $line ($this->response) { |
| 94 | | $csv->parse($line) |
| 95 | | or confess 'Failed to parse CSV input'; |
| 96 | | my @fields = $csv->fields; |
| 97 | | my $num_fields = @fields - 1; |
| 98 | | next if $num_fields < 13; |
| 99 | | $fields[1] =~ s/^ts\.//; # remove rubbish |
| 100 | | |
| 101 | | # Cybozu Calendar CSV Format |
| 102 | | # GENERIC | RECCURENT |
| 103 | | # [ 0] id? | id? |
| 104 | | # [ 1] created | created |
| 105 | | # [ 2] <BLANK> x start_date / end_date |
| 106 | | # [ 3] start_date x initial start_date? |
| 107 | | # [ 4] end_date x until_date |
| 108 | | # [ 5] start_time | start_time |
| 109 | | # [ 6] end_time | end_time |
| 110 | | # [ 7] <BLANK> | freq |
| 111 | | # [ 8] <BLANK> | freq_value |
| 112 | | # [ 9] ??? | ??? |
| 113 | | # [10] ??? | ??? |
| 114 | | # [11] abbrev | abbrev |
| 115 | | # [12] summary | summary |
| 116 | | # [13] description | description |
| 117 | | |
| 118 | | my %param; |
| 119 | | @param{qw(id created start_time end_time freq freq_value abbrev summary description)} = @fields[0,1,5..8,11..13]; |
| 120 | | $param{time_zone} = $this->{time_zone} || 'Asia/Tokyo'; |
| 121 | | |
| 122 | | my $item; |
| 123 | | if (!$param{freq}) { |
| 124 | | @param{qw(start_date end_date)} = @fields[3,4]; |
| 125 | | $item = WWW::CybozuOffice6::Calendar::Event->new(%param); |
| 126 | | } else { |
| 127 | | @param{qw(start_date end_date until_date)} = @fields[2,2,4]; |
| 128 | | if ($num_fields > 13) { |
| 129 | | my @exdates = @fields[14..$num_fields]; |
| 130 | | $param{exdates} = \@exdates; |
| 131 | | } |
| 132 | | my $freq = $param{freq}; |
| 133 | | if ($freq =~ /^[1-5]$/) { |
| 134 | | $param{freq} = 'm'; |
| 135 | | my @week_str = ('SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA'); |
| 136 | | $param{freq_value} = $freq . $week_str[$param{freq_value}]; |
| 137 | | } |
| 138 | | $item = WWW::CybozuOffice6::Calendar::RecurrentEvent->new(%param); |
| 139 | | } |
| 140 | | |
| 141 | | next unless $item; |
| 142 | | $item->comment($line); # save the CSV line as for debug info. |
| 143 | | push @items, $item; |
| | 100 | for my $line ( $this->response ) { |
| | 101 | $csv->parse($line) |
| | 102 | or confess 'Failed to parse CSV input'; |
| | 103 | my @fields = $csv->fields; |
| | 104 | my $num_fields = @fields - 1; |
| | 105 | next if $num_fields < 13; |
| | 106 | $fields[1] =~ s/^ts\.//; # remove rubbish |
| | 107 | |
| | 108 | # Cybozu Calendar CSV Format |
| | 109 | # GENERIC | RECCURENT |
| | 110 | # [ 0] id? | id? |
| | 111 | # [ 1] created | created |
| | 112 | # [ 2] <BLANK> x start_date / end_date |
| | 113 | # [ 3] start_date x initial start_date? |
| | 114 | # [ 4] end_date x until_date |
| | 115 | # [ 5] start_time | start_time |
| | 116 | # [ 6] end_time | end_time |
| | 117 | # [ 7] <BLANK> | freq |
| | 118 | # [ 8] <BLANK> | freq_value |
| | 119 | # [ 9] ??? | ??? |
| | 120 | # [10] ??? | ??? |
| | 121 | # [11] abbrev | abbrev |
| | 122 | # [12] summary | summary |
| | 123 | # [13] description | description |
| | 124 | |
| | 125 | my %param; |
| | 126 | @param{ |
| | 127 | qw(id created start_time end_time freq freq_value abbrev summary description) |
| | 128 | } = @fields[ 0, 1, 5 .. 8, 11 .. 13 ]; |
| | 129 | $param{time_zone} = $this->{time_zone} || 'Asia/Tokyo'; |
| | 130 | |
| | 131 | my $item; |
| | 132 | if ( !$param{freq} ) { |
| | 133 | @param{qw(start_date end_date)} = @fields[ 3, 4 ]; |
| | 134 | $item = WWW::CybozuOffice6::Calendar::Event->new(%param); |
| | 135 | } |
| | 136 | else { |
| | 137 | @param{qw(start_date end_date until_date)} = @fields[ 2, 2, 4 ]; |
| | 138 | if ( $num_fields > 13 ) { |
| | 139 | my @exdates = @fields[ 14 .. $num_fields ]; |
| | 140 | $param{exdates} = \@exdates; |
| | 141 | } |
| | 142 | my $freq = $param{freq}; |
| | 143 | if ( $freq =~ /^[1-5]$/ ) { |
| | 144 | $param{freq} = 'm'; |
| | 145 | my @week_str = ( 'SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA' ); |
| | 146 | $param{freq_value} = $freq . $week_str[ $param{freq_value} ]; |
| | 147 | } |
| | 148 | $item = WWW::CybozuOffice6::Calendar::RecurrentEvent->new(%param); |
| | 149 | } |
| | 150 | |
| | 151 | next unless $item; |
| | 152 | $item->comment($line); # save the CSV line as for debug info. |
| | 153 | push @items, $item; |
| 161 | | sub id { shift->_accessor('id', @_) } |
| 162 | | sub start { shift->_accessor('start', @_) } |
| 163 | | sub end { shift->_accessor('end', @_) } |
| 164 | | sub summary { shift->_accessor('summary', @_) } |
| 165 | | sub description { shift->_accessor('description', @_) } |
| 166 | | sub created { shift->_accessor('created', @_) } |
| 167 | | sub modified { shift->_accessor('modified', @_) } |
| 168 | | sub is_full_day { shift->_accessor('is_full_day', @_) } |
| 169 | | sub comment { shift->_accessor('comment', @_) } |
| | 171 | sub id { shift->_accessor( 'id', @_ ) } |
| | 172 | sub start { shift->_accessor( 'start', @_ ) } |
| | 173 | sub end { shift->_accessor( 'end', @_ ) } |
| | 174 | sub summary { shift->_accessor( 'summary', @_ ) } |
| | 175 | sub description { shift->_accessor( 'description', @_ ) } |
| | 176 | sub created { shift->_accessor( 'created', @_ ) } |
| | 177 | sub modified { shift->_accessor( 'modified', @_ ) } |
| | 178 | sub is_full_day { shift->_accessor( 'is_full_day', @_ ) } |
| | 179 | sub comment { shift->_accessor( 'comment', @_ ) } |
| | 180 | |
| 213 | | return unless $ymd && ($ymd =~ m!^(\d+)/(\d+)/(\d+)$! || $ymd =~ m!^da\.(\d+)\.(\d+)\.(\d+)$!); |
| 214 | | @args{qw(year month day)} = ($1, $2, $3); |
| 215 | | |
| 216 | | if ($hms && $hms ne ':') { |
| 217 | | return unless $hms =~ m!^(\d+):(\d+)(?:\:?(\d+)?)$!; |
| 218 | | @args{qw(hour minute second)} = ($1, $2, $3 || 0); |
| 219 | | @args{qw(hour minute second)} = (23, 59, 59) if $args{hour} > 23; |
| 220 | | } else { |
| 221 | | @args{qw(hour minute second)} = (0, 0, 0); |
| | 226 | return |
| | 227 | unless $ymd |
| | 228 | && ( $ymd =~ m!^(\d+)/(\d+)/(\d+)$! |
| | 229 | || $ymd =~ m!^da\.(\d+)\.(\d+)\.(\d+)$! ); |
| | 230 | @args{qw(year month day)} = ( $1, $2, $3 ); |
| | 231 | |
| | 232 | if ( $hms && $hms ne ':' ) { |
| | 233 | return unless $hms =~ m!^(\d+):(\d+)(?:\:?(\d+)?)$!; |
| | 234 | @args{qw(hour minute second)} = ( $1, $2, $3 || 0 ); |
| | 235 | @args{qw(hour minute second)} = ( 23, 59, 59 ) if $args{hour} > 23; |
| | 236 | } |
| | 237 | else { |
| | 238 | @args{qw(hour minute second)} = ( 0, 0, 0 ); |
| 258 | | if ($FREQUENCY{$freq} eq 'WEEKDAYS') { |
| 259 | | %rrule = ( FREQ => 'WEEKLY', BYDAY => 'MO,TU,WE,TH,FR' ); |
| 260 | | } else { |
| 261 | | %rrule = ( FREQ => $FREQUENCY{$freq} ); |
| 262 | | } |
| 263 | | if ($param{freq_value} =~ /^\d(SU|MO|TU|WE|TH|FR|SA)$/) { |
| 264 | | $rrule{BYDAY} = $param{freq_value}; |
| 265 | | $rrule{INTERVAL} = 1; |
| | 282 | if ( $FREQUENCY{$freq} eq 'WEEKDAYS' ) { |
| | 283 | %rrule = ( FREQ => 'WEEKLY', BYDAY => 'MO,TU,WE,TH,FR' ); |
| | 284 | } |
| | 285 | else { |
| | 286 | %rrule = ( FREQ => $FREQUENCY{$freq} ); |
| | 287 | } |
| | 288 | if ( $param{freq_value} =~ /^\d(SU|MO|TU|WE|TH|FR|SA)$/ ) { |
| | 289 | $rrule{BYDAY} = $param{freq_value}; |
| | 290 | $rrule{INTERVAL} = 1; |
| 269 | | if ($param{until_date} =~ m!^(\d+)/(\d+)/(\d+)$! || $param{until_date} =~ m!^da\.(\d+)\.(\d+)\.(\d+)$!) { |
| 270 | | my %args = (year => $1, month => $2, day => $3); |
| 271 | | my $until; |
| 272 | | if ($this->{is_full_day}) { |
| 273 | | $until = $this->to_datetime($param{until_date}, ':'); |
| 274 | | } else { |
| 275 | | $until = $this->{end}->clone->set(%args); |
| 276 | | $until->set_time_zone('UTC'); # timezone must be UTC |
| 277 | | } |
| 278 | | $rrule{UNTIL} = $until; |
| | 294 | if ( $param{until_date} =~ m!^(\d+)/(\d+)/(\d+)$! |
| | 295 | || $param{until_date} =~ m!^da\.(\d+)\.(\d+)\.(\d+)$! ) |
| | 296 | { |
| | 297 | my %args = ( year => $1, month => $2, day => $3 ); |
| | 298 | my $until; |
| | 299 | if ( $this->{is_full_day} ) { |
| | 300 | $until = $this->to_datetime( $param{until_date}, ':' ); |
| | 301 | } |
| | 302 | else { |
| | 303 | $until = $this->{end}->clone->set(%args); |
| | 304 | $until->set_time_zone('UTC'); # timezone must be UTC |
| | 305 | } |
| | 306 | $rrule{UNTIL} = $until; |