Jump to content

Rotating day assignments with exclusions.


mrplatts

Recommended Posts

Hi,
First, I'm not a programmer, but understand the basics of programming langauges.  I'm learning PHP, so if this seems obvious, I'm sorry in advance. 

What I want to do is allow a user to input a start date & an end date.  The script should then assign a six-day rotation of the numbers 1 thru 6 to weekdays only.  This much I have done.

what I need now is an easy way to:
(1) collect  exceptions to the above rule  -- i.e. weekdays that should not be incremented/assigned a rotation number.

(2) apply those exceptions to the output (eventually exportation to MySQL table, right now, an HTML TABLE.

I'm assigning the rotation using an if - else statement, first checking that the date('w', $s) is not 0 or 6 (weekend) ... I have the rotor working if I manually feed the exclusions, if it passes, it assigns the rotation number, and increments for the next cycle.  Otherwise, it moves on.  THen there is another if{} to check if the number has incremented to seven, then bumps it back to one.

$current_date != $do1 && $current_date != $do2 && $current_date != $do3 && $current_date != $do4

of course, this is terrible in efficient, and not very useful.

Any clues on how you would do this? Ideas to make the code more efficient?

Thanks alot,

Rich
Link to comment
https://forums.phpfreaks.com/topic/26932-rotating-day-assignments-with-exclusions/
Share on other sites

Try something like
[code]
<?php
$excepts = array('2006-12-25', '2006-12-26', '2007-01-01') ;

$today = mktime(0,0,0);
$count = 0;

echo '<pre>';
for ($i=0; $i<90; $i++) {
    $t = strtotime("+$i days", $today);
    $dt = date('Y-m-d', $t);
    if (!in_array($dt, $excepts) && date('w',$t)!=0 && date('w',$t)!=6) {
        $rota = $count++ % 6 + 1;
        if ($rota==1) echo "\n\n";
        printf("<br/>%d : %-5s%-10s", $rota, date('D', $t), date ('d-m-Y', $t) );
    }
}
echo '</pre>';
?>
[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.