Quick hack to improve vCal output
[tpope-extra.git] / perl / schedproc
index a61b4532491e20dbdf1dc0937d1f36427e575dc9..dc5df8cb38fca955a6094bfc125dec95efc66d6e 100755 (executable)
@@ -87,6 +87,27 @@ sub generate_id {
     return $id;
 }
 
+sub first_class {
+    my %class = @_;
+    $class{'duration'} =~ /(\d\d\d\d)(\d\d)(\d\d)-(\d\d\d\d)(\d\d)(\d\d)/;
+    my $days = Delta_Days($1,$2,$3,$4,$5,$6);
+    my $firstday = Date::Calc->new($1,$2,$3);
+    my $lastday = Date::Calc->new($4,$5,$6);
+    my $today;
+    my @days=();
+    foreach(split(" ",$class{'days'})) {
+       push @days, Decode_Day_of_Week($_);
+    }
+    my @off = ();
+    @off = @{$class{'off'}} if ($class{'off'});
+    for($today = $firstday; $today < $lastday; $today++) {
+       next unless(grep($_ == Day_of_Week($today->date), @days));
+       next if(grep($_ == "$today", @off));
+       return $today;
+    }
+    return undef;
+}
+
 sub next_class {
     my %class = @_;
     $class{'duration'} =~ /(\d\d\d\d)(\d\d)(\d\d)-(\d\d\d\d)(\d\d)(\d\d)/;
@@ -362,8 +383,8 @@ sub do_vcalendar_schedule {
        print "DESCRIPTION:", $row->{'id'}, "\r\n";
        print "LOCATION:", $row->{'location'}, "\r\n";
        print "CATEGORIES:Education\r\n";
-       print "DTSTART:", $startdate."T".$starttime, "00\r\n";
-       print "DTEND:", $startdate."T".$stoptime, "00\r\n";
+       print "DTSTART:", first_class(%$row)."T".$starttime, "00\r\n";
+       print "DTEND:", first_class(%$row)."T".$stoptime, "00\r\n";
        print "RRULE:W1 ", $row->{'days'} . " $stopdate", "T000000\r\n";
        print("EXDATE:$day\r\n") if($day);
        print "ATTENDEE;ROLE=OWNER;STATUS=CONFIRMED:", $opts{'name'}, "\r\n" if(defined($opts{'name'}));