Comments
[tpope-extra.git] / perl / schedproc
index 96b607e32cfe45e24f60e6e2e46a431d9e0af317..1c94288ff28fe949b1380ec8e0edfcb3843ebaa0 100755 (executable)
@@ -137,7 +137,7 @@ sub next_class {
     return undef;
 }
 
-sub ical_datetime {
+sub vcal_datetime {
     my $date=shift;
     my $time=shift;
     $date =~ /(\d\d\d\d)(\d\d)(\d\d)/;
@@ -379,18 +379,18 @@ sub do_vcalendar_schedule {
     print "BEGIN:VCALENDAR\r\nVERSION:1.0\r\n";
     foreach my $row (@schedule) {
        map { s/\n/-/g; $_} %$row;
+       my ($starttime, $stoptime)=($row->{'begin'}, $row->{'end'});
+       my ($startdate, $stopdate)=split(/-/, $row->{'duration'});
+       $starttime =~ s/://;
+       $stoptime =~ s/://;
+       my $first = first_class(%$row);
        my @day = ();
        @day = @{$row->{'off'}} if ($row->{'off'});
        my $day = "";
        if(exists($day[0])) {
            $day = join(";", @day);
-           $day =~ s/\b(\d{8})\b/$1T000000/g;
+           $day =~ s/\b(\d{8})\b/$1T${starttime}00/g;
        }
-       my ($starttime, $stoptime)=($row->{'begin'}, $row->{'end'});
-       my ($startdate, $stopdate)=split(/-/, $row->{'duration'});
-       $starttime =~ s/://;
-       $stoptime =~ s/://;
-       my $first = first_class(%$row);
        if(defined($file) && (-d $file)) {
            open FH, ">$file/" . $row->{'id'} . ".vcs" or die "$!";
            select FH;
@@ -401,9 +401,10 @@ sub do_vcalendar_schedule {
        print "DESCRIPTION:", $row->{'id'}, "\r\n";
        print "LOCATION:", $row->{'location'}, "\r\n";
        print "CATEGORIES:Education\r\n";
-       #print "DTSTART:", ical_datetime(first_class(%$row),$starttime), "\r\n";
-       print "DTSTART:", $first."T".$starttime, "00\r\n";
-       print "DTEND:", $first."T".$stoptime, "00\r\n";
+       print "DTSTART:", vcal_datetime($first,$starttime), "\r\n";
+       print "DTEND:", vcal_datetime($first,$stoptime), "\r\n";
+       #print "DTSTART:", $first."T".$starttime, "00\r\n";
+       #print "DTEND:", $first."T".$stoptime, "00\r\n";
        $row->{'days'} =~ s/([MTWRFS])/ $days{$1}/g;
        $row->{'days'} =~ s/^ //;
        print "RRULE:W1 ", $row->{'days'} . " $stopdate", "T000000\r\n";
@@ -445,43 +446,50 @@ END:DAYLIGHT$r
 END:VTIMEZONE$r
 EOF
     ;
+    my $now = Date::Calc->now();
+    $now = sprintf ("%02d%02d%02dT%02d%02d%02dZ", $now->datetime());
     my %days = (M => "MO", T => "TU", W => "WE", R => "TH", F => "FR", S => "SA", U => "SU");
     my $file = $opts{'out'};
     my @schedule = get_schedule(@_);
     open(STDOUT, ">" . $file) || die $! if(defined($file) && (! -d $file));
     open(STDOUT, ">/dev/null") || die $! if(defined($file) && (-d $file));
-    print "BEGIN:VCALENDAR$r\nVERSION:2.0$r\n$timezone";
+    print "BEGIN:VCALENDAR$r\nVERSION:2.0$r\nMETHOD:PUBLISH$r\n$timezone";
     foreach my $row (@schedule) {
        map { s/\n/-/g; $_} %$row;
-       my @day = ();
-       @day = @{$row->{'off'}} if ($row->{'off'});
        my ($starttime, $stoptime)=($row->{'begin'}, $row->{'end'});
        my ($startdate, $stopdate)=split(/-/, $row->{'duration'});
        $starttime =~ s/://;
        $stoptime =~ s/://;
        my $first = first_class(%$row);
+       my @day = ();
+       @day = @{$row->{'off'}} if ($row->{'off'});
+       my $day = "";
+       if(exists($day[0])) {
+           $day = join(",", @day);
+           #$day =~ s/\b(\d{8})\b/$1T${starttime}00/g;
+       }
        if(defined($file) && (-d $file)) {
            open FH, ">$file/" . $row->{'id'} . ".vcs" or die "$!";
            select FH;
-           print "BEGIN:VCALENDAR$r\nVERSION:2.0$r\n$timezone";
+           print "BEGIN:VCALENDAR$r\nVERSION:2.0$r\nMETHOD:PUBLISH$r\n$timezone";
        }
        print "BEGIN:VEVENT$r\n";
+       print "ORGANIZER:mailto:" . $opts{'email'} . "$r\n" if $opts{'email'};
+       print "UID:" . $row->{'id'} . "\@from.sctweb$r\n";
+       print "DTSTAMP:$now$r\n";
        print "SUMMARY:", $row->{'title'}, "$r\n";
        print "DESCRIPTION:", $row->{'id'}, "$r\n";
        print "LOCATION:", $row->{'location'}, "$r\n";
        print "CATEGORIES:Education$r\n";
        print "TRANSP:OPAQUE$r\n";
-       #print "DTSTART;$tzn$first,$starttime), "$r\n";
-       #print "DTEND;$tzn$first,$stoptime), "$r\n";
        print "DTSTART;TZID=\"$tzn\":", $first."T".$starttime, "00$r\n";
        print "DTEND;TZID=\"$tzn\":", $first."T".$stoptime, "00$r\n";
        $row->{'days'} =~ s/([MTWRFS])/,$days{$1}/g;
        $row->{'days'} =~ s/^,//;
-       $stopdate++
+       #$stopdate++;
        print "RRULE:FREQ=WEEKLY;UNTIL=${stopdate}T000000Z;BYDAY=", $row->{'days'}, "$r\n";
-       foreach my $day (@day) {
-           print("EXDATE;TZID=\"$tzn\":${day}T$starttime$r\n");
-       }
+       #print("EXDATE;TZID=\"$tzn\":$day$r\n") if($day);
+       print("EXDATE;VALUE=DATE:$day$r\n") if($day);
        print "ATTENDEE;CN=".$row->{'instructor'}.";RSVP=FALSE;PARTSTAT=ACCEPTED;ROLE=CHAIR:mailto:" . (get_faculty_email($row->{'instructor'}) || "fake\@ddress"), "$r\n";
        print "ATTENDEE;CN=".$opts{'name'}.";RSVP=FALSE;PARTSTAT=ACCEPTED;ROLE=REQ-PARTICIPANT:mailto:" . ($opts{'email'} || "fake\@ddress"), "$r\n" if $opts{'name'};
        print "END:VEVENT$r\n";