0 ); } */ function localDayOfWeek($timestamp) { if(!isset($timestamp)) { $timestamp = time(); } return date('l', $timestamp); } function signupAllowed($weeks, $signup_timestamp, $timezone_offset) { // $gmt_now = strtotime('now'); // http://php.net/strtotime $gmt_now = strtotime($_REQUEST['simnow']); $today_is_cutoff_day = (localDayOfWeek($gmt_now) == 'Monday'); if($today_is_cutoff_day) $base_cutoff_timestamp = strtotime('this Monday 9am' , $gmt_now); else $base_cutoff_timestamp = strtotime('last Monday 9am' , $gmt_now); // returns datestamp corresponding to cutoff date // $cutoff_timestamp is $base_cutoff_timestamp + however many weeks, minus one second. $cutoff_timestamp = strtotime('+'.strval($weeks) . ' week -1 second', $base_cutoff_timestamp); // 's' suffix ignored; -1 second to make sun 23:59:59 // /* global $br; echo 'DATES:
'; echo ''; echo '' . "\n"; echo '' . "\n"; // echo '' . "\n"; echo '' . "\n"; //echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '
'.date('l', $gmt_now). ' is ' . ($today_is_cutoff_day ? '' : 'not ') . 'Monday (cutoff day)
time() is ' . $gmt_now . '' . date('D M j Y, G:i:s', $gmt_now) . '
local_now is ' . $local_now . '' . date('D M j Y, G:i:s', $local_now) . '
the *base* cutoff day was/is ' . $base_cutoff_timestamp . '' . date('D M j Y, G:i:s', $base_cutoff_timestamp) .'
the *adjusted* cutoff day was/is ' . $adjusted_cutoff_timestamp . '' . date('D M j Y, G:i:s', $adjusted_cutoff_timestamp) . '
the *actual* cutoff date is ' . $cutoff_timestamp . '' . date('D M j Y, G:i:s', $cutoff_timestamp) . '
the *signup* date is ' . $signup_timestamp . '' . date('D M j Y, G:i:s', $signup_timestamp) . '
'; // */ // positive if the signup is sooner than the cutoff; 0 if equal, negative if it's later. return ( ($cutoff_timestamp - $signup_timestamp) > 0 ); } $br = '
'; if( isset($_REQUEST['rel_time']) && isset($_REQUEST['weeks']) && isset($_REQUEST['offset']) ) { echo $_REQUEST['rel_time'] . $br; $result = signupAllowed(intval($_REQUEST['weeks']), strtotime($_REQUEST['rel_time']), intval($_REQUEST['offset'])); echo 'result is '; echo ($result) ? 'true' : 'false'; echo "$br$br$br"; } $realnow = date('M j Y G:i:s', time()); if (! isset($_REQUEST['simnow'])) { $_REQUEST['simnow'] = $realnow; } echo << Simulated Current Time: e.g. $realnow
Weeks-interval: e.g. 1 or 2 or 3
Date string: e.g. +1 week -3 days
(strtotime()/date syntax)
Offset in seconds: e.g. -3600
FORMULAIC; ?>
Show PHP Source