Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getSecondTuesday($test_date = NULL){
- if ($test_date == NULL) {$current_date = array(date("n",time()), date("j",time()), date("Y",time()));}
- else {$current_date = array(date("n",$test_date), date("j",$test_date), date("Y",$test_date));}
- var_dump($test_date);
- $result_date = $current_date;
- $month_begin_weekday = date("w",mktime(0,0,0,$current_date[0],1,$current_date[2]));
- if (self::debug) echo "First day of the month is: ".$month_begin_weekday."<br/>\n";
- if($month_begin_weekday==2){
- if (self::debug) echo "First day of the month is the first Tuesday of the month. Second Tuesday is in exactly one week.<br/>\n";
- $result_date[1] = date("j",mktime(0,0,0,$current_date[0],1,$current_date[2])) + 7;
- }
- elseif($month_begin_weekday>2){
- if (self::debug) echo "This week's Tuesday not require_onced in this month. FF a little less than two weeks.<br/>\n";
- $result_date[1] = date("j",mktime(0,0,0,$current_date[0],1,$current_date[2])) + (14 - ($month_begin_weekday-2));
- }
- else{
- if (self::debug) echo "This week's Tuesday is the first Tuesday of the month. FF a little more than one week.<br/>\n";
- $result_date[1] = date("j",mktime(0,0,0,$current_date[0],1,$current_date[2])) + (7 + (2-$month_begin_weekday));
- }
- return $result_date;
- }
- static public function getNextSecondTuesday($testDate = NULL){
- if ($testDate == NULL) {$testDate = time();}
- if (self::debug) {
- echo "Date to be tested: <br/>\n";
- print_r($testDate);
- echo "<br/>\n";
- }
- $result = getSecondTuesday($testDate);
- if ($result[1] < $testDate[1]){
- if (self::debug) echo "This month's meeting is passed, get Second Tuesday for next month.<br/>\n";
- $testDate[0]++;
- $result = getSecondTuesday($testDate);
- }
- $the_result = mktime(18,0,0,$result[0], $result[1], $result[2]);
- return $the_result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement