function getShiftData($user_date_id = NULL, $user_id = NULL, $epoch = NULL, $filter = NULL, $tmp_punch_control_obj = NULL, $maximum_shift_time = NULL, $new_shift_trigger_time = NULL, $plf = NULL) { global $profiler; $profiler->startTimer('PayPeriodScheduleFactory::getShiftData()'); if (is_numeric($user_date_id) and $user_date_id > 0) { $user_id = $epoch = NULL; } if ($user_date_id == '' and $user_id == '' and $epoch == '') { return FALSE; } if ($maximum_shift_time === NULL) { $maximum_shift_time = $this->getMaximumShiftTime(); } //Debug::text('User Date ID: '. $user_date_id .' User ID: '. $user_id .' TimeStamp: '. TTDate::getDate('DATE+TIME', $epoch), __FILE__, __LINE__, __METHOD__, 10); if ($new_shift_trigger_time === NULL) { $new_shift_trigger_time = $this->getNewDayTriggerTime(); } if (!is_object($plf)) { $plf = TTnew('PunchListFactory'); if ($user_date_id != '') { $plf->getByUserDateId($user_date_id); } else { //Get punches by time stamp. $punch_control_id = 0; if (is_object($tmp_punch_control_obj)) { $punch_control_id = $tmp_punch_control_obj->getId(); } //We need to double the maximum shift time when searching for punches. //Assuming a maximum punch time of 14hrs: // In: 10:00AM Out: 2:00PM // In: 6:00PM Out: 6:00AM (next day) // The above scenario when adding the last 6:00AM punch on the next day will only look back 14hrs and not find the first // punch pair, therefore allowing more than 14hrs on the same day. // So we need to extend the maximum shift time just when searching for punches and let getShiftData() sort out the proper maximum shift time itself. $plf->getShiftPunchesByUserIDAndEpoch($user_id, $epoch, $punch_control_id, $maximum_shift_time * 2); unset($punch_control_id); } } Debug::text('Punch Rows: ' . $plf->getRecordCount() . ' UserID: ' . $user_id . ' Date: ' . TTDate::getDate('DATE+TIME', $epoch) . '(' . $epoch . ') MaximumShiftTime: ' . $maximum_shift_time . ' Filter: ' . $filter, __FILE__, __LINE__, __METHOD__, 10); if ($plf->getRecordCount() > 0) { $shift = 0; $i = 0; $nearest_shift_id = 0; $nearest_punch_difference = FALSE; $prev_punch_obj = FALSE; foreach ($plf as $p_obj) { //Debug::text('Shift: '. $shift .' Punch ID: '. $p_obj->getID() .' Punch Control ID: '. $p_obj->getPunchControlID() .' TimeStamp: '. TTDate::getDate('DATE+TIME', $p_obj->getTimeStamp() ), __FILE__, __LINE__, __METHOD__, 10); //If we're editing a punch, we need to use the object passed to this function instead of the one //from the database. if ($epoch == NULL) { //If user_date_id is passed without epoch, set epoch to the first punch we find. $epoch = $p_obj->getTimeStamp(); } if (isset($prev_punch_arr) and $p_obj->getTimeStamp() > $prev_punch_arr['time_stamp']) { $shift_data[$shift]['previous_punch_key'] = $i - 1; if ($shift_data[$shift]['previous_punch_key'] < 0) { $shift_data[$shift]['previous_punch_key'] = NULL; } } //Determine if a non-saved PunchControl object was passed, and if so, match the IDs to use that instead. if (is_object($tmp_punch_control_obj) and $p_obj->getPunchControlID() == $tmp_punch_control_obj->getId()) { Debug::text('Passed non-saved punch control object that matches, using that instead... Using ID: ' . (int) $tmp_punch_control_obj->getId(), __FILE__, __LINE__, __METHOD__, 10); $punch_control_obj = $tmp_punch_control_obj; } else { $punch_control_obj = $p_obj->getPunchControlObject(); } //Can't use PunchControl object total_time because the record may not be saved yet when editing //an already existing punch. //When editing, simply pass the existing PunchControl object to this function so we can //use it instead of the one in the database perhaps? $total_time = $punch_control_obj->getTotalTime(); //We can't skip records with total_time == 0, because then when deleting one of the two //punches in a pair, the remaining punch is ignored and causing punches to jump around between days in some cases. if ($i > 0 and isset($shift_data[$shift]['last_out']) and ($p_obj->getStatus() == 10 or $p_obj->getStatus() == $prev_punch_arr['status_id'])) { Debug::text('Checking for new shift... This Control ID: ' . $p_obj->getPunchControlID() . ' Last Out Control ID: ' . $shift_data[$shift]['last_out']['punch_control_id'] . ' Last Out Time: ' . TTDate::getDate('DATE+TIME', $shift_data[$shift]['last_out']['time_stamp']), __FILE__, __LINE__, __METHOD__, 10); //Assume that if two punches are assigned to the same punch_control_id are the same shift, even if the time between //them exceeds the new_shift_trigger_time. This helps fix the bug where you could add a In punch then add a Out //punch BEFORE the In punch as long as it was more than the Maximum Shift Time before the In Punch. //ie: Add: In Punch 10-Dec-09 @ 8:00AM, Add: Out Punch 09-Dec-09 @ 5:00PM. //Basically it just helps the validation checks to determine the error. // //It used to be that if shifts are split at midnight, new_shift_trigger_time must be 0, so the "split" punch can occur at midnight. //However we have since added a check to see if punches span midnight and trigger a new shift based on that, regardless of the new shift trigger time. //As the new_shift_trigger_time of 0 also affected lunch/break automatic detection by Punch Time, since an Out punch and a In punch of any time //would trigger a new shift, and it wouldn't be detected as lunch/break. // //What happens when the employee takes lunch/break over midnight? Lunch out at 11:30PM Lunch IN at 12:30AM // We need to split those into two lunches, or two breaks? But then that can affect those policies if they are only allowed one break. // Or do we not split the shift at all when this occurs? Currently we don't split at all. if ($p_obj->getPunchControlID() != $shift_data[$shift]['last_out']['punch_control_id'] and ($p_obj->getTimeStamp() - $shift_data[$shift]['last_out']['time_stamp'] >= $new_shift_trigger_time or $this->getShiftAssignedDay() == 40 and $p_obj->getType() == 10 and $shift_data[$shift]['last_out']['type_id'] == 10 and TTDate::doesRangeSpanMidnight($shift_data[$shift]['last_out']['time_stamp'], $p_obj->getTimeStamp(), TRUE) == TRUE)) { $shift++; } } elseif ($i > 0 and isset($prev_punch_arr['time_stamp']) and $prev_punch_arr['punch_control_id'] != $p_obj->getPunchControlId() and abs($prev_punch_arr['time_stamp'] - $p_obj->getTimeStamp()) > $maximum_shift_time) { //Debug::text(' New shift because two punch_control records exist and punch timestamp exceed maximum shift time.', __FILE__, __LINE__, __METHOD__, 10); $shift++; } if (!isset($shift_data[$shift]['total_time'])) { $shift_data[$shift]['total_time'] = 0; } $punch_day_epoch = TTDate::getBeginDayEpoch($p_obj->getTimeStamp()); if (!isset($shift_data[$shift]['total_time_per_day'][$punch_day_epoch])) { $shift_data[$shift]['total_time_per_day'][$punch_day_epoch] = 0; } //Determine which shift is closest to the given epoch. $punch_difference_from_epoch = abs($epoch - $p_obj->getTimeStamp()); if ($nearest_punch_difference === FALSE or $punch_difference_from_epoch <= $nearest_punch_difference) { Debug::text('Nearest Shift Determined to be: ' . $shift . ' Nearest Punch Diff: ' . (int) $nearest_punch_difference . ' Punch Diff: ' . $punch_difference_from_epoch, __FILE__, __LINE__, __METHOD__, 10); //If two punches have the same timestamp, use the shift that matches the passed punch control object, which is usually the one we are currently editing... //This is for splitting shifts at exactly midnight. if ($punch_difference_from_epoch != $nearest_punch_difference or $punch_difference_from_epoch == $nearest_punch_difference and (is_object($tmp_punch_control_obj) and $tmp_punch_control_obj->getId() == $p_obj->getPunchControlID())) { //Debug::text('Found two punches with the same timestamp... Tmp Punch Control: '.$tmp_punch_control_obj->getId() .' Punch Control: '. $p_obj->getPunchControlID() , __FILE__, __LINE__, __METHOD__, 10); $nearest_shift_id = $shift; $nearest_punch_difference = $punch_difference_from_epoch; } } $punch_arr = array('id' => $p_obj->getId(), 'punch_control_id' => $p_obj->getPunchControlId(), 'user_date_id' => $punch_control_obj->getUserDateID(), 'time_stamp' => $p_obj->getTimeStamp(), 'status_id' => $p_obj->getStatus(), 'type_id' => $p_obj->getType()); $shift_data[$shift]['punches'][] = $punch_arr; $shift_data[$shift]['punch_control_ids'][] = $p_obj->getPunchControlId(); if ($punch_control_obj->getUserDateID() != FALSE) { $shift_data[$shift]['user_date_ids'][] = $punch_control_obj->getUserDateID(); } if (!isset($shift_data[$shift]['span_midnight'])) { $shift_data[$shift]['span_midnight'] = FALSE; } if (!isset($shift_data[$shift]['first_in']) and $p_obj->getStatus() == 10) { //Debug::text('First In -- Punch ID: '. $p_obj->getID() .' Punch Control ID: '. $p_obj->getPunchControlID() .' TimeStamp: '. TTDate::getDate('DATE+TIME', $p_obj->getTimeStamp() ), __FILE__, __LINE__, __METHOD__, 10); $shift_data[$shift]['first_in'] = $punch_arr; } elseif ($p_obj->getStatus() == 20) { //Debug::text('Last Out -- Punch ID: '. $p_obj->getID() .' Punch Control ID: '. $p_obj->getPunchControlID() .' TimeStamp: '. TTDate::getDate('DATE+TIME', $p_obj->getTimeStamp() ), __FILE__, __LINE__, __METHOD__, 10); $shift_data[$shift]['last_out'] = $punch_arr; //Debug::text('Total Time: '. $total_time, __FILE__, __LINE__, __METHOD__, 10); $shift_data[$shift]['total_time'] += $total_time; //Check to see if the previous punch was on a different day then the current punch. if (isset($prev_punch_arr) and is_array($prev_punch_arr) and ($p_obj->getStatus() == 20 and $prev_punch_arr['status_id'] != 20) and TTDate::doesRangeSpanMidnight($prev_punch_arr['time_stamp'], $p_obj->getTimeStamp()) == TRUE) { Debug::text('Punch PAIR DOES span midnight', __FILE__, __LINE__, __METHOD__, 10); $shift_data[$shift]['span_midnight'] = TRUE; $total_time_for_each_day_arr = TTDate::calculateTimeOnEachDayBetweenRange($prev_punch_arr['time_stamp'], $p_obj->getTimeStamp()); if (is_array($total_time_for_each_day_arr)) { foreach ($total_time_for_each_day_arr as $begin_day_epoch => $day_total_time) { if (!isset($shift_data[$shift]['total_time_per_day'][$begin_day_epoch])) { $shift_data[$shift]['total_time_per_day'][$begin_day_epoch] = 0; } $shift_data[$shift]['total_time_per_day'][$begin_day_epoch] += $day_total_time; } } unset($total_time_for_each_day_arr, $begin_day_epoch, $day_total_time, $prev_day_total_time); } else { $shift_data[$shift]['total_time_per_day'][$punch_day_epoch] += $total_time; } } $prev_punch_arr = $punch_arr; $i++; } //Debug::Arr($shift_data, 'aShift Data:', __FILE__, __LINE__, __METHOD__, 10); if (isset($shift_data)) { //Loop through each shift to determine the day with the most time. foreach ($shift_data as $tmp_shift_key => $tmp_shift_data) { krsort($shift_data[$tmp_shift_key]['total_time_per_day']); //Sort by day first arsort($shift_data[$tmp_shift_key]['total_time_per_day']); //Sort by total time per day. reset($shift_data[$tmp_shift_key]['total_time_per_day']); $shift_data[$tmp_shift_key]['day_with_most_time'] = key($shift_data[$tmp_shift_key]['total_time_per_day']); $shift_data[$tmp_shift_key]['punch_control_ids'] = array_unique($shift_data[$tmp_shift_key]['punch_control_ids']); if (isset($shift_data[$tmp_shift_key]['user_date_ids'])) { $shift_data[$tmp_shift_key]['user_date_ids'] = array_unique($shift_data[$tmp_shift_key]['user_date_ids']); } } unset($tmp_shift_key, $tmp_shift_data); if ($filter == 'first_shift') { //Only return first shift. $shift_data = $shift_data[0]; } elseif ($filter == 'last_shift') { //Only return last shift. $shift_data = $shift_data[$shift]; } elseif ($filter == 'nearest_shift') { $shift_data = $shift_data[$nearest_shift_id]; //Check to make sure the nearest shift is within the new shift trigger time of EPOCH. if (isset($shift_data['first_in']['time_stamp'])) { $first_in = $shift_data['first_in']['time_stamp']; } elseif (isset($shift_data['last_out']['time_stamp'])) { $first_in = $shift_data['last_out']['time_stamp']; } if (isset($shift_data['last_out']['time_stamp'])) { $last_out = $shift_data['last_out']['time_stamp']; } elseif (isset($shift_data['first_in']['time_stamp'])) { $last_out = $shift_data['first_in']['time_stamp']; } //The check below must occur so if the user attempts to add an In punch that occurs AFTER the Out punch, this function //still returns the shift data, so the validation checks can occur in PunchControl factory. if ($first_in > $last_out) { //It appears that the first in punch has occurred after the OUT punch, so swap first_in and last_out, so we don't return FALSE in this case. list($first_in, $last_out) = array($last_out, $first_in); } if (TTDate::isTimeOverLap($epoch, $epoch, $first_in - $new_shift_trigger_time, $last_out + $new_shift_trigger_time) == FALSE) { Debug::Text('Nearest shift is outside the new shift trigger time... Epoch: ' . $epoch . ' First In: ' . $first_in . ' Last Out: ' . $last_out . ' New Shift Trigger: ' . $new_shift_trigger_time, __FILE__, __LINE__, __METHOD__, 10); return FALSE; } unset($first_in, $last_out); } $profiler->stopTimer('PayPeriodScheduleFactory::getShiftData()'); //Debug::Arr($shift_data, 'bShift Data:', __FILE__, __LINE__, __METHOD__, 10); return $shift_data; } } $profiler->stopTimer('PayPeriodScheduleFactory::getShiftData()'); return FALSE; }
function getShiftData($user_date_id = NULL, $user_id = NULL, $epoch = NULL, $filter = NULL, $tmp_punch_control_obj = NULL) { global $profiler; $profiler->startTimer('PayPeriodScheduleFactory::getShiftData()'); if (is_numeric($user_date_id) and $user_date_id > 0) { $user_id = $epoch = NULL; } if ($user_date_id == '' and $user_id == '' and $epoch == '') { return FALSE; } //Debug::text('User Date ID: '. $user_date_id .' User ID: '. $user_id .' TimeStamp: '. TTDate::getDate('DATE+TIME', $epoch), __FILE__, __LINE__, __METHOD__, 10); $new_shift_trigger_time = $this->getNewDayTriggerTime(); $plf = new PunchListFactory(); if ($user_date_id != '') { $plf->getByUserDateId($user_date_id); } else { //Get punches by time stamp. $punch_control_id = 0; if (is_object($tmp_punch_control_obj)) { $punch_control_id = $tmp_punch_control_obj->getId(); } $plf->getShiftPunchesByUserIDAndEpoch($user_id, $epoch, $punch_control_id, $this->getMaximumShiftTime()); unset($punch_control_id); } Debug::text('Punch Rows: ' . $plf->getRecordCount() . ' UserID: ' . $user_id . ' Date: ' . TTDate::getDate('DATE+TIME', $epoch) . '(' . $epoch . ') MaximumShiftTime: ' . $this->getMaximumShiftTime(), __FILE__, __LINE__, __METHOD__, 10); //Debug::Arr($punches, ' Punches: ', __FILE__, __LINE__, __METHOD__, 10); if ($plf->getRecordCount() > 0) { $shift = 0; $i = 0; $nearest_shift_id = 0; $nearest_punch_difference = FALSE; $prev_punch_obj = FALSE; foreach ($plf as $p_obj) { //Debug::text('Shift: '. $shift .' Punch ID: '. $p_obj->getID() .' Punch Control ID: '. $p_obj->getPunchControlID() .' TimeStamp: '. TTDate::getDate('DATE+TIME', $p_obj->getTimeStamp() ), __FILE__, __LINE__, __METHOD__, 10); //If we're editing a punch, we need to use the object passed to this function instead of the one //from the database. if ($epoch == NULL) { //If user_date_id is passed without epoch, set epoch to the first punch we find. $epoch = $p_obj->getTimeStamp(); } if (isset($prev_punch_arr) and $p_obj->getTimeStamp() > $prev_punch_arr['time_stamp']) { $shift_data[$shift]['previous_punch_key'] = $i - 1; if ($shift_data[$shift]['previous_punch_key'] < 0) { $shift_data[$shift]['previous_punch_key'] = NULL; } } //Determine if a non-saved PunchControl object was passed, and if so, match the IDs to use that instead. if (is_object($tmp_punch_control_obj) and $p_obj->getPunchControlID() == $tmp_punch_control_obj->getId()) { Debug::text('Passed non-saved punch control object that matches, using that instead... Using ID: ' . (int) $tmp_punch_control_obj->getId(), __FILE__, __LINE__, __METHOD__, 10); $punch_control_obj = $tmp_punch_control_obj; } else { $punch_control_obj = $p_obj->getPunchControlObject(); } //Can't use PunchControl object total_time because the record may not be saved yet when editing //an already existing punch. //When editing, simply pass the existing PunchControl object to this function so we can //use it instead of the one in the database perhaps? $total_time = $punch_control_obj->getTotalTime(); /* //We can't skip records with total_time == 0, because then when deleting one of the two //punches in a pair, the remaining punch is ignored and causing punches to jump around between days in some cases. if ( $total_time == 0 ) { Debug::text('Total time is 0, skipping this punch control object...', __FILE__, __LINE__, __METHOD__, 10); //continue; } */ if ($i > 0 and isset($shift_data[$shift]['last_out']) and ($p_obj->getStatus() == 10 or $p_obj->getStatus() == $prev_punch_arr['status_id'])) { Debug::text('Checking for new shift...', __FILE__, __LINE__, __METHOD__, 10); if ($p_obj->getTimeStamp() - $shift_data[$shift]['last_out']['time_stamp'] > $new_shift_trigger_time) { $shift++; } } if (!isset($shift_data[$shift]['total_time'])) { $shift_data[$shift]['total_time'] = 0; } $punch_day_epoch = TTDate::getBeginDayEpoch($p_obj->getTimeStamp()); if (!isset($shift_data[$shift]['total_time_per_day'][$punch_day_epoch])) { $shift_data[$shift]['total_time_per_day'][$punch_day_epoch] = 0; } //Determine which shift is closest to the given epoch. $punch_difference_from_epoch = abs($epoch - $p_obj->getTimeStamp()); if ($nearest_punch_difference === FALSE or $punch_difference_from_epoch < $nearest_punch_difference) { Debug::text('Nearest Shift Determined to be: ' . $shift . ' Nearest Punch Diff: ' . (int) $nearest_punch_difference . ' Punch Diff: ' . $punch_difference_from_epoch, __FILE__, __LINE__, __METHOD__, 10); $nearest_shift_id = $shift; $nearest_punch_difference = $punch_difference_from_epoch; } $punch_arr = array('id' => $p_obj->getId(), 'punch_control_id' => $p_obj->getPunchControlId(), 'user_date_id' => $punch_control_obj->getUserDateID(), 'time_stamp' => $p_obj->getTimeStamp(), 'status_id' => $p_obj->getStatus(), 'type_id' => $p_obj->getType()); $shift_data[$shift]['punches'][] = $punch_arr; $shift_data[$shift]['punch_control_ids'][] = $p_obj->getPunchControlId(); if ($punch_control_obj->getUserDateID() != FALSE) { $shift_data[$shift]['user_date_ids'][] = $punch_control_obj->getUserDateID(); } $shift_data[$shift]['span_midnight'] = FALSE; if (!isset($shift_data[$shift]['first_in']) and $p_obj->getStatus() == 10) { //Debug::text('First In -- Punch ID: '. $p_obj->getID() .' Punch Control ID: '. $p_obj->getPunchControlID() .' TimeStamp: '. TTDate::getDate('DATE+TIME', $p_obj->getTimeStamp() ), __FILE__, __LINE__, __METHOD__, 10); $shift_data[$shift]['first_in'] = $punch_arr; } elseif ($p_obj->getStatus() == 20) { //Debug::text('Last Out -- Punch ID: '. $p_obj->getID() .' Punch Control ID: '. $p_obj->getPunchControlID() .' TimeStamp: '. TTDate::getDate('DATE+TIME', $p_obj->getTimeStamp() ), __FILE__, __LINE__, __METHOD__, 10); $shift_data[$shift]['last_out'] = $punch_arr; //Debug::text('Total Time: '. $total_time, __FILE__, __LINE__, __METHOD__, 10); $shift_data[$shift]['total_time'] += $total_time; //Check to see if the previous punch was on a different day then the current punch. if (isset($prev_punch_arr) and is_array($prev_punch_arr) and ($p_obj->getStatus() == 20 and $prev_punch_arr['status_id'] != 20) and TTDate::doesRangeSpanMidnight($prev_punch_arr['time_stamp'], $p_obj->getTimeStamp()) == TRUE) { Debug::text('Punch pair DOES span midnight', __FILE__, __LINE__, __METHOD__, 10); $shift_data[$shift]['span_midnight'] = TRUE; $total_time_for_each_day_arr = TTDate::calculateTimeOnEachDayBetweenRange($prev_punch_arr['time_stamp'], $p_obj->getTimeStamp()); if (is_array($total_time_for_each_day_arr)) { foreach ($total_time_for_each_day_arr as $begin_day_epoch => $day_total_time) { if (!isset($shift_data[$shift]['total_time_per_day'][$begin_day_epoch])) { $shift_data[$shift]['total_time_per_day'][$begin_day_epoch] = 0; } $shift_data[$shift]['total_time_per_day'][$begin_day_epoch] += $day_total_time; } } unset($total_time_for_each_day_arr, $begin_day_epoch, $day_total_time, $prev_day_total_time); } else { $shift_data[$shift]['total_time_per_day'][$punch_day_epoch] += $total_time; } } $prev_punch_arr = $punch_arr; $i++; } //Debug::Arr($shift_data, 'aShift Data:', __FILE__, __LINE__, __METHOD__, 10); if (isset($shift_data)) { //Loop through each shift to determine the day with the most time. foreach ($shift_data as $tmp_shift_key => $tmp_shift_data) { krsort($shift_data[$tmp_shift_key]['total_time_per_day']); //Sort by day first arsort($shift_data[$tmp_shift_key]['total_time_per_day']); //Sort by total time per day. reset($shift_data[$tmp_shift_key]['total_time_per_day']); $shift_data[$tmp_shift_key]['day_with_most_time'] = key($shift_data[$tmp_shift_key]['total_time_per_day']); $shift_data[$tmp_shift_key]['punch_control_ids'] = array_unique($shift_data[$tmp_shift_key]['punch_control_ids']); if (isset($shift_data[$tmp_shift_key]['user_date_ids'])) { $shift_data[$tmp_shift_key]['user_date_ids'] = array_unique($shift_data[$tmp_shift_key]['user_date_ids']); } } unset($tmp_shift_key, $tmp_shift_data); if ($filter == 'first_shift') { //Only return first shift. $shift_data = $shift_data[0]; } elseif ($filter == 'last_shift') { //Only return last shift. $shift_data = $shift_data[$shift]; } elseif ($filter == 'nearest_shift') { $shift_data = $shift_data[$nearest_shift_id]; //Check to make sure the nearest shift is within the new shift trigger time of EPOCH. if (isset($shift_data['first_in']['time_stamp'])) { $first_in = $shift_data['first_in']['time_stamp']; } elseif (isset($shift_data['last_out']['time_stamp'])) { $first_in = $shift_data['last_out']['time_stamp']; } if (isset($shift_data['last_out']['time_stamp'])) { $last_out = $shift_data['last_out']['time_stamp']; } elseif (isset($shift_data['first_in']['time_stamp'])) { $last_out = $shift_data['first_in']['time_stamp']; } if (TTDate::isTimeOverLap($epoch, $epoch, $first_in - $new_shift_trigger_time, $last_out + $new_shift_trigger_time) == FALSE) { Debug::Text('Nearest shift is outside the new shift trigger time... Epoch: ' . $epoch . ' First In: ' . $first_in . ' Last Out: ' . $last_out . ' New Shift Trigger: ' . $new_shift_trigger_time, __FILE__, __LINE__, __METHOD__, 10); return FALSE; } unset($first_in, $last_out); } $profiler->stopTimer('PayPeriodScheduleFactory::getShiftData()'); //Debug::Arr($shift_data, 'bShift Data:', __FILE__, __LINE__, __METHOD__, 10); return $shift_data; } } $profiler->stopTimer('PayPeriodScheduleFactory::getShiftData()'); return FALSE; }
function test_calculateTimeOnEachDayBetweenRange() { $test1_result = TTDate::calculateTimeOnEachDayBetweenRange(strtotime('01-Jan-09 8:00AM'), strtotime('01-Jan-09 11:30PM')); $this->assertEquals(count($test1_result), 1); $this->assertEquals($test1_result[1230796800], 55800); $test2_result = TTDate::calculateTimeOnEachDayBetweenRange(strtotime('01-Jan-09 4:00PM'), strtotime('02-Jan-09 8:00AM')); $this->assertEquals(count($test2_result), 2); $this->assertEquals($test2_result[1230796800], 28800); $this->assertEquals($test2_result[1230883200], 28800); $test3_result = TTDate::calculateTimeOnEachDayBetweenRange(strtotime('01-Jan-09 4:00PM'), strtotime('03-Jan-09 8:00AM')); $this->assertEquals(count($test3_result), 3); $this->assertEquals($test3_result[1230796800], 28800); $this->assertEquals($test3_result[1230883200], 86400); $this->assertEquals($test3_result[1230969600], 28800); $test4_result = TTDate::calculateTimeOnEachDayBetweenRange(strtotime('01-Jan-09 4:00PM'), strtotime('9-Jan-09 8:00AM')); $this->assertEquals(count($test4_result), 9); $this->assertEquals($test4_result[1230796800], 28800); $this->assertEquals($test4_result[1230883200], 86400); $this->assertEquals($test4_result[1230969600], 86400); $this->assertEquals($test4_result[1231056000], 86400); $this->assertEquals($test4_result[1231142400], 86400); $this->assertEquals($test4_result[1231228800], 86400); $this->assertEquals($test4_result[1231315200], 86400); $this->assertEquals($test4_result[1231401600], 86400); $this->assertEquals($test4_result[1231488000], 28800); $test5_result = TTDate::calculateTimeOnEachDayBetweenRange(strtotime('01-Jan-09 12:00AM'), strtotime('01-Jan-09 12:59:59PM')); $this->assertEquals(count($test5_result), 1); $this->assertEquals($test5_result[1230796800], 46799); $test5_result = TTDate::calculateTimeOnEachDayBetweenRange(strtotime('01-Jan-09 12:00AM'), strtotime('02-Jan-09 12:00AM')); $this->assertEquals(count($test5_result), 1); $this->assertEquals($test5_result[1230796800], 86400); $test5_result = TTDate::calculateTimeOnEachDayBetweenRange(strtotime('01-Jan-09 12:01AM'), strtotime('02-Jan-09 12:01AM')); $this->assertEquals(count($test5_result), 2); $this->assertEquals($test5_result[1230796800], 86340); $this->assertEquals($test5_result[1230883200], 60); $test5_result = TTDate::calculateTimeOnEachDayBetweenRange(strtotime('01-Jan-09 1:53PM'), strtotime('03-Jan-09 6:12AM')); $this->assertEquals(count($test5_result), 3); $this->assertEquals($test5_result[1230796800], 36420); $this->assertEquals($test5_result[1230883200], 86400); $this->assertEquals($test5_result[1230969600], 22320); }