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


PHP Tinebase_DateTime::addDay方法代码示例

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


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

示例1: skipWday

 /**
  * skips date to (n'th next/previous) occurance of $_wday
  *
  * @param Tinebase_DateTime  $_date
  * @param int|string $_wday
  * @param int        $_n
  * @param bool       $_considerDateItself
  */
 public static function skipWday($_date, $_wday, $_n = +1, $_considerDateItself = FALSE)
 {
     $wdayDigit = is_int($_wday) ? $_wday : self::$WEEKDAY_DIGIT_MAP[$_wday];
     $wdayOffset = $_date->get('w') - $wdayDigit;
     if ($_n == 0) {
         throw new Exception('$_n must not be 0');
     }
     $direction = $_n > 0 ? 'forward' : 'backward';
     $weeks = abs($_n);
     if ($_considerDateItself && $wdayOffset == 0) {
         $weeks--;
     }
     switch ($direction) {
         case 'forward':
             if ($wdayOffset >= 0) {
                 $_date->addDay($weeks * 7 - $wdayOffset);
             } else {
                 $_date->addDay(abs($wdayOffset) + ($weeks - 1) * 7);
             }
             break;
         case 'backward':
             if ($wdayOffset > 0) {
                 $_date->subDay(abs($wdayOffset) + ($weeks - 1) * 7);
             } else {
                 $_date->subDay($weeks * 7 + $wdayOffset);
             }
             break;
     }
     return $_date;
 }
开发者ID:ingoratsdorf,项目名称:Tine-2.0-Open-Source-Groupware-and-CRM,代码行数:38,代码来源:Rrule.php

