From 7842299da020514739cba09d416f89372013c97b Mon Sep 17 00:00:00 2001 From: herrmannj <> Date: Thu, 24 Aug 2023 08:56:13 +0000 Subject: [PATCH] Cron.pm: wip git-svn-id: https://svn.fhem.de/fhem/trunk@27892 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/lib/FHEM/Scheduler/Cron.pm | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/fhem/lib/FHEM/Scheduler/Cron.pm b/fhem/lib/FHEM/Scheduler/Cron.pm index 6f204bf55..a936a50a2 100644 --- a/fhem/lib/FHEM/Scheduler/Cron.pm +++ b/fhem/lib/FHEM/Scheduler/Cron.pm @@ -680,14 +680,14 @@ sub _next_positional_date { my ($y, $m) = ($year_next, $self->{list_of_months}->[$temp_month_ptr]); my $first_wday = $self->get_weekday($y, $m, 1); my $day_diff = ($wday + 7 - $first_wday) %7; - $day_diff += 1 + (($position - 1) * 7); - my $candidate = sprintf('%04d%02d%02d', $y, $m, $day_diff); - $self->log(5, 'candidate %04d-%02d-%02d', $y, $m, $day_diff) if $ENV{EXTENDED_DEBUG}; - if ($self->is_valid_date($y, $m, $day_diff) and + my $d = $day_diff += 1 + (($position - 1) * 7); + my $candidate = sprintf('%04d%02d%02d', $y, $m, $d); + $self->log(5, 'candidate %04d-%02d-%02d', $y, $m, $d) if $ENV{EXTENDED_DEBUG}; + if ($d < 32 and $self->is_valid_date($y, $m, $d) and (($inclusive and $candidate >= $from_date) or (not $inclusive and $candidate > $from_date))) { push @res, $self->{positional_date_cache}->{$item} = $found = $candidate; - $self->log(5, 'found candidate %04d-%02d-%02d for %s', $y, $m, $day_diff, $item) if $ENV{EXTENDED_DEBUG}; + $self->log(5, 'found candidate %04d-%02d-%02d for %s', $y, $m, $d, $item) if $ENV{EXTENDED_DEBUG}; # last and exit loop } else { $temp_month_ptr++; @@ -714,13 +714,14 @@ sub _next_positional_date { my $last_wday = $self->get_weekday($y, $m, $last_day); my $day_diff = ($last_wday + 7 - $wday) %7; $day_diff += (($position * -1) - 1) * 7; - my $candidate = sprintf('%04d%02d%02d', $y, $m, $days_in_month[$m] - $day_diff); - $self->log(5, 'candidate %04d-%02d-%02d', $y, $m, $days_in_month[$m] - $day_diff) if $ENV{EXTENDED_DEBUG}; - if ($self->is_valid_date($y, $m, $days_in_month[$m] - $day_diff) and + my $d = $days_in_month[$m] - $day_diff; + my $candidate = sprintf('%04d%02d%02d', $y, $m, $d); + $self->log(5, 'candidate %04d-%02d-%02d', $y, $m, $d) if $ENV{EXTENDED_DEBUG}; + if ($d > 1 and $self->is_valid_date($y, $m, $d) and (($inclusive and $candidate >= $from_date) or (not $inclusive and $candidate > $from_date))) { push @res, $self->{positional_date_cache}->{$item} = $found = $candidate; - $self->log(5, 'found candidate %04d-%02d-%02d for %s', $y, $m, $days_in_month[$m] - $day_diff, $item) if $ENV{EXTENDED_DEBUG}; + $self->log(5, 'found candidate %04d-%02d-%02d for %s', $y, $m, $d, $item) if $ENV{EXTENDED_DEBUG}; # last and exit loop } else { $temp_month_ptr++;