| 61 | | my $created = Date::ICal->new(epoch => $epoch)->ical; |
|---|
| 62 | | |
|---|
| 63 | | my @d = split("/", $fields[3]); |
|---|
| 64 | | my @t = split(":", $fields[5]); |
|---|
| 65 | | my $date = Date::ICal->new( |
|---|
| 66 | | year => $d[0], month => $d[1], day => $d[2], |
|---|
| 67 | | hour => $t[0] || 0, min => $t[1] || 0, sec => $t[2] || 0 |
|---|
| 68 | | ); |
|---|
| 69 | | my $dtstart = $date->ical(offset => '+0900'); |
|---|
| 70 | | $dtstart =~ s/T000000// if $fields[5] =~ /^:$/; |
|---|
| 71 | | |
|---|
| 72 | | my @d = split("/", $fields[4]); |
|---|
| 73 | | my @t = split(":", $fields[6]); |
|---|
| 74 | | my $date = Date::ICal->new( |
|---|
| 75 | | year => $d[0], month => $d[1], day => $d[2], |
|---|
| 76 | | hour => $t[0] || 0, min => $t[1] || 0, sec => $t[2] || 0 |
|---|
| 77 | | ); |
|---|
| 78 | | $date += 'P1D' if $fields[6] =~ /^:$/; # full-day or multiple-days events |
|---|
| 79 | | my $dtend = $date->ical(offset => '+0900'); |
|---|
| 80 | | $dtend =~ s/T000000// if $fields[6] =~ /^:$/; |
|---|
| | 63 | my $created = dt2ical(DateTime->from_epoch(epoch => $epoch)); |
|---|
| | 64 | |
|---|
| | 65 | my $dt1 = cydate2dt($fields[3], $fields[5], $tz); |
|---|
| | 66 | my $dtstart = ($fields[5] !~ /^:$/) ? |
|---|
| | 67 | dt2ical($dt1) : $dt1->ymd(''); |
|---|
| | 68 | |
|---|
| | 69 | my $dt2 = cydate2dt($fields[4], $fields[6], $tz); |
|---|
| | 70 | my $dtend = ($fields[6] !~ /^:$/) ? |
|---|
| | 71 | dt2ical($dt2) : $dt2->add(days => 1)->ymd(''); |
|---|
| | 108 | sub cydate2dt { |
|---|
| | 109 | my($date, $time, $tz) = @_; |
|---|
| | 110 | my @d = split("/", $date); |
|---|
| | 111 | my @t = split(":", $time); |
|---|
| | 112 | |
|---|
| | 113 | my $dt = DateTime->new( |
|---|
| | 114 | year => $d[0], month => $d[1], day => $d[2], |
|---|
| | 115 | hour => $t[0] || 0, minute => $t[1] || 0, second => $t[2] || 0, |
|---|
| | 116 | time_zone => $tz || 'Asia/Tokyo' |
|---|
| | 117 | ); |
|---|
| | 118 | return $dt; |
|---|
| | 119 | } |
|---|
| | 120 | |
|---|
| | 121 | sub dt2ical { |
|---|
| | 122 | my($dt) = @_; |
|---|
| | 123 | $dt->ymd('') . 'T' . $dt->hms('') . ($dt->time_zone->is_utc ? 'Z' : ''); |
|---|
| | 124 | } |
|---|
| | 125 | |
|---|
| | 127 | =head1 NAME |
|---|
| | 128 | |
|---|
| | 129 | cybozu2ical - Convert CybozuOffice6 calendar into iCal format |
|---|
| | 130 | |
|---|
| | 131 | =head1 SYNOPSIS |
|---|
| | 132 | |
|---|
| | 133 | % cybozu2ical |
|---|
| | 134 | % cybozu2ical /path/to/config.yaml |
|---|
| | 135 | |
|---|
| | 136 | =head1 DESCRIPTION |
|---|
| | 137 | |
|---|
| | 138 | =head1 DESCRIPTION |
|---|
| | 139 | |
|---|
| | 140 | C<cybozu2ical> is a command line application that fetches Cybozu |
|---|
| | 141 | Office 6 calendar items and converts them into a iCal file. It allows |
|---|
| | 142 | you to easily integrate the Cybozu Calendar into iCalendar-enabled |
|---|
| | 143 | Calendar applications, such as Microsoft Outlook, Apple iCal, and of |
|---|
| | 144 | course, Google Calendar. |
|---|
| | 145 | |
|---|
| | 146 | You can run this via crontab, for example, every 1 hour. |
|---|
| | 147 | |
|---|
| | 148 | =head1 REQUIREMENT |
|---|
| | 149 | |
|---|
| | 150 | This application requires perl 5.8.0 with following Perl modules |
|---|
| | 151 | installed on your box. |
|---|
| | 152 | |
|---|
| | 153 | =over 4 |
|---|
| | 154 | |
|---|
| | 155 | =item Data::ICal |
|---|
| | 156 | |
|---|
| | 157 | =item DateTime |
|---|
| | 158 | |
|---|
| | 159 | =item YAML |
|---|
| | 160 | |
|---|
| | 161 | =back |
|---|
| | 162 | |
|---|
| | 163 | =head1 OPTIONS |
|---|
| | 164 | |
|---|
| | 165 | This application has a command-line option as follows: |
|---|
| | 166 | |
|---|
| | 167 | =over 4 |
|---|
| | 168 | |
|---|
| | 169 | =item path/to/config.yaml |
|---|
| | 170 | |
|---|
| | 171 | Specified the path to a configuration file. By default, C<config.yaml> |
|---|
| | 172 | in the current directory. |
|---|
| | 173 | |
|---|
| | 174 | =back |
|---|
| | 175 | |
|---|
| | 176 | =head1 CONFIGURATION |
|---|
| | 177 | |
|---|
| | 178 | The distributions includes a sample configuration file |
|---|
| | 179 | C<config.yaml.sample>. You can rename it to C<config.yaml> and |
|---|
| | 180 | configure C<cybozu2ical>. |
|---|
| | 181 | |
|---|
| | 182 | =over 4 |
|---|
| | 183 | |
|---|
| | 184 | =item cybozu_url |
|---|
| | 185 | |
|---|
| | 186 | Set the URL of your Cybozu Office 6. |
|---|
| | 187 | |
|---|
| | 188 | =item username, password |
|---|
| | 189 | |
|---|
| | 190 | Set your username and password for Cybozu Office 6. |
|---|
| | 191 | |
|---|
| | 192 | =item time_zone |
|---|
| | 193 | |
|---|
| | 194 | Set the timezone of your Cybozu Office 6 (e.g., Asia/Tokyo). |
|---|
| | 195 | |
|---|
| | 196 | =item tzname |
|---|
| | 197 | |
|---|
| | 198 | Set the short timezone name of your Cybozu Office 6 (e.g., JST). |
|---|
| | 199 | |
|---|
| | 200 | =back |
|---|
| | 201 | |
|---|
| | 202 | =head1 DEVELOPMENT |
|---|
| | 203 | |
|---|
| | 204 | The development version is always available from the following |
|---|
| | 205 | subversion repository: |
|---|
| | 206 | |
|---|
| | 207 | svn://svn.as-is.net/public/cybozu2ical/trunk |
|---|
| | 208 | |
|---|
| | 209 | You can browse the files via SVN::Web from the following: |
|---|
| | 210 | |
|---|
| | 211 | http://svn.as-is.net/svnweb/public/browse/cybozu2ical/trunk/ |
|---|
| | 212 | |
|---|
| | 213 | Any comments, suggestions, or patches are welcome. |
|---|
| | 214 | |
|---|
| | 215 | =head1 AUTHOR |
|---|
| | 216 | |
|---|
| | 217 | Hirotaka Ogawa E<lt>hirotaka.ogawa at gmail.comE<gt> |
|---|
| | 218 | |
|---|
| | 219 | This script is free software and licensed under the same terms as Perl |
|---|
| | 220 | (Artistic/GPL). |
|---|
| | 221 | |
|---|
| | 222 | =cut |
|---|