Changeset 1762

Show
Ignore:
Timestamp:
10/15/06 23:16:56
Author:
miyagawa
Message:

Publish::iCal: outsource TZ/UTC/Olson/floating logic to DateTime?::Format::ICal. Added dependency and added tests

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/plagger/deps/Publish-iCal.yaml

    r1725 r1762  
    33depends: 
    44  Data::ICal: 0 
     5  DateTime::Format::ICal: 0 
  • trunk/plagger/lib/Plagger/Plugin/Publish/iCal.pm

    r1760 r1762  
    77use Data::ICal::Entry::Event; 
    88use DateTime::Duration; 
     9use DateTime::Format::ICal; 
    910use Plagger::Util; 
    1011 
     
    4142 
    4243        my $tz = $date->time_zone; 
    43         my %param; 
    44         if (!$tz->is_floating && $tz->name ne 'UTC' && !$tz->isa('DateTime::TimeZone::OffsetOnly')) { 
    45             # don't set TZID if tz name is like '+0900' 
    46             $param{TZID} = $tz->name; 
    47         } 
    4844 
    49         my($dtstart, $dtend); 
     45        my $dtstart = $date->format('ICal'); 
     46        my $dtend   = $date->format('ICal'); 
     47 
    5048        if ($date->hms eq '00:00:00') { 
    51             $dtstart = [ $date->strftime('%Y%m%d'), { %param, VALUE => 'DATE' } ]; 
    52             $dtend   = [ $date->strftime('%Y%m%d'), { %param, VALUE => 'DATE' } ]; 
     49            $dtstart = [ $dtstart, { VALUE => 'DATE' } ]; 
     50            $dtend   = [ $dtend,   { VALUE => 'DATE' } ]; 
    5351        } else { 
    54             $dtstart = [ iso8691_full($date), \%param ]; 
    55             $dtend   = [ iso8691_full($date), \%param ]; 
     52            $dtstart =~ s/^TZID=(.*?):// 
     53                and $dtstart = [ $dtstart, { TZID => $1 } ]; 
     54            $dtend   =~ s/^TZID=(.*?):// 
     55                and $dtend   = [ $dtend, { TZID => $1 } ]; 
    5656        } 
    5757 
     
    7676 
    7777    $context->log(info => "Wrote iCalendar file to $path"); 
    78 } 
    79  
    80 sub iso8691_full { 
    81     my $date = shift; 
    82     my $iso  = $date->strftime('%Y%m%dT%H%M%S'); 
    83     $iso .= $date->time_zone->name eq 'UTC' ? 'Z' : ''; 
    84     $iso; 
    8578} 
    8679 
  • trunk/plagger/t/plugins/Publish-iCal/base.t

    r1760 r1762  
    3131my $ical = Data::ICal->new(filename => $::output); 
    3232is @{$ical->entries}, 5; 
    33 is $ical->entries->[0]->property('dtstart')->[0]->value, "20060710T213213"; 
    34 is $ical->entries->[0]->property('dtend')->[0]->value, "20060710T213213"; 
     33is $ical->entries->[0]->property('dtstart')->[0]->value, "20060710T123213Z"; 
     34is $ical->entries->[0]->property('dtend')->[0]->value, "20060710T123213Z"; 
    3535 
    3636=== Full day event 
     
    109109ok -e $::output; 
    110110my $ical = Data::ICal->new(filename => $::output); 
    111 is $ical->entries->[0]->property('dtstart')->[0]->value, "20061020T123456"; 
     111is $ical->entries->[0]->property('dtstart')->[0]->value, "20061020T033456Z"; 
    112112is_deeply $ical->entries->[0]->property('dtstart')->[0]->parameters, {}; 
    113113