summaryrefslogtreecommitdiff
path: root/utils/rhrd-schedules
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2016-04-27 14:42:59 (GMT)
committerChristian Pointner <equinox@spreadspace.org>2016-04-27 14:42:59 (GMT)
commitec629f278662cc3323bac49ffc5d19bc0cf57a5e (patch)
tree3b5fd64e010caf046a8671e92a90b5834b04af01 /utils/rhrd-schedules
parent57d18e373f2c3bbe55b206c3c8263057a26b7505 (diff)
print schedule reports works now
Diffstat (limited to 'utils/rhrd-schedules')
-rwxr-xr-xutils/rhrd-schedules118
1 files changed, 109 insertions, 9 deletions
diff --git a/utils/rhrd-schedules b/utils/rhrd-schedules
index fd74380..1021b76 100755
--- a/utils/rhrd-schedules
+++ b/utils/rhrd-schedules
@@ -51,8 +51,17 @@ sub generate
for my $entry (@{$data}) {
my $start = DateTime::Format::Strptime::strptime("%Y-%m-%d_%H:%M:%S", ${$entry}{'start'});
my $title = ${$entry}{'title'};
- my $showid = ${$entry}{'id'};
- print "$start: ($showid) $title\n";
+ my $pvid = ${$entry}{'id'};
+ my $showid = ${$entry}{'automation-id'};
+ if($start->year != $year || $start->month != $month || $start->day != $day) {
+ print "WARNING: skipping entry whith invalid start -> $start: $title ($pvid)\n";
+ next;
+ }
+ # Rivendell has problems with events starting at midnight
+ if($start->hour == 0 && $start->minute == 0 && $start->second == 0) {
+ $start->set_second(1);
+ }
+ print "$start: $showid\n";
}
# TODO: create day log in rddb
return 0;
@@ -121,17 +130,108 @@ sub show__day
return $errcnt;
}
-sub show
+# (W1|W2|W3|W4|ALL)
+sub parse_rdweek
{
- my ($ctx, $week, $dow) = @_;
+ my ($dow) = @_;
+
+ if(uc($dow) eq "W1") {
+ return(1);
+ } elsif(uc($dow) eq "W2") {
+ return(2);
+ } elsif(uc($dow) eq "W3") {
+ return(3);
+ } elsif(uc($dow) eq "W4") {
+ return(4);
+ } elsif(uc($dow) eq "ALL") {
+ return(1, 2, 3, 4);
+ }
+ return ();
+}
+
+# (MO|TU|WE|TH|FR|SA|SU|ALL)
+sub parse_dow
+{
+ my ($dow) = @_;
+
+ if(uc($dow) eq "MO") {
+ return(1);
+ } elsif(uc($dow) eq "TU") {
+ return(2);
+ } elsif(uc($dow) eq "WE") {
+ return(3);
+ } elsif(uc($dow) eq "TH") {
+ return(4);
+ } elsif(uc($dow) eq "FR") {
+ return(5);
+ } elsif(uc($dow) eq "SA") {
+ return(6);
+ } elsif(uc($dow) eq "SU") {
+ return(7);
+ } elsif(uc($dow) eq "ALL") {
+ return(1, 2, 3, 4, 5, 6, 7);
+ }
+ return ();
+}
+
+sub cmp_dates
+{
+ my ($a, $b) = @_;
+
+ my $delta = Date::Calc::Delta_Days(@{$a}, @{$b});
+ if($delta > 0) {
+ return -1;
+ }
+ if($delta < 0) {
+ return 1;
+ }
+ return 0;
+}
+
+sub gen_dates
+{
+ my ($week, $dow) = @_;
+
+ my @weeks = parse_rdweek($week);
+ unless(@weeks) {
+ print "error parsing week: $week, must be one of W1, W2, W3, W4, ALL\n";
+ return ()
+ }
+ my @dows = parse_dow($dow);
+ unless(@dows) {
+ print "error parsing day of week: $dow, must be one of MO, TU, WE, TH, FR, SA, SU, ALL\n";
+ return ()
+ }
+ my $curweek = RHRD::utils::get_rd_week();
+ my @today = Date::Calc::Today();
my @dates = ();
+ for $week (@weeks) {
+ my @base = Date::Calc::Standard_to_Business(@today);
+ if($curweek != $week) {
+ my $diff = ($week - $curweek)*7;
+ @base = Date::Calc::Standard_to_Business(Date::Calc::Add_Delta_Days(@today, $diff));
+ }
+ for $dow (@dows) {
+ $base[2] = $dow;
+ my @date = Date::Calc::Business_to_Standard(@base);
+ if(Date::Calc::Delta_Days(@today, @date) < 0) {
+ @date = Date::Calc::Add_Delta_Days(@date, 28)
+ }
+ push @dates, \@date;
+ }
+ }
+ return sort { cmp_dates($a, $b) } @dates;
+}
- # TODO: parse week number and day
- my @d1 = (2016, 4, 14);
- my @d2 = (2016, 4, 15);
- $dates[0] = \@d1;
- $dates[1] = \@d2;
+sub show
+{
+ my ($ctx, $week, $dow) = @_;
+
+ my @dates = gen_dates($week, $dow);
+ unless(@dates) {
+ return -1;
+ }
for my $date (@dates) {
print Date::Calc::Date_to_Text(@{$date}) . ":\n";