From c05f37ce611c0dd939b47a598b764d89bee1fa14 Mon Sep 17 00:00:00 2001 From: James Date: Sun, 29 Sep 2019 11:22:53 +0100 Subject: [PATCH] pretty good prototype --- src/rrule.php | 51 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/src/rrule.php b/src/rrule.php index a644bdf..7d84742 100755 --- a/src/rrule.php +++ b/src/rrule.php @@ -14,35 +14,50 @@ function updateIssueBody($issue,$text){ } //replace the tag contents with the result from our $text function $issue->body=preg_replace("#.*?#s",'
'.$text.'',$issue->body); + $issue->save(); }; +//loop through each issue that has a RRULE foreach($repo->getIssues(['q'=>'RRULE:']) as $issue){ - //echo "GOT: {$issue->number}\n"; + //extract the rule text if(preg_match('/RRULE:\s?(.*)/',$issue->body,$matches)){ $rruletxt=$matches[1]; - //echo "RRULEtxt: ".$rruletxt."\n"; + //create the rule, report any exceptions try{ $rrule = new RRule($rruletxt); - /*foreach ( $rrule as $occurrence ) { - echo $occurrence->format('D d M Y'),"\n "; - }*/ - $result=$rrule->humanReadable()."
\n NEXT1:".$rrule[0]->format('r')."
\n NEXT2:".$rrule[1]->format('r'); - updateIssueBody($issue,$result); - $issue->save(); - //echo $rrule[0]->format('Y-m-d')." == ".date('Y-m-d')."\n"; }catch(Exception $e){ $result="\n```plain\n".$e->getMessage()." ($rruletxt)\n```\n"; updateIssueBody($issue,$result); - $issue->save(); continue; } - if($rrule[0]->format('Y-m-d')==date('Y-m-d')){ - $issue->addComment("Today (NEXT:".$rrule[1]->format('r').")"); - } + }else{ //couldn't extract, report error + updateIssueBody($issue,"Can't extract RRULE:"); + continue; + } - updateIssueBody($issue,$result); - // not working https://github.com/go-gitea/gitea/issues/8179 - //$issue->due_date=$rrule[0]->format('c'); - $issue->save(); - } + // if we get here, then there is a valid rrule :) + + // calcultate some useful info + $next_inc=$rrule->getOccurrencesAfter(date('Y-m-d'),$inclusive=true,$limit=1)[0]; + $next_exc=$rrule->getOccurrencesAfter(date('Y-m-d'),$inclusive=false,$limit=1)[0]; + $today=$next_inc->format('Y-m-d')==date('Y-m-d'); + + //some debug + $result=$rrule->humanReadable(). + "
\n NOW: ".date('Y-m-d'). + "
\n First: ".$rrule[0]->format('Y-m-d'). + "
\n Second: ".$rrule[1]->format('Y-m-d'). + "
\n Today: ".($today?'Yes':'no'). + "
\n Next Inc: ".$next_inc->format('Y-m-d'). + "
\n Next Exc: ".$next_exc->format('Y-m-d'); + updateIssueBody($issue,$result); + + //is it today? + if($today){ + $issue->addComment("Today (NEXT:".$next_exc->format('Y-m-d').")"); + } + + // not working https://github.com/go-gitea/gitea/issues/8179 + //$issue->due_date=$rrule[0]->format('c'); + //$issue->save(); }