<?php
//$current_date = mktime(0, 0, 0, date("m"), date("d"), date("Y"));
//$permit_active_date = mktime(0, 0, 0, date("m"), date("d"), date("Y"));
$current_date = mktime(0, 0, 0, 10, 25, 2018);
$permit_active_date = mktime(0, 0, 0, 10, 25, 2018);
$pay_frequency = "BW";
$UCDHS_MasterPaySchedule = array (
"BW" => array (
array (
"file_submit_date" => mktime(0,0,0,9,14,2018),
"pay_check_date" => mktime(0,0,0,9,19,2018),
"park_period_start" => mktime(0,0,0,10,1,2018),
"park_period_end" => mktime(0,0,0,10,15,2018),
"check_num" => 1
),
array (
"file_submit_date" => mktime(0,0,0,9,28,2018),
"pay_check_date" => mktime(0,0,0,10,3,2018),
"park_period_start" => mktime(0,0,0,10,16,2018),
"park_period_end" => mktime(0,0,0,10,31,2018),
"check_num" => 2
),
array (
"file_submit_date" => mktime(0,0,0,10,12,2018),
"pay_check_date" => mktime(0,0,0,10,17,2018),
"park_period_start" => mktime(0,0,0,11,1,2018),
"park_period_end" => mktime(0,0,0,11,15,2018),
"check_num" => 3
),
array (
"file_submit_date" => mktime(0,0,0,11,8,2018),
"pay_check_date" => mktime(0,0,0,11,14,2018),
"park_period_start" => mktime(0,0,0,11,16,2018),
"park_period_end" => mktime(0,0,0,11,30,2018),
"check_num" => 4
),
array (
"file_submit_date" => mktime(0,0,0,11,21,2018),
"pay_check_date" => mktime(0,0,0,11,28,2018),
"park_period_start" => mktime(0,0,0,12,1,2018),
"park_period_end" => mktime(0,0,0,12,15,2018),
"check_num" => 5
),
array (
"file_submit_date" => mktime(0,0,0,12,7,2018),
"pay_check_date" => mktime(0,0,0,12,12,2018),
"park_period_start" => mktime(0,0,0,12,16,2018),
"park_period_end" => mktime(0,0,0,12,31,2018),
"check_num" => 6
)
)
);
//reduce array to pay schedule
// $arrPaySchedule = $UCDHS_MasterPaySchedule[$pay_frequency];
//find pay cycle where parking period includes permit start date
$pay_cycle_for_active_date = get_pay_cycle_for_active_date($current_date, $permit_active_date, $UCDHS_MasterPaySchedule[$pay_frequency]);
print $pay_cycle_for_active_date;
/**
* Number of days between two dates.
*
* @param date $dt1 First date
* @param date $dt2 Second date
* @return int
*/
function daysBetween($dt1, $dt2) {
return date_diff(
date_create($dt2),
date_create($dt1)
)->format('%a');
}
function get_pay_cycle_for_active_date($current_date, $permit_active_date, $arr_pay_schedule) {
// note: function assumes that pay period data is ordered earliest to latest, in the arrPaySchedule array
//default values:
$current_period_id = -1;
$active_period_id = -1;
//$return_file_submit_date
//pay_check_date
//park_period_start
//park_period_end
//check_num
//loop through pay periods...
foreach($arr_pay_schedule as $period_num => $period) {
//find current parking period
if ($current_date >= $period["park_period_start"] && $current_date <= $period["park_period_end"]) {
$current_period_id = $period_num;
}
//find parking period which contains permit_active_date
if ($permit_active_date >= $period["park_period_start"] && $permit_active_date <= $period["park_period_end"]) {
$active_period_id = $period_num;
}
//determine number of days permit is valid in perid permit becomes valid
$days_valid_in_active_period = 0; //daysBetween($permit_active_date, $period["park_period_end"]);
}
echo "current_period_id = ".$current_period_id."\f\r";
echo "active_period_id = ".$active_period_id."\f\r";
echo "days_valid_in_active_period = ".$days_valid_in_active_period."\f\r";
echo "permit_active_date = ".$permit_active_date."/f/r";
echo "period['park_period_end'] = ".$period["park_period_end"]."\f\r";
return "";
// $arrSelectedSchedule = array_filter($arrPaySchedule, function($e) use($permit_active_date) {return ($e["park_period_start"]<=$permit_active_date && $e["park_period_end"]>=$permit_active_date);});
// print_r($arrSelectedSchedule);
// return array_search()
// return count(array_filter($arrPaySchedule, function($e) use($permit_active_date) {return ($e["park_period_start"]<=$permit_active_date && $e["park_period_end"]>=$permit_active_date);}));
}
//$min=mktime(0,0,0,10,1,2018);
//$max=mktime(0,0,0,10,4,2018);
//print count(array_filter($UCDHSPaySchedule["BW"], function($e) use($min,$max) {return ($e["permit_active_date"]>$min && $e["permit_active_date"]<$max);}));
//function gets the number of submittion dates between the $current_date and the submission date for permit starting on $active_date
//function get_cycle_count($current_date, $active_date, $UCDHSPaySchedule) {
//print count(array_filter($UCDHSPaySchedule["BW"], function($e) use($min,$max) {return ($e["permit_active_date"]>$min && //$e["permit_active_date"]<$max);}));
//}
//$cars = array (
//"Volvo" => array("Volvo",22,18),
//"BMW" => array("BMW",15,13),
//"Saab" => array("Saab",5,2),
//"Land Rover" => array("Land Rover",17,15)
//);
//print $cars['Volvo'][0];
?>
- Output for 5.6.38, 7.1.0 - 7.1.23, 7.2.0 - 7.2.33, 7.3.16 - 7.3.31, 7.4.0 - 7.4.33, 8.0.0 - 8.0.12, 8.0.14 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
- current_period_id = 1
active_period_id = 1
days_valid_in_active_period = 0
permit_active_date = 1540418400/f/rperiod['park_period_end'] = 1546210800
- Output for 7.3.32 - 7.3.33, 8.0.13
- current_period_id = 1
active_period_id = 1
days_valid_in_active_period = 0
permit_active_date = 1540425600/f/rperiod['park_period_end'] = 1546214400
preferences:
159.98 ms | 401 KiB | 169 Q