示例2: _createAutoInvoicesForContract

 /**
  * create auto invoices for one contract
  * 
  * @param Sales_Model_Contract $contract
  * @param Tinebase_DateTime $currentDate
  * @param boolean $merge
  */
 protected function _createAutoInvoicesForContract(Sales_Model_Contract $contract, Tinebase_DateTime $currentDate, $merge = false)
 {
     // set this current billing date (user timezone)
     $this->_currentBillingDate = clone $currentDate;
     $this->_currentBillingDate->setDate($this->_currentBillingDate->format('Y'), $this->_currentBillingDate->format('m'), 1);
     $this->_currentBillingDate->setTime(0, 0, 0);
     // check all prerequisites needed for billing of the contract
     if (!$this->_validateContract($contract)) {
         return false;
     }
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Processing contract "' . $this->_currentBillingContract->number . '"');
     }
     // fire event to allow other applications do some work before billing
     $this->_firePrebillEvent();
     // find product aggregates of the current contract
     $productAggregates = $this->_findProductAggregates();
     // find month that needs to be billed next (note: _currentMonthToBill is the 01-01 00:00:00 of the next month, its the border, like last_autobill)
     $this->_currentMonthToBill = null;
     foreach ($productAggregates as $productAggregate) {
         if (null != $productAggregate->last_autobill) {
             $tmp = clone $productAggregate->last_autobill;
             $tmp->setDate($tmp->format('Y'), $tmp->format('m'), 1);
             $tmp->setTime(0, 0, 0);
             if (null == $this->_currentMonthToBill || $tmp->isLater($this->_currentMonthToBill)) {
                 $this->_currentMonthToBill = $tmp;
             }
         }
     }
     // this contract has no productAggregates, maybe just time accounts? use last invoice to find already billed month
     if (null == $this->_currentMonthToBill) {
         // find newest invoice of contract (probably can be done more efficient!)
         $invoiceRelations = Tinebase_Relations::getInstance()->getRelations('Sales_Model_Contract', 'Sql', $contract->getId(), NULL, array(), TRUE, array('Sales_Model_Invoice'));
         // do not modify $newestInvoiceTime!!!! it does NOT get cloned!
         $newestInvoiceTime = null;
         $newestInvoice = null;
         foreach ($invoiceRelations as $invoiceRelation) {
             $invoiceRelation->related_record->setTimezone(Tinebase_Core::getUserTimezone());
             if (null == $newestInvoiceTime || $invoiceRelation->related_record->creation_time->isLater($newestInvoiceTime)) {
                 $newestInvoiceTime = $invoiceRelation->related_record->creation_time;
                 $newestInvoice = $invoiceRelation->related_record;
             }
         }
         if (null != $newestInvoice) {
             // we can only take the end_date because there are no product aggregates (that have a last_autobill set) in this contract, otherwise it might be one interval ahead!
             $this->_currentMonthToBill = clone $newestInvoice->end_date;
             $this->_currentMonthToBill->addDay(4);
             $this->_currentMonthToBill->subMonth(1);
             //$this->_currentMonthToBill->setTimezone(Tinebase_Core::getUserTimezone());
         }
     }
     $_addMonth = true;
     if (null == $this->_currentMonthToBill) {
         $this->_currentMonthToBill = clone $contract->start_date;
         $_addMonth = false;
     }
     $this->_currentMonthToBill->setTimezone(Tinebase_Core::getUserTimezone());
     $this->_currentMonthToBill->setDate($this->_currentMonthToBill->format('Y'), $this->_currentMonthToBill->format('m'), 1);
     $this->_currentMonthToBill->setTime(0, 0, 0);
     if ($_addMonth) {
         $this->_currentMonthToBill->addMonth(1);
     }
     $doSleep = false;
     if (($merge || $contract->merge_invoices) && $this->_currentMonthToBill->isEarlier($this->_currentBillingDate)) {
         $this->_currentMonthToBill = clone $this->_currentBillingDate;
     }
     while ($this->_currentMonthToBill->isEarlierOrEquals($this->_currentBillingDate)) {
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' $this->_currentMonthToBill: ' . $this->_currentMonthToBill . ' $this->_currentBillingDate ' . $this->_currentBillingDate);
             foreach ($productAggregates as $productAggregate) {
                 Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . $productAggregate->id . ' ' . $productAggregate->last_autobill . ' ' . $productAggregate->interval);
             }
         }
         //required to have one sec difference in the invoice creation_time, can be optimized to look for milliseconds
         if ($doSleep) {
             sleep(1);
             $doSleep = false;
         }
         // prepare relations and find all billable accountables of the current contract
         list($relations, $billableAccountables) = $this->_prepareInvoiceRelationsAndFindBillableAccountables($productAggregates);
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' count $billableAccountables: ' . count($billableAccountables));
             foreach ($billableAccountables as $ba) {
                 Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' accountable: ' . get_class($ba['ac']) . ' id: ' . $ba['ac']->getId());
             }
         }
         // find invoice positions and the first start date and last end date of all billables
         list($invoicePositions, $earliestStartDate, $latestEndDate) = $this->_findInvoicePositionsAndInvoiceInterval($billableAccountables);
         /**** TODO ****/
         // if there are no positions, no more bills need to be created,
         // but the last_autobill info is set, if the current date is later
         if ($invoicePositions->count() > 0) {
             // prepare invoice
//.........这里部分代码省略.........
开发者ID:ingoratsdorf,项目名称:Tine-2.0-Open-Source-Groupware-and-CRM,代码行数:101,代码来源:Invoice.php

示例3: testCalculation

 /**
  * tests account summary and getFeastAndFreeDays method calculation
  */
 public function testCalculation()
 {
     $employmentBegin = new Tinebase_DateTime('2012-12-15');
     $employmentChange = new Tinebase_DateTime('2014-01-01');
     $employmentEnd = new Tinebase_DateTime('2014-06-30');
     $referenceDate = new Tinebase_DateTime('2013-10-10');
     $contractController = HumanResources_Controller_Contract::getInstance();
     $employeeController = HumanResources_Controller_Employee::getInstance();
     $contractBackend = new HumanResources_Backend_Contract();
     $employee = $this->_getEmployee('unittest');
     $employee->employment_begin = $employmentBegin;
     $employee->employment_end = $employmentEnd;
     $contract1 = $this->_getContract();
     $contract1->start_date = $employmentBegin;
     $contract1->workingtime_json = '{"days": [8,8,8,8,8,0,0]}';
     $contract1->vacation_days = 25;
     $contract2 = $this->_getContract();
     $contract2->start_date = $employmentChange;
     $contract2->end_date = $employmentEnd;
     $contract2->workingtime_json = '{"days": [4,4,4,4,4,4,4]}';
     $rs = new Tinebase_Record_RecordSet('HumanResources_Model_Contract');
     $rs->addRecord($contract1);
     $rs->addRecord($contract2);
     $employee->contracts = $rs;
     $employee = $employeeController->create($employee);
     $json = new HumanResources_Frontend_Json();
     $accountController = HumanResources_Controller_Account::getInstance();
     $accountsFilter = array(array('field' => "employee_id", 'operator' => "AND", 'value' => array(array('field' => ':id', 'operator' => 'equals', 'value' => $employee->getId()))));
     // should not be created, exist already
     $accountController->createMissingAccounts(2013, $employee);
     $accountController->createMissingAccounts(2014, $employee);
     // create feast days
     $feastDays = array('01-01', '03-29', '04-01', '05-01', '05-09', '05-20', '10-03', '12-25', '12-26', '12-31');
     foreach ($feastDays as $day) {
         $date = new Tinebase_DateTime('2013-' . $day . ' 12:00:00');
         $this->_createFeastDay($date);
         $date = new Tinebase_DateTime('2014-' . $day . ' 12:00:00');
         $this->_createFeastDay($date);
     }
     // what about the holy evening? it's recurring
     // @see 0009114: Freetime edit dialog doesn't calculate recurring feast days
     //      https://forge.tine20.org/mantisbt/view.php?id=9114
     $this->_createRecurringFeastDay(new Tinebase_DateTime('2011-12-24'));
     $result = $json->searchAccounts($accountsFilter, array('sort' => 'year', 'dir' => 'DESC'));
     $this->assertEquals('3', $result['totalcount'], 'Three accounts should have been found!');
     $accountId2013 = $result['results'][1]['id'];
     $account2013 = $json->getAccount($accountId2013);
     $accountId2014 = $result['results'][0]['id'];
     $account2014 = $json->getAccount($accountId2014);
     $this->assertEquals(25, $account2013['possible_vacation_days']);
     $this->assertEquals(250, $account2013['working_days']);
     $this->assertEquals(15, $account2014['possible_vacation_days']);
     $this->assertEquals(175, $account2014['working_days']);
     // add 5 extra free days to the account with different expiration dates, 2 days aren't expired already
     $tomorrow = Tinebase_DateTime::now();
     $tomorrow->addDay(1);
     $yesterday = Tinebase_DateTime::now();
     $yesterday->subDay(1);
     $eft1 = new HumanResources_Model_ExtraFreeTime(array('days' => 2, 'account_id' => $accountId2013, 'expires' => $tomorrow));
     $eft2 = new HumanResources_Model_ExtraFreeTime(array('days' => 3, 'account_id' => $accountId2013, 'expires' => $yesterday));
     $eftController = HumanResources_Controller_ExtraFreeTime::getInstance();
     $eftController->create($eft1);
     $eftController->create($eft2);
     $account2013 = $json->getAccount($accountId2013);
     $this->assertEquals(27, $account2013['possible_vacation_days']);
     $this->assertEquals(27, $account2013['remaining_vacation_days']);
     $this->assertEquals(250, $account2013['working_days']);
     $this->assertEquals(3, $account2013['expired_vacation_days'], 'There should be 3 expired vacation days at first!');
     // the extra freetimes added to the account2013 should not affect account 2014
     $account2014 = $json->getAccount($accountId2014);
     $this->assertEquals(15, $account2014['possible_vacation_days']);
     $this->assertEquals(175, $account2014['working_days']);
     // now add 3 vacation days before the expiration day of the second extra free time
     // #8202: Allow to book remaining free days from last years' account, respect expiration
     $freetime = array('account_id' => $accountId2013, 'employee_id' => $employee->getId(), 'type' => 'vacation', 'status' => 'ACCEPTED', 'firstday_date' => $yesterday->subWeek(1)->toString());
     $nd = $referenceDate->subMonth(2);
     $freetime['freedays'] = array(array('duration' => '1', 'date' => $nd->toString()), array('duration' => '1', 'date' => $nd->addDay(1)->toString()), array('duration' => '1', 'date' => $nd->addDay(1)->toString()));
     $freetime = $this->_json->saveFreeTime($freetime);
     // so the 3 days haven't been expired, because 3 vacation days have been booked before
     $account2013 = $json->getAccount($accountId2013);
     $this->assertEquals(30, $account2013['possible_vacation_days'], 'There should be 30 possible vacation days after all!');
     $this->assertEquals(27, $account2013['remaining_vacation_days'], 'There should be 27 remaining vacation days after all!');
     $this->assertEquals(0, $account2013['expired_vacation_days'], 'There should be no expired vacation days after all!');
     $this->assertEquals(3, $account2013['taken_vacation_days'], 'He took 3 vacation days');
     // test account filter for: employee_id and year
     $accountsFilter = array(array('field' => "employee_id", 'operator' => "AND", 'value' => array(array('field' => ':id', 'operator' => 'equals', 'value' => $employee->getId()))), array('field' => 'year', 'operator' => 'equals', 'value' => $account2013['year']));
     $result = $json->searchAccounts($accountsFilter, array());
     $this->assertEquals(1, $result['totalcount']);
     // test account quicksearch filter
     $qsFilter = array(array('field' => "query", 'operator' => "contains", 'value' => Tinebase_Core::getUser()->accountFirstName));
     $result = $json->searchAccounts($qsFilter, array());
     $this->assertEquals(3, $result['totalcount'], 'should find exactly 3 accounts');
     $qsFilter = array(array('field' => "query", 'operator' => "contains", 'value' => 'Adsmin'));
     $result = $json->searchAccounts($qsFilter, array());
     $this->assertEquals(0, $result['totalcount']);
     $refdate = clone $referenceDate;
     // now we test if adding a vacation with dates of 2013 but the account of 2014 works as expected
//.........这里部分代码省略.........
开发者ID:bitExpert,项目名称:Tine-2.0-Open-Source-Groupware-and-CRM,代码行数:101,代码来源:JsonTests.php

示例4: testModifyReturnValue

 public function testModifyReturnValue()
 {
     $dt = new Tinebase_DateTime('2010-11-25 12:11:00');
     $instance = $dt->addDay(-1);
     $this->assertEquals('Tinebase_DateTime', get_class($instance), 'wrong type');
 }
开发者ID:rodrigofns,项目名称:ExpressoLivre3,代码行数:6,代码来源:DateTimeTest.php


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