当前位置: 首页>>代码示例>>PHP>>正文


PHP TTDate::calculateTimeOnEachDayBetweenRange方法代码示例

本文整理汇总了PHP中TTDate::calculateTimeOnEachDayBetweenRange方法的典型用法代码示例。如果您正苦于以下问题:PHP TTDate::calculateTimeOnEachDayBetweenRange方法的具体用法?PHP TTDate::calculateTimeOnEachDayBetweenRange怎么用?PHP TTDate::calculateTimeOnEachDayBetweenRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TTDate的用法示例。


在下文中一共展示了TTDate::calculateTimeOnEachDayBetweenRange方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getShiftData


//.........这里部分代码省略.........
             //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);
开发者ID:alachaum,项目名称:timetrex,代码行数:67,代码来源:PayPeriodScheduleFactory.class.php

示例2: getShiftData


//.........这里部分代码省略.........
             }
             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;
 }
开发者ID:J-P-Hanafin,项目名称:TimeTrex-1,代码行数:101,代码来源:PayPeriodScheduleFactory.class.php

示例3: test_calculateTimeOnEachDayBetweenRange

 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);
 }
开发者ID:alachaum,项目名称:timetrex,代码行数:41,代码来源:DateTimeTest.php


注:本文中的TTDate::calculateTimeOnEachDayBetweenRange方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。