本文整理汇总了PHP中TTDate::roundTime方法的典型用法代码示例。如果您正苦于以下问题:PHP TTDate::roundTime方法的具体用法?PHP TTDate::roundTime怎么用?PHP TTDate::roundTime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TTDate
的用法示例。
在下文中一共展示了TTDate::roundTime方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setTimeStamp
function setTimeStamp($epoch, $enable_rounding = TRUE)
{
$epoch = $original_epoch = trim($epoch);
if ($enable_rounding == TRUE and $this->getTransfer() == FALSE) {
$epoch = $this->roundTimeStamp($epoch);
} else {
Debug::text(' Rounding Disabled... ', __FILE__, __LINE__, __METHOD__, 10);
}
//Always round to one min, no matter what. Even on a transfer.
$epoch = TTDate::roundTime($epoch, 60);
if ($this->Validator->isDate('time_stamp', $epoch, TTi18n::gettext('Incorrect time stamp'))) {
Debug::text(' Set: ' . $epoch, __FILE__, __LINE__, __METHOD__, 10);
$this->data['time_stamp'] = $epoch;
return TRUE;
}
return FALSE;
}
示例2: Execute
function Execute($php_cli = NULL, $dir = NULL)
{
global $config_vars;
$lock_file = new LockFile($config_vars['cache']['dir'] . DIRECTORY_SEPARATOR . $this->getName() . '.lock');
//Check job last updated date, if its more then 12hrs and its still in the "running" status,
//chances are its an orphan. Change status.
//if ( $this->getStatus() != 10 AND $this->getLastRunDate() < time()-(12*3600) ) {
if ($this->getStatus() != 10 and $this->getUpdatedDate() > 0 and $this->getUpdatedDate() < time() - 6 * 3600) {
Debug::text('ERROR: Job has been running for more then 6 hours! Asssuming its an orphan, marking as ready for next run.', __FILE__, __LINE__, __METHOD__, 10);
$this->setStatus(10);
$this->Save(FALSE);
$lock_file->delete();
}
if (!is_executable($php_cli)) {
Debug::text('ERROR: PHP CLI is not executable: ' . $php_cli, __FILE__, __LINE__, __METHOD__, 10);
return FALSE;
}
if ($this->isSystemLoadValid() == FALSE) {
Debug::text('System load is too high, skipping...', __FILE__, __LINE__, __METHOD__, 10);
return FALSE;
}
//Cron script to execute
$script = $dir . DIRECTORY_SEPARATOR . $this->getCommand();
if ($this->getStatus() == 10 and $lock_file->exists() == FALSE) {
$lock_file->create();
$this->setExecuteFlag(TRUE);
Debug::text('Job is NOT currently running, running now...', __FILE__, __LINE__, __METHOD__, 10);
//Mark job as running
$this->setStatus(20);
//Running
$this->Save(FALSE);
//Even if the file does not exist, we still need to "pretend" the cron job ran (set last ran date) so we don't
//display the big red error message saying that NO jobs have run in the last 24hrs.
if (file_exists($script)) {
$command = '"' . $php_cli . '" "' . $script . '"';
//if ( OPERATING_SYSTEM == 'WIN' ) {
//Windows requires quotes around the entire command, and each individual section with that might have spaces.
//23-May-13: This seems to cause the command to fail now. Perhaps its related to newer versions of PHP?
//$command = '"'. $command .'"';
//}
Debug::text('Command: ' . $command, __FILE__, __LINE__, __METHOD__, 10);
$start_time = microtime(TRUE);
exec($command, $output, $retcode);
Debug::Arr($output, 'Time: ' . (microtime(TRUE) - $start_time) . 's - Command RetCode: ' . $retcode . ' Output: ', __FILE__, __LINE__, __METHOD__, 10);
TTLog::addEntry($this->getId(), 500, TTi18n::getText('Executing Cron Job') . ': ' . $this->getID() . ' ' . TTi18n::getText('Command') . ': ' . $command . ' ' . TTi18n::getText('Return Code') . ': ' . $retcode, NULL, $this->getTable());
} else {
Debug::text('WARNING: File does not exist, skipping: ' . $script, __FILE__, __LINE__, __METHOD__, 10);
}
$this->setStatus(10);
//Ready
$this->setLastRunDate(TTDate::roundTime(time(), 60, 30));
$this->Save(FALSE);
$this->setExecuteFlag(FALSE);
$lock_file->delete();
return TRUE;
} else {
Debug::text('Job is currently running, skipping...', __FILE__, __LINE__, __METHOD__, 10);
}
return FALSE;
}
示例3: setGrace
function setGrace($value)
{
$value = trim($value);
if ($this->Validator->isNumeric('grace', $value, TTi18n::gettext('Incorrect grace value'))) {
//If someone is using hour parse format ie: 0.12 we need to round to the nearest
//minute other wise it'll be like 7mins and 23seconds messing up rounding.
//$this->data['grace'] = $value;
$this->data['grace'] = TTDate::roundTime($value, 60, 20);
return TRUE;
}
return FALSE;
}
示例4: getAverageTime
function getAverageTime($user_id)
{
$udtlf = TTnew('UserDateTotalListFactory');
//Check if Min and Max time is the same, if so we can skip any averaging.
if ($this->getHolidayPolicyObject()->getMinimumTime() > 0 and $this->getHolidayPolicyObject()->getMaximumTime() > 0 and $this->getHolidayPolicyObject()->getMinimumTime() == $this->getHolidayPolicyObject()->getMaximumTime()) {
Debug::text('Min and Max times are equal.', __FILE__, __LINE__, __METHOD__, 10);
return $this->getHolidayPolicyObject()->getMinimumTime();
}
if ($this->getHolidayPolicyObject()->getAverageTimeWorkedDays() == TRUE) {
Debug::text('Using worked days only...', __FILE__, __LINE__, __METHOD__, 10);
if ($this->getHolidayPolicyObject()->getIncludeOverTime() == TRUE) {
$last_days_worked = (array) $udtlf->getDaysWorkedByUserIDAndStartDateAndEndDate($user_id, $this->getDateStamp() - $this->getHolidayPolicyObject()->getAverageTimeDays() * 86400, $this->getDateStamp() - 86400);
} else {
//Make sure if they aren't including overtime, we don't include days where they only worked overtime.
$last_days_worked = (array) $udtlf->getDaysWorkedRegularTimeByUserIDAndStartDateAndEndDate($user_id, $this->getDateStamp() - $this->getHolidayPolicyObject()->getAverageTimeDays() * 86400, $this->getDateStamp() - 86400);
}
$paid_absence_before_days = array();
if ($this->getHolidayPolicyObject()->getIncludePaidAbsenceTime() == TRUE) {
$paid_absence_before_days = (array) $udtlf->getDaysPaidAbsenceByUserIDAndStartDateAndEndDate($user_id, $this->getDateStamp() - $this->getHolidayPolicyObject()->getAverageTimeDays() * 86400, $this->getDateStamp() - 86400);
Debug::text('Employee has paid absence days prior: ' . count($paid_absence_before_days), __FILE__, __LINE__, __METHOD__, 10);
}
//Debug::Arr($last_days_worked, 'Last Days Worked: ', __FILE__, __LINE__, __METHOD__,10);
$last_days_worked_count = count(array_unique(array_merge($last_days_worked, $paid_absence_before_days)));
unset($last_days_worked, $paid_absence_before_days);
} else {
$last_days_worked_count = $this->getHolidayPolicyObject()->getAverageDays();
}
Debug::text('Average time over days:' . $last_days_worked_count, __FILE__, __LINE__, __METHOD__, 10);
if ($this->getHolidayPolicyObject()->getIncludeOverTime() == TRUE) {
Debug::text('Including OverTime!', __FILE__, __LINE__, __METHOD__, 10);
$total_seconds_worked = $udtlf->getWorkedTimeSumByUserIDAndStartDateAndEndDate($user_id, $this->getDateStamp() - $this->getHolidayPolicyObject()->getAverageTimeDays() * 86400, $this->getDateStamp() - 86400);
} else {
Debug::text('NOT Including OverTime!', __FILE__, __LINE__, __METHOD__, 10);
$total_seconds_worked = $udtlf->getRegularTimeSumByUserIDAndStartDateAndEndDate($user_id, $this->getDateStamp() - $this->getHolidayPolicyObject()->getAverageTimeDays() * 86400, $this->getDateStamp() - 86400);
}
if ($this->getHolidayPolicyObject()->getIncludePaidAbsenceTime() == TRUE) {
//FIXME: How does this affect the number of days worked above?
Debug::text('Including Paid Absence Time!', __FILE__, __LINE__, __METHOD__, 10);
$total_seconds_worked += $udtlf->getPaidAbsenceTimeSumByUserIDAndStartDateAndEndDate($user_id, $this->getDateStamp() - $this->getHolidayPolicyObject()->getAverageTimeDays() * 86400, $this->getDateStamp() - 86400);
} else {
Debug::text('NOT Including Paid Absence Time!', __FILE__, __LINE__, __METHOD__, 10);
}
if ($last_days_worked_count > 0) {
$avg_seconds_worked_per_day = bcdiv($total_seconds_worked, $last_days_worked_count);
Debug::text('AVG hours worked per day:' . TTDate::getHours($avg_seconds_worked_per_day), __FILE__, __LINE__, __METHOD__, 10);
} else {
$avg_seconds_worked_per_day = 0;
}
if ($this->getHolidayPolicyObject()->getMaximumTime() > 0 and $avg_seconds_worked_per_day > $this->getHolidayPolicyObject()->getMaximumTime()) {
$avg_seconds_worked_per_day = $this->getHolidayPolicyObject()->getMaximumTime();
Debug::text('AVG hours worked per day exceeds maximum regulars hours per day, setting to:' . $avg_seconds_worked_per_day / 60 / 60, __FILE__, __LINE__, __METHOD__, 10);
}
if ($avg_seconds_worked_per_day < $this->getHolidayPolicyObject()->getMinimumTime()) {
$avg_seconds_worked_per_day = $this->getHolidayPolicyObject()->getMinimumTime();
Debug::text('AVG hours worked per day is less then minimum regulars hours per day, setting to:' . $avg_seconds_worked_per_day / 60 / 60, __FILE__, __LINE__, __METHOD__, 10);
}
//Round to nearest 15mins.
if ((int) $this->getHolidayPolicyObject()->getRoundIntervalPolicyID() != 0 and is_object($this->getHolidayPolicyObject()->getRoundIntervalPolicyObject())) {
$avg_seconds_worked_per_day = TTDate::roundTime($avg_seconds_worked_per_day, $this->getHolidayPolicyObject()->getRoundIntervalPolicyObject()->getInterval(), $this->getHolidayPolicyObject()->getRoundIntervalPolicyObject()->getRoundType());
Debug::text('Rounding Stat Time To: ' . $avg_seconds_worked_per_day, __FILE__, __LINE__, __METHOD__, 10);
} else {
Debug::text('NOT Rounding Stat Time!', __FILE__, __LINE__, __METHOD__, 10);
}
return $avg_seconds_worked_per_day;
}
示例5: test_roundTime
function test_roundTime()
{
//10 = Down
//20 = Average
//30 = Up
//Test rounding down by 15minutes
$this->assertEquals((int) TTDate::roundTime(strtotime('15-Apr-07 8:06 AM'), 60 * 15, 10), strtotime('15-Apr-07 8:00 AM'));
//Test rounding down by 5minutes
$this->assertEquals((int) TTDate::roundTime(strtotime('15-Apr-07 8:06 AM'), 60 * 5, 10), strtotime('15-Apr-07 8:05 AM'));
//Test rounding down by 5minutes when no rounding should occur.
$this->assertEquals((int) TTDate::roundTime(strtotime('15-Apr-07 8:05 AM'), 60 * 5, 10), strtotime('15-Apr-07 8:05 AM'));
//Test rounding down by 15minutes with 3minute grace.
$this->assertEquals((int) TTDate::roundTime(strtotime('15-Apr-07 4:58 PM'), 60 * 15, 10, 60 * 3), strtotime('15-Apr-07 5:00 PM'));
$this->assertEquals((int) TTDate::roundTime(strtotime('15-Apr-07 4:56 PM'), 60 * 15, 10, 60 * 3), strtotime('15-Apr-07 4:45 PM'));
$this->assertEquals((int) TTDate::roundTime(strtotime('15-Apr-07 5:11 PM'), 60 * 15, 10, 60 * 3), strtotime('15-Apr-07 5:00 PM'));
//Test rounding down by 5minutes with 2minute grace
$this->assertEquals((int) TTDate::roundTime(strtotime('15-Apr-07 5:11 PM'), 60 * 5, 10, 60 * 2), strtotime('15-Apr-07 5:10 PM'));
$this->assertEquals((int) TTDate::roundTime(strtotime('15-Apr-07 5:07 PM'), 60 * 5, 10, 60 * 2), strtotime('15-Apr-07 5:05 PM'));
//Test rounding avg by 15minutes
$this->assertEquals((int) TTDate::roundTime(strtotime('15-Apr-07 8:06 AM'), 60 * 15, 20), strtotime('15-Apr-07 8:00 AM'));
$this->assertEquals((int) TTDate::roundTime(strtotime('15-Apr-07 8:08 AM'), 60 * 15, 20), strtotime('15-Apr-07 8:15 AM'));
//Test rounding avg by 5minutes
$this->assertEquals((int) TTDate::roundTime(strtotime('15-Apr-07 8:06 AM'), 60 * 5, 20), strtotime('15-Apr-07 8:05 AM'));
$this->assertEquals((int) TTDate::roundTime(strtotime('15-Apr-07 8:08 AM'), 60 * 5, 20), strtotime('15-Apr-07 8:10 AM'));
//Test rounding avg by 5minutes when no rounding should occur.
$this->assertEquals((int) TTDate::roundTime(strtotime('15-Apr-07 8:05 AM'), 60 * 5, 20), strtotime('15-Apr-07 8:05 AM'));
//Test rounding up by 15minutes
$this->assertEquals((int) TTDate::roundTime(strtotime('15-Apr-07 8:06 AM'), 60 * 15, 30), strtotime('15-Apr-07 8:15 AM'));
//Test rounding up by 5minutes
$this->assertEquals((int) TTDate::roundTime(strtotime('15-Apr-07 8:06 AM'), 60 * 5, 30), strtotime('15-Apr-07 8:10 AM'));
//Test rounding up by 5minutes when no rounding should occur.
$this->assertEquals((int) TTDate::roundTime(strtotime('15-Apr-07 8:05 AM'), 60 * 5, 30), strtotime('15-Apr-07 8:05 AM'));
//Test rounding up by 15minutes with 3minute grace.
$this->assertEquals((int) TTDate::roundTime(strtotime('15-Apr-07 8:01 AM'), 60 * 15, 30, 60 * 3), strtotime('15-Apr-07 8:00 AM'));
$this->assertEquals((int) TTDate::roundTime(strtotime('15-Apr-07 8:04 AM'), 60 * 15, 30, 60 * 3), strtotime('15-Apr-07 8:15 AM'));
$this->assertEquals((int) TTDate::roundTime(strtotime('15-Apr-07 8:03 AM'), 60 * 15, 30, 60 * 3), strtotime('15-Apr-07 8:00 AM'));
//Test rounding up by 5minutes with 2minute grace
$this->assertEquals((int) TTDate::roundTime(strtotime('15-Apr-07 8:03 AM'), 60 * 5, 30, 60 * 2), strtotime('15-Apr-07 8:05 AM'));
$this->assertEquals((int) TTDate::roundTime(strtotime('15-Apr-07 8:01 AM'), 60 * 5, 30, 60 * 2), strtotime('15-Apr-07 8:00 AM'));
}
示例6: getAverageTime
function getAverageTime($user_id)
{
$udtlf = new UserDateTotalListFactory();
//Check if Min and Max time is the same, if so we can skip any averaging.
if ($this->getHolidayPolicyObject()->getMinimumTime() > 0 and $this->getHolidayPolicyObject()->getMaximumTime() > 0 and $this->getHolidayPolicyObject()->getMinimumTime() == $this->getHolidayPolicyObject()->getMaximumTime()) {
Debug::text('Min and Max times are equal.', __FILE__, __LINE__, __METHOD__, 10);
return $this->getHolidayPolicyObject()->getMinimumTime();
}
if ($this->getHolidayPolicyObject()->getAverageTimeWorkedDays() == TRUE) {
$last_days_worked_count = $udtlf->getDaysWorkedByUserIDAndStartDateAndEndDate($user_id, $this->getDateStamp() - $this->getHolidayPolicyObject()->getAverageTimeDays() * 86400, $this->getDateStamp() - 86400);
} else {
Debug::text('NOT Using worked days!', __FILE__, __LINE__, __METHOD__, 10);
$last_days_worked_count = $this->getHolidayPolicyObject()->getAverageTimeDays();
}
Debug::text('Last Days Worked:' . $last_days_worked_count, __FILE__, __LINE__, __METHOD__, 10);
if ($this->getHolidayPolicyObject()->getIncludeOverTime() == TRUE) {
Debug::text('Including OverTime!', __FILE__, __LINE__, __METHOD__, 10);
$total_seconds_worked = $udtlf->getWorkedTimeSumByUserIDAndStartDateAndEndDate($user_id, $this->getDateStamp() - $this->getHolidayPolicyObject()->getAverageTimeDays() * 86400, $this->getDateStamp() - 86400);
} else {
Debug::text('NOT Including OverTime!', __FILE__, __LINE__, __METHOD__, 10);
$total_seconds_worked = $udtlf->getRegularTimeSumByUserIDAndStartDateAndEndDate($user_id, $this->getDateStamp() - $this->getHolidayPolicyObject()->getAverageTimeDays() * 86400, $this->getDateStamp() - 86400);
}
if ($this->getHolidayPolicyObject()->getIncludePaidAbsenceTime() == TRUE) {
Debug::text('Including Paid Absence Time!', __FILE__, __LINE__, __METHOD__, 10);
$total_seconds_worked += $udtlf->getPaidAbsenceTimeSumByUserIDAndStartDateAndEndDate($user_id, $this->getDateStamp() - $this->getHolidayPolicyObject()->getAverageTimeDays() * 86400, $this->getDateStamp() - 86400);
} else {
Debug::text('NOT Including Paid Absence Time!', __FILE__, __LINE__, __METHOD__, 10);
}
if ($last_days_worked_count > 0) {
$avg_seconds_worked_per_day = bcdiv($total_seconds_worked, $last_days_worked_count);
Debug::text('AVG hours worked per day:' . TTDate::getHours($avg_seconds_worked_per_day), __FILE__, __LINE__, __METHOD__, 10);
} else {
$avg_seconds_worked_per_day = 0;
}
if ($this->getHolidayPolicyObject()->getMaximumTime() > 0 and $avg_seconds_worked_per_day > $this->getHolidayPolicyObject()->getMaximumTime()) {
$avg_seconds_worked_per_day = $this->getHolidayPolicyObject()->getMaximumTime();
Debug::text('AVG hours worked per day exceeds maximum regulars hours per day, setting to:' . $avg_seconds_worked_per_day / 60 / 60, __FILE__, __LINE__, __METHOD__, 10);
}
if ($avg_seconds_worked_per_day < $this->getHolidayPolicyObject()->getMinimumTime()) {
$avg_seconds_worked_per_day = $this->getHolidayPolicyObject()->getMinimumTime();
Debug::text('AVG hours worked per day is less then minimum regulars hours per day, setting to:' . $avg_seconds_worked_per_day / 60 / 60, __FILE__, __LINE__, __METHOD__, 10);
}
//Round to nearest 15mins.
if ((int) $this->getHolidayPolicyObject()->getRoundIntervalPolicyID() != 0 and is_object($this->getHolidayPolicyObject()->getRoundIntervalPolicyObject())) {
$avg_seconds_worked_per_day = TTDate::roundTime($avg_seconds_worked_per_day, $this->getHolidayPolicyObject()->getRoundIntervalPolicyObject()->getInterval(), $this->getHolidayPolicyObject()->getRoundIntervalPolicyObject()->getRoundType());
Debug::text('Rounding Stat Time To: ' . $avg_seconds_worked_per_day, __FILE__, __LINE__, __METHOD__, 10);
} else {
Debug::text('NOT Rounding Stat Time!', __FILE__, __LINE__, __METHOD__, 10);
}
return $avg_seconds_worked_per_day;
}
示例7: getAccrualRatePerTimeFrequency
function getAccrualRatePerTimeFrequency($accrual_rate, $annual_pay_periods = NULL)
{
$retval = FALSE;
switch ($this->getApplyFrequency()) {
case 10:
//Pay Period
if ($annual_pay_periods == '') {
return FALSE;
}
$retval = bcdiv($accrual_rate, $annual_pay_periods, 0);
break;
case 20:
//Year
$retval = $accrual_rate;
break;
case 30:
//Month
$retval = bcdiv($accrual_rate, 12, 0);
break;
case 40:
//Week
$retval = bcdiv($accrual_rate, 52, 0);
break;
}
//Round to nearest minute, or 15mins?
$retval = TTDate::roundTime($retval, 60, 20);
Debug::Text('Accrual Rate Per Frequency: ' . $retval . ' Accrual Rate: ' . $accrual_rate . ' Pay Periods: ' . $annual_pay_periods, __FILE__, __LINE__, __METHOD__, 10);
return $retval;
}
示例8: setTimeStamp
function setTimeStamp($epoch, $enable_rounding = TRUE)
{
$epoch = $original_epoch = trim($epoch);
//We can't disable rounding if its the first IN punch and no transfer actually needs to occur.
//Have setTransfer check to see if there is a previous punch and if not, don't allow it to be set.
if ($enable_rounding == TRUE and ($this->getTransfer() == FALSE or $this->getEnableAutoTransfer() == FALSE)) {
$epoch = $this->roundTimeStamp($epoch);
} else {
Debug::text(' Rounding Disabled... ', __FILE__, __LINE__, __METHOD__, 10);
}
//Always round to one min, no matter what. Even on a transfer.
$epoch = TTDate::roundTime($epoch, 60);
if ($this->Validator->isDate('time_stamp', $epoch, TTi18n::gettext('Incorrect time stamp'))) {
Debug::text(' Set: ' . $epoch, __FILE__, __LINE__, __METHOD__, 10);
$this->data['time_stamp'] = $epoch;
return TRUE;
}
return FALSE;
}