php - Generate a date schedule that executes only on weekdays -


i have date schedule function in php aims execute on working days. code have @ moment generating schedule days of week while statement doesn't seem working , i'm not sure why.

i'm student, i'm not experienced kind of thing. here code have far:

public static function generate_date_schedule($tasksperdayschedule, $startdate) {     $schedule = [];      $date = clone $startdate;      foreach ($tasksperdayschedule $numberoftasks) {         $day = (int)$date->format('n');          // skip weekend days.         while ($day > 5) {             $date->add(new dateinterval('p1d'));             $day = (int)$date->format('n');         }          $schedule[$date->format(self::date_format)] = $numberoftasks;          $date->add(new dateinterval('p1d'));     }     return $schedule; 

it small missing, appreciated! thanks

i think simple logical error.

inside while loop you're updating $day, foreach loop continues execute rest of code.

better yet, can avoid while loop by:

if($day > 5)     continue; 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -