From 4cfa52f3f99a47f7b7681deb4b4581cc3fc75487 Mon Sep 17 00:00:00 2001 From: betateilchen <> Date: Fri, 8 Feb 2019 20:59:50 +0000 Subject: [PATCH] 57_Calendar.pm: add limit:when=today|tomorrow (as discussed with Boris) git-svn-id: https://svn.fhem.de/fhem/trunk@18535 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/57_Calendar.pm | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/fhem/FHEM/57_Calendar.pm b/fhem/FHEM/57_Calendar.pm index 25d2472df..9aa6f4640 100644 --- a/fhem/FHEM/57_Calendar.pm +++ b/fhem/FHEM/57_Calendar.pm @@ -1995,6 +1995,18 @@ sub Calendar_Get($@) { for my $limit (@limits) { if($limit =~ /count=([1-9]+\d*)/) { $count= $1; + } elsif($limit =~ /when=(today|tomorrow)/i) { + my ($from,$to); + if (lc($1) eq 'today') { + $from = Calendar_GetSecondsFromMidnight(); + $to = DAYSECONDS - $from; + $from *= -1; + } else { + $from = DAYSECONDS - Calendar_GetSecondsFromMidnight(); + $to = $from + DAYSECONDS; + } + push @filters, { ref => \&filter_endafter, param => $t+$from }; + push @filters, { ref => \&filter_startbefore, param => $t+$to }; } elsif($limit =~ /from=([+-]?)(.+)/ ) { my $sign= $1 eq "-" ? -1 : 1; my ($error, $from)= Calendar_GetSecondsFromTimeSpec($2); @@ -2226,6 +2238,12 @@ sub Calendar_DisarmTimer($) { } # +################################### +sub Calendar_GetSecondsFromMidnight(){ + my @time = localtime(); + return (($time[2] * HOURSECONDS) + ($time[1] * MINUTESECONDS) + $time[0]); +} + ################################### sub Calendar_GetSecondsFromTimeSpec($) { @@ -3370,11 +3388,13 @@ sub CalendarEventsAsHtml($;$) {
to=[+|-]<timespec>
when=today|tomorrow
get MyCalendar events limit:count=10
get MyCalendar events limit:from=-2d
get MyCalendar events limit:when=today
get MyCalendar events limit:count=10,from=0,to=+10d