>I' m searching a way to programmatically alternate  2 schedules each sunday
at 00:00. >Schedule1 start on first sunday and seven days later, schedule2
replace schedule1,and seven >days later, schedule1 replace schedule2 etc...

The *easiest* thing to do would be to run a cron job every Sunday at
midnight to flip something...

But, assuming you want to avoid that:

<?php
    $now = time()
    $weeknumber = $now % 52;
    #So now I know which week of the year it is...
    #How do I know if it's "before" or "after" Sunday?
    #Easy:
    $dayofweek = date("w", $now);
    #So, now $dayofweek is either 0, for Sunday, or 1 for Monday, or...
    #Problem, how to mix and match $weeknumber and $dayofweek to "change" on
Sundays
    #Well, did this year start on a Wednesday, or what?
    $newyeardayofweek = date("w", mktime(0, 0, 0, 1, 1, date("Y", $now)));
    #This formula makes a lot more sense if you look at sample data:
/*
Format is:
The Day of week (Sun-Sat)
The day of the year 1-365
$weeknumber/$dayofweek
The right-hand column is 1/2
based on which schedule we want.
                            |
                            |
                            v
                Thu Fri Sat
                1   2   3   1
                0/4 0/5 0/6
Sun Mon Tue Wed Thu Fri Sat
4   5   6   7   8   9   10  2
0/0 0/1 0/2 0/3 1/4 1/5 1/6
Sun Mon Tue Wed Thu Fri Sat
11  12  13  14  15  16  17  1
1/0 1/1 1/2 1/3 2/4 2/5 2/6
Sun Mon Tue Wed Thu Fri Sat
18  19  20  21  22  23  24  2
2/0 2/1 2/2 2/3 3/4 3/5 3/6
*/
    #So, the "trick" is to switch on whether our day of the week is before
or after
    #the day that started the year off.
    if ((($weeknumber % 2) && ($dayofweek >= $newyeardayofweek)) ||
(!($weeknumber % 2) && ($dayofweek < $newyeardayofweek))){
        include 'schedule1';
    }
    else{
        include 'schedule2';
    }
?>

Somebody else probably has a one-line answer.  Oh well. :-)

--
Visit the Zend Store at http://www.zend.com/store/
Wanna help me out?  Like Music?  Buy a CD: http://l-i-e.com/artists.htm
Volunteer a little time: http://chatmusic.com/volunteer.htm



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to