2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-10 09:16:53 +00:00

patch to enable WEEKLY;BYDAY applied

git-svn-id: https://svn.fhem.de/fhem/trunk@2339 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
borisneubert 2012-12-16 17:50:58 +00:00
parent a91f0a6d8c
commit 6d6a8417a7

View File

@ -67,6 +67,9 @@ sub addproperty {
#main::debug "key= $key parts= $parts";
$parts= "" unless(defined($parts));
$parameter= "" unless(defined($parameter));
if($key eq "EXDATE") {
push @{$self->{properties}{exdates}}, $parameter;
}
$self->{properties}{$key}= {
PARTS => "$parts",
VALUE => "$parameter"
@ -351,8 +354,16 @@ sub fromVEvent {
#Dates to exclude in reoccuring rule
my @exdate;
@exdate= split(",", $vevent->value("EXDATE")) if($vevent->value("EXDATE"));
@exdate = map { tm($_) } @exdate;
if(exists($vevent->{properties}{exdates})) {
foreach my $entry (@{$vevent->{properties}{exdates}}) {
my @ed = split(",", $entry);
@ed = map { tm($_) } @ed;
push @exdate, @ed;
}
}
#@exdate= split(",", $vevent->value("EXDATE")) if($vevent->value("EXDATE"));
#@exdate = map { tm($_) } @exdate;
$self->{exdate} = \@exdate;
#$self->{summary}=~ s/;/,/g;
@ -467,6 +478,7 @@ sub advanceToNextOccurance {
return if(!exists($self->{freq})); #This event is not reoccuring
return if(exists($self->{count}) and $self->{count} == 0); #We are already at the last occurance
my @weekdays = qw(SU MO TU WE TH FR SA);
#There are no leap seconds in epoch time
#Valid values for freq: SECONDLY, MINUTELY, HOURLY, DAILY, WEEKLY, MONTHLY, YEARLY
my $nextstart = $self->{start};
@ -481,7 +493,20 @@ sub advanceToNextOccurance {
} elsif($self->{freq} eq "DAILY") {
$nextstart += 60*60*24*$self->{interval};
} elsif($self->{freq} eq "WEEKLY") {
$nextstart += 7*60*60*24*$self->{interval};
# special handling for WEEKLY and BYDAY
if(exists($self->{byday})) {
my ($msec, $mmin, $mhour, $mday, $mmon, $myear, $mwday, $yday, $isdat);
my $preventloop = 0;
do {
$nextstart += 60*60*24*$self->{interval};
($msec, $mmin, $mhour, $mday, $mmon, $myear, $mwday, $yday, $isdat) = gmtime($nextstart);
$preventloop ++;
} while(index($self->{byday}, $weekdays[$mwday]) == -1 and $preventloop < 10);
}
else {
# default WEEKLY handling
$nextstart += 7*60*60*24*$self->{interval};
}
} elsif($self->{freq} eq "MONTHLY") {
# here we ignore BYMONTHDAY as we consider the day of month of $self->{start}
# to be equal to BYMONTHDAY.