本文整理汇总了PHP中CDate::copy方法的典型用法代码示例。如果您正苦于以下问题:PHP CDate::copy方法的具体用法?PHP CDate::copy怎么用?PHP CDate::copy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CDate
的用法示例。
在下文中一共展示了CDate::copy方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: CDate
if (isset($_GET['user_id'])) {
$AppUI->setState('TimecardMonthlyUserId', $_GET['user_id']);
} else {
$AppUI->setState('TimecardMonthlyUserId', $AppUI->user_id);
}
$user_id = $AppUI->getState('TimecardMonthlyUserId') ? $AppUI->getState('TimecardMonthlyUserId') : 0;
} else {
$user_id = $AppUI->user_id;
}
$start_report = new CDate();
$start_report->setMonth($month);
$start_report->setYear($year);
$start_report->setDay(1);
$start_report->setTime(0, 0, 0);
$end_report = new CDate();
$end_report->copy($start_report);
$end_report->addMonths(1);
$end_report->addDays(-1);
$end_report->setTime(23, 59, 59);
//Get hash of users
$sql = "SELECT user_id, contact_email, concat(contact_last_name,' ',contact_first_name) as name FROM users LEFT JOIN contacts AS c ON users.user_contact = contact_id ORDER BY contact_last_name, contact_first_name;";
$result = db_loadList($sql);
$people = array();
// users list
foreach ($result as $row) {
$people[$row['user_id']] = $row;
$users[$row['user_id']] = $row['name'];
}
unset($result);
$sql = "\r\n select distinct(project_id), project_name from task_log\r\n left join tasks on tasks.task_id = task_log.task_log_task\r\n left join projects on projects.project_id = tasks.task_project\r\n where\r\n task_log_date >= '" . $start_report->format(FMT_DATETIME_MYSQL) . "'\r\n and task_log_date <= '" . $end_report->format(FMT_DATETIME_MYSQL) . "'\r\n and task_log_task != 0\r\n and task_log_creator = " . $user_id . "\r\n order by project_name\r\n\t\t";
# echo $sql;
示例2: DBQuery
function update_dep_dates($task_id)
{
global $tracking_dynamics;
$q = new DBQuery();
$newTask = new CTask();
$newTask->load($task_id);
// Do not update tasks that are not tracking dependencies
if (!in_array($newTask->task_dynamic, $tracking_dynamics)) {
return;
}
// load original task dates and calculate task time span
$tsd = new CDate($newTask->task_start_date);
$ted = new CDate($newTask->task_end_date);
$duration = $tsd->calcDuration($ted);
// reset start date
$nsd = new CDate($newTask->get_deps_max_end_date($newTask));
// prefer Wed 8:00 over Tue 16:00 as start date
$nsd = $nsd->next_working_day();
$new_start_date = $nsd->format(FMT_DATETIME_MYSQL);
// Add task time span to End Date again
$ned = new CDate();
$ned->copy($nsd);
$ned->addDuration($duration, '1');
// make sure one didn't land on a non-working day
$ned = $ned->next_working_day(true);
// prefer tue 16:00 over wed 8:00 as an end date
$ned = $ned->prev_working_day();
$new_end_date = $ned->format(FMT_DATETIME_MYSQL);
// update the db
$q->addTable('tasks');
$q->addUpdate('task_start_date', $new_start_date);
$q->addUpdate('task_end_date', $new_end_date);
$q->addWhere('task_dynamic <> 1 AND task_id = ' . $task_id);
$q->exec();
$q->clear();
if ($newTask->task_parent != $newTask->task_id) {
$newTask->updateDynamics();
}
return;
}
示例3: arraySelect
$sql = "\n\t\t\tSELECT\n\t\t\t\ttask_log_creator,\n\t\t\t\tsum(task_log_hours) as hours\n\t\t\tFROM\n\t\t\t\ttask_log\n\t\t\tWHERE\n\t\t\t\ttask_log_date >= '" . $start_day->format(FMT_DATETIME_MYSQL) . "' \n\t\t\t\tAND task_log_date <= '" . $end_day->format(FMT_DATETIME_MYSQL) . "'\n\t\t\t\tAND task_log_creator in (" . implode(", ", $ids) . ")\n\t\t\tGROUP BY\n\t\t\t\ttask_log_creator\n\t\t\t";
//print "<pre>$sql</pre>";
$result = db_loadList($sql);
foreach ($result as $row) {
$people[$row['task_log_creator']][$i] = $row['hours'];
}
$date = $start_day->format("%Y-%m-%d") . " 12:00:00";
$start_day->setDate($date, DATE_FORMAT_ISO);
$start_day->addDays(-7);
}
}
$sql = "SELECT company_id, company_name FROM companies WHERE " . getPermsWhereClause("companies", "company_id") . " ORDER BY company_name";
//print "<pre>$sql</pre>";
$companies = arrayMerge(array(0 => $AppUI->_('All Entities')), db_loadHashList($sql));
$next_day = new CDate();
$next_day->copy($start_day);
$next_day->addDays($week_count * 7 * 2);
?>
<form name="frmCompanySelect" action="" method="get">
<input type="hidden" name="m" value="timecard">
<input type="hidden" name="report_type" value="weekly_by_user">
<input type="hidden" name="tab" value="<?php
echo $tab;
?>
">
<table cellspacing="1" cellpadding="2" border="0" width="100%">
<tr>
<td width="95%"><?php
echo arraySelect($companies, 'company_id', 'size="1" class="text" id="medium" onchange="document.frmCompanySelect.submit()"', $company_id);
?>
</td>
示例4: calcDuration
function calcDuration($e)
{
// since one will alter the date ($this) one better copies it to a new instance
$s = new CDate();
$s->copy($this);
// get dP time constants
$cal_day_start = intval(dPgetConfig('cal_day_start'));
$cal_day_end = intval(dPgetConfig('cal_day_end'));
$dwh = intval(dPgetConfig('daily_working_hours'));
// assume start is before end and set a default signum for the duration
$sgn = 1;
// check whether start before end, interchange otherwise
if ($e->before($s)) {
// calculated duration must be negative, set signum appropriately
$sgn = -1;
$dummy = $s;
$s->copy($e);
$e = $dummy;
}
// determine the (working + non-working) day difference between the two dates
$days = $e->dateDiff($s);
// if it is an intraday difference one is finished very easily
if ($days == 0) {
return min($dwh, abs($e->hour - $s->hour)) * $sgn;
}
// initialize the duration var
$duration = 0;
// process the first day
// take into account the first day if it is a working day!
$duration += $s->isWorkingDay() ? min($dwh, abs($cal_day_end - $s->hour)) : 0;
$s->addDays(1);
// end of processing the first day
// calc workingdays between start and end
for ($i = 1; $i < $days; $i++) {
$duration += $s->isWorkingDay() ? $dwh : 0;
$s->addDays(1);
}
// take into account the last day in span only if it is a working day!
$duration += $s->isWorkingDay() ? min($dwh, abs($e->hour - $cal_day_start)) : 0;
return $duration * $sgn;
}
示例5: CDate
$today_weekday = $start_day->getDayOfWeek();
//roll back to the first day of that week, regardless of what day was specified
$rollover_day = '0';
$new_start_offset = $rollover_day - $today_weekday;
$start_day->addDays($new_start_offset);
//last day of that week, add 6 days
$end_day = new CDate();
$end_day->copy($start_day);
$end_day->addDays(6);
//date of the first day of the previous week.
$prev_date = new CDate();
$prev_date->copy($start_day);
$prev_date->addDays(-7);
//date of the first day of the next week.
$next_date = new CDate();
$next_date->copy($start_day);
$next_date->addDays(7);
//***MOD 20050525 pedroa $is_my_timesheet = $user_id == $AppUI->user_id;
$is_my_timesheet = $user_id == $AppUI->user_id || $can_edit_other_timesheets;
?>
<script>
function viewLog(id) {
go('index.php?m=tasks&a=view&task_id='+id);
}
function editLog(id) {
go('index.php?m=timecard&tab=1&tid='+id);
}
function deleteLog(id, name, day) {
if (confirm('Are you sure you want to delete task log\n[ '+name+' ]\ncreated on '+day+'?')) {
示例6: CTask
// updating the table recording the
// dependency relations with this task
$obj->updateDependencies($hdependencies);
// we will reset the task's start date based upon dependencies
// and shift the end date appropriately
if ($adjustStartDate && !is_null($hdependencies)) {
// load already stored task data for this task
$tempTask = new CTask();
$tempTask->load($obj->task_id);
// shift new start date to the last dependency end date
$nsd = new CDate($tempTask->get_deps_max_end_date($tempTask));
// prefer Wed 8:00 over Tue 16:00 as start date
$nsd = $nsd->next_working_day();
// prepare the creation of the end date
$ned = new CDate();
$ned->copy($nsd);
if (empty($obj->task_start_date)) {
// appropriately calculated end date via start+duration
$ned->addDuration($obj->task_duration, $obj->task_duration_type);
} else {
// calc task time span start - end
$d = $tsd->calcDuration($ted);
// Re-add (keep) task time span for end date.
// This is independent from $obj->task_duration.
// The value returned by Date::Duration() is always in hours ('1')
$ned->addDuration($d, '1');
}
// prefer tue 16:00 over wed 8:00 as an end date
$ned = $ned->prev_working_day();
$obj->task_start_date = $nsd->format(FMT_DATETIME_MYSQL);
$obj->task_end_date = $ned->format(FMT_DATETIME_MYSQL);
示例7: calcFinish
public function calcFinish($durn, $durnType)
{
// since one will alter the date ($this) one better copies it to a new instance
$f = new CDate();
$f->copy($this);
// get w2P time constants
$cal_day_start = intval(w2PgetConfig('cal_day_start'));
$cal_day_end = intval(w2PgetConfig('cal_day_end'));
$workHours = intval(w2PgetConfig('daily_working_hours'));
$workingDays = w2PgetConfig('cal_working_days');
$working_days = explode(',', $workingDays);
//temporary variables
$inc = floor($durn);
$hoursToAddToLastDay = 0;
$hoursToAddToFirstDay = $durn;
$fullWorkingDays = 0;
$int_st_hour = $f->getHour();
//catch the gap between the working hours and the open hours (like lunch periods)
$workGap = $cal_day_end - $cal_day_start - $workHours;
// calculate the number of non-working days
$k = 7 - count($working_days);
$durnMins = ($durn - $inc) * 60;
if ($f->getMinute() + $durnMins >= 60) {
$inc++;
}
$mins = ($f->getMinute() + $durnMins) % 60;
if ($mins > 38) {
$f->setMinute(45);
} elseif ($mins > 23) {
$f->setMinute(30);
} elseif ($mins > 8) {
$f->setMinute(15);
} else {
$f->setMinute(0);
}
// jump over to the first working day
for ($i = 0; $i < $k; $i++) {
if (array_search($f->getDayOfWeek(), $working_days) === false) {
$f->addDays(1);
}
}
if ($durnType == 24) {
if ($f->getHour() == $cal_day_start && $f->getMinute() == 0) {
$fullWorkingDays = ceil($inc);
$f->setMinute(0);
} else {
$fullWorkingDays = ceil($inc) + 1;
}
// Include start day as a working day (if it is one)
if (!(array_search($f->getDayOfWeek(), $working_days) === false)) {
$fullWorkingDays--;
}
for ($i = 0; $i < $fullWorkingDays; $i++) {
$f->addDays(1);
if (array_search($f->getDayOfWeek(), $working_days) === false) {
$i--;
}
}
if ($f->getHour() == $cal_day_start && $f->getMinute() == 0) {
$f->setHour($cal_day_end);
$f->setMinute(0);
}
} else {
$hoursToAddToFirstDay = $inc;
if ($f->getHour() + $inc > $cal_day_end - $workGap) {
$hoursToAddToFirstDay = $cal_day_end - $workGap - $f->getHour();
}
if ($hoursToAddToFirstDay > $workHours) {
$hoursToAddToFirstDay = $workHours;
}
$inc -= $hoursToAddToFirstDay;
$hoursToAddToLastDay = $inc % $workHours;
$fullWorkingDays = floor(($inc - $hoursToAddToLastDay) / $workHours);
if ($hoursToAddToLastDay <= 0 && !($hoursToAddToFirstDay == $workHours)) {
$f->setHour($f->getHour() + $hoursToAddToFirstDay);
} elseif ($hoursToAddToLastDay == 0) {
$f->setHour($f->getHour() + $hoursToAddToFirstDay + $workGap);
} else {
$f->setHour($cal_day_start + $hoursToAddToLastDay);
$f->addDays(1);
}
if (($f->getHour() == $cal_day_end || $f->getHour() - $int_st_hour == $workHours + $workGap) && $mins > 0) {
$f->addDays(1);
$f->setHour($cal_day_start);
}
// boolean for setting later if we just found a non-working day
// and therefore do not have to add a day in the next loop
// (which would have caused to not respecting multiple non-working days after each other)
$g = false;
for ($i = 0, $i_cmp = ceil($fullWorkingDays); $i < $i_cmp; $i++) {
if (!$g) {
$f->addHours(1);
}
$g = false;
// calculate overriden non-working days
if (array_search($f->getDayOfWeek(), $working_days) === false) {
$f->addDays(1);
$i--;
$g = true;
}
//.........这里部分代码省略.........