本文整理汇总了PHP中Tinebase_DateTime::setTimezone方法的典型用法代码示例。如果您正苦于以下问题:PHP Tinebase_DateTime::setTimezone方法的具体用法?PHP Tinebase_DateTime::setTimezone怎么用?PHP Tinebase_DateTime::setTimezone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tinebase_DateTime
的用法示例。
在下文中一共展示了Tinebase_DateTime::setTimezone方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getFilterImap
/**
*
* @return type
*/
public function getFilterImap()
{
$format = "d-M-Y";
// prepare value
$value = (array) $this->_getDateValues($this->_operator, $this->_value);
$timezone = Tinebase_Helper::array_value('timezone', $this->_options);
$timezone = $timezone ? $timezone : Tinebase_Core::getUserTimezone();
foreach ($value as &$date) {
$date = new Tinebase_DateTime($date);
// should be in user timezone
$date->setTimezone(new DateTimeZone($timezone));
}
switch ($this->_operator) {
case 'within':
case 'inweek':
$value[1]->add(new DateInterval('P1D'));
// before is not inclusive, so we have to add a day
$return = "SINCE {$value[0]->format($format)} BEFORE {$value[1]->format($format)}";
break;
case 'before':
$return = "BEFORE {$value[0]->format($format)}";
break;
case 'after':
$return = "SINCE {$value[0]->format($format)}";
break;
case 'equals':
$return = "ON {$value[0]->format($format)}";
}
return $return;
}
示例2: getFilterImap
/**
*
* @return type
* @todo fix method setFromArray()
*/
public function getFilterImap()
{
$format = "d-M-Y";
// prepare value
$value = (array) $this->_getDateValues($this->_operator, $this->_value);
$timezone = array_value('timezone', $this->_options);
foreach ($value as &$date) {
$date = new Tinebase_DateTime($date);
// should be in user timezone
$date->setTimezone(new DateTimeZone($timezone));
}
switch ($this->_operator) {
case 'within':
case 'inweek':
$return = "SINCE {$value[0]->format($format)} BEFORE {$value[1]->format($format)}";
break;
case 'before':
$return = "BEFORE {$value[0]->format($format)}";
break;
case 'after':
$return = "SINCE {$value[0]->format($format)}";
break;
case 'equals':
// errado
$return = "ON {$value[0]->format($format)}";
}
return $return;
}
示例3: toArray
/**
* returns array with the filter settings of this filter
* - convert value to user timezone
*
* @param bool $_valueToJson resolve value for json api?
* @return array
*/
public function toArray($_valueToJson = false)
{
$result = parent::toArray($_valueToJson);
if ($this->_operator != 'within' && $this->_operator != 'inweek' && $_valueToJson == true) {
$date = new Tinebase_DateTime($result['value']);
$date->setTimezone(Tinebase_Core::get(Tinebase_Core::USERTIMEZONE));
$result['value'] = $date->toString(Tinebase_Record_Abstract::ISO8601LONG);
}
return $result;
}
示例4: testHasTime
public function testHasTime()
{
$date = new Tinebase_DateTime('2011-11-11 11:11:11', 'Europe/Berlin');
$this->assertTrue($date->hasTime(), 'date must have the hasTime flag');
$date->hasTime(FALSE);
$this->assertFalse($date->hasTime(), 'date must not have the hasTime flag');
$this->assertEquals('00:00:00', $date->format('H:i:s'), 'time info has not been reset');
$date->setTimezone('Asia/Tehran');
$this->assertEquals('2011-11-11', $date->format('Y-m-d'), 'date must not chage');
$this->assertEquals('00:00:00', $date->format('H:i:s'), 'time must not chage');
}
示例5: _setReferenceDate
protected function _setReferenceDate()
{
// set reference date to the 1st january of last year
$this->_referenceDate = Tinebase_DateTime::now();
$this->_referenceDate->setTimezone(Tinebase_Core::getUserTimezone());
$this->_referenceDate->subYear(1);
$this->_referenceDate->setDate($this->_referenceDate->format('Y'), 1, 1);
$this->_referenceDate->setTime(0, 0, 0);
$this->_referenceYear = $this->_referenceDate->format('Y');
$this->_lastMonthDays = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
// find out if year is a leap year
if ((bool) $this->_referenceDate->format('L')) {
$this->_isLeapYear = TRUE;
$this->_lastMonthDays[1] = 29;
}
}
示例6: convertDate
/**
* convert date from sent/received
*
* @param string $_dateString
* @return Zend_Date
*/
public static function convertDate($_dateString)
{
try {
$date = new Tinebase_DateTime($_dateString ? $_dateString : '@0');
$date->setTimezone('UTC');
} catch (Exception $e) {
// try to fix missing timezone char
if (preg_match('/UT$/', $_dateString)) {
$_dateString .= 'C';
}
// try some explicit formats
foreach (self::$dateFormats as $format) {
$date = DateTime::createFromFormat($format, $_dateString);
if ($date) {
break;
}
}
if (!$date) {
Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . " Date {$_dateString} could not be converted to DateTime -> using 1970-01-01 00:00:00.");
$date = new Tinebase_DateTime('@0');
}
}
return $date;
}
示例7: _getDate
/**
* returns the current date if no $date string is given (needed for mocking only)
*
* @param string $date
* @param boolean $usertimezone
*/
protected function _getDate($date = NULL, $usertimezone = FALSE)
{
if (!$date) {
$date = Tinebase_DateTime::now();
} else {
$date = new Tinebase_DateTime($date);
}
if ($usertimezone) {
$date->setTimezone(Tinebase_Core::getUserTimezone());
}
return $date;
}
示例8: testImportWithResolveStrategyMergeTheirs
/**
* test import with mergeTheirs resolve strategy
*
* @see 0007226: tag handling and other import problems
*/
public function testImportWithResolveStrategyMergeTheirs()
{
$this->_testNeedsTransaction();
$result = $this->_importHelper(array('dryrun' => 0));
$this->assertEquals(2, count($result['results']), 'no import results');
$fritz = $result['results'][1];
$fritz['tags'][] = array('name' => 'new import tag');
$fritz['tel_work'] = '04040';
$clientRecords = array(array('recordData' => $fritz, 'resolveStrategy' => 'mergeTheirs', 'index' => 1));
$result = $this->_importHelper(array('dryrun' => 0), $clientRecords);
$this->assertEquals(1, $result['totalcount'], 'Should merge fritz');
$this->assertEquals(2, count($result['results'][0]['tags']), 'Should merge tags');
$this->assertEquals(0, $result['failcount'], 'no failures expected');
$this->assertEquals(1, $result['duplicatecount'], 'klaus should still be a duplicate');
$fritz = $result['results'][0];
$fritz['tel_work'] = '04040';
// need to adjust user TZ
$lastModified = new Tinebase_DateTime($fritz['last_modified_time']);
$fritz['last_modified_time'] = $lastModified->setTimezone(Tinebase_Core::getUserTimezone())->toString();
$clientRecords = array(array('recordData' => $fritz, 'resolveStrategy' => 'mergeTheirs', 'index' => 1));
$result = $this->_importHelper(array('dryrun' => 0), $clientRecords);
$this->assertEquals(1, $result['totalcount'], 'Should merge fritz: ' . print_r($result, TRUE));
}
示例9: testAddContract
/**
* test adding a contract with manually setting the end_date of the contract before
*/
public function testAddContract()
{
$sdate = new Tinebase_DateTime('2013-01-01 00:00:00');
$sdate->setTimezone(Tinebase_Core::getUserTimezone());
$employee = $this->_getEmployee('rwright');
$contractController = HumanResources_Controller_Contract::getInstance();
$employeeController = HumanResources_Controller_Employee::getInstance();
$employee = $employeeController->create($employee);
$contract = $this->_getContract($sdate);
$contract->workingtime_json = '{"days": [8,8,8,8,8,0,0]}';
$contract->employee_id = $employee->getId();
$feastCalendar = $this->_getFeastCalendar();
$contract->feast_calendar_id = $feastCalendar->getId();
$contract->start_date = $sdate;
$contractController->create($contract);
$employeeJson = $this->_json->getEmployee($employee->getId());
$accountController = HumanResources_Controller_Account::getInstance();
// should not be created, exist already
$accountController->createMissingAccounts(2013, $employee);
$account = $accountController->getAll()->getFirstRecord();
$employeeJson['vacation'] = array(array('account_id' => $account->getId(), 'type' => 'vacation', 'status' => 'ACCEPTED', 'freedays' => array(array('duration' => '1', 'date' => '2013-01-11 00:00:00'))));
$employeeJson = $this->_json->saveEmployee($employeeJson);
$this->assertEquals(1, count($employeeJson['vacation']));
// manually set the end date and add a new contract
$employeeJson['contracts'][0]['end_date'] = '2013-05-31 00:00:00';
$employeeJson['contracts'][1] = array('start_date' => '2013-06-01 00:00:00', 'workingtime_json' => '{"days": [8,8,8,8,8,0,0]}', 'vacation_days' => 27, 'feast_calendar_id' => $feastCalendar->getId());
// no exception should be thrown
$employeeJson = $this->_json->saveEmployee($employeeJson);
$this->assertEquals(2, count($employeeJson['contracts']));
// an exception should be thrown
$employeeJson['contracts'][0]['vacation_days'] = 31;
$this->setExpectedException('HumanResources_Exception_ContractNotEditable');
$employeeJson = $this->_json->saveEmployee($employeeJson);
}
示例10: testCalcYearlyByMonthDayLeapYear
public function testCalcYearlyByMonthDayLeapYear()
{
$event = new Calendar_Model_Event(array('uid' => Tinebase_Record_Abstract::generateUID(), 'summary' => 'yearly 29.feb', 'dtstart' => '2008-02-29 08:00:00', 'dtend' => '2008-02-29 10:00:00', 'rrule' => 'FREQ=YEARLY;INTERVAL=1;BYMONTH=2;BYMONTHDAY=29', 'originator_tz' => 'Europe/Berlin', Tinebase_Model_Grants::GRANT_EDIT => true));
$exceptions = new Tinebase_Record_RecordSet('Calendar_Model_Event');
// note: 2009-03-29 Europe/Berlin switched to DST
$from = new Tinebase_DateTime('2008-02-25 00:00:00');
$until = new Tinebase_DateTime('2013-03-01 23:59:59');
$until->setTimezone('Europe/Berlin');
$from->setTimezone('Europe/Berlin');
$recurSet = Calendar_Model_Rrule::computeRecurrenceSet($event, $exceptions, $from, $until);
$this->assertEquals(1, count($recurSet), 'leapyear only failed');
$this->assertEquals('2012-02-29 08:00:00', $recurSet[0]->dtstart->get(Tinebase_Record_Abstract::ISO8601LONG));
}
示例11: _createSharedInvoices
/**
* creates the invoices - no containers, just "shared"
*/
protected function _createSharedInvoices()
{
$sic = Sales_Controller_Invoice::getInstance();
$now = new Tinebase_DateTime();
$now->setTimezone(Tinebase_Core::getUserTimezone());
$now->setDate($now->format('Y'), $now->format('m'), 1);
$now->setTime(3, 0, 0);
$date = clone $this->_referenceDate;
while ($date < $now) {
$sic->createAutoInvoices($date);
$date->addMonth(1);
}
}
示例12: getEditableState
/**
* resolves virtual field "is_editable"
*
* @param array $resultSet
*/
public function getEditableState($resultSet)
{
for ($i = 0; $i < count($resultSet); $i++) {
$sDate = new Tinebase_DateTime($resultSet[$i]['start_date']);
$sDate->setTimezone(Tinebase_Core::getUserTimezone());
$eDate = NULL;
if ($resultSet[$i]['end_date']) {
$eDate = new Tinebase_DateTime($resultSet[$i]['end_date']);
$eDate->setTimezone(Tinebase_Core::getUserTimezone());
}
$freeTimeFilter = new HumanResources_Model_FreeTimeFilter(array(array('field' => 'firstday_date', 'operator' => 'after', 'value' => $sDate), array('field' => 'type', 'operator' => 'equals', 'value' => 'vacation')));
if ($eDate) {
$freeTimeFilter->addFilter(new Tinebase_Model_Filter_Date(array('field' => 'firstday_date', 'operator' => 'before', 'value' => $eDate)));
}
$freeTimeFilter->addFilter(new Tinebase_Model_Filter_Text(array('field' => 'employee_id', 'operator' => 'equals', 'value' => $resultSet[$i]['employee_id'])));
$freeTimeController = HumanResources_Controller_FreeTime::getInstance();
$resultSet[$i]['is_editable'] = $freeTimeController->search($freeTimeFilter)->count() > 0 ? FALSE : TRUE;
}
return $resultSet;
}
示例13: _parseAlarm
/**
* parse valarm properties
*
* @param Tinebase_Record_Abstract $record
* @param iteratable $valarms
* @param \Sabre\VObject\Component $vcalendar
*/
protected function _parseAlarm(Tinebase_Record_Abstract $record, $valarms, \Sabre\VObject\Component $vcomponent)
{
foreach ($valarms as $valarm) {
if ($valarm->ACTION == 'NONE') {
if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' We can\'t cope with action NONE: iCal 6.0 sends default alarms in the year 1976 with action NONE. Skipping alarm.');
}
continue;
}
if (!is_object($valarm->TRIGGER)) {
if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Alarm has no TRIGGER value. Skipping it.');
}
continue;
}
# TRIGGER:-PT15M
if (is_string($valarm->TRIGGER->getValue()) && $valarm->TRIGGER instanceof Sabre\VObject\Property\ICalendar\Duration) {
if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' Adding DURATION trigger value for ' . $valarm->TRIGGER->getValue());
}
$valarm->TRIGGER->add('VALUE', 'DURATION');
}
$trigger = is_object($valarm->TRIGGER['VALUE']) ? $valarm->TRIGGER['VALUE'] : (is_object($valarm->TRIGGER['RELATED']) ? $valarm->TRIGGER['RELATED'] : NULL);
if ($trigger === NULL) {
// added Trigger/Related for eM Client alarms
// 2014-01-03 - Bullshit, why don't we have testdata for emclient alarms?
// this alarm handling should be refactored, the logic is scrambled
// @see 0006110: handle iMIP messages from outlook
// @todo fix 0007446: handle broken alarm in outlook invitation message
if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Alarm has no TRIGGER value. Skipping it.');
}
continue;
}
switch (strtoupper($trigger->getValue())) {
# TRIGGER;VALUE=DATE-TIME:20111031T130000Z
case 'DATE-TIME':
$alarmTime = new Tinebase_DateTime($valarm->TRIGGER->getValue());
$alarmTime->setTimezone('UTC');
$alarm = new Tinebase_Model_Alarm(array('alarm_time' => $alarmTime, 'minutes_before' => 'custom', 'model' => $this->_modelName));
break;
# TRIGGER;VALUE=DURATION:-PT1H15M
# TRIGGER;VALUE=DURATION:-PT1H15M
case 'DURATION':
default:
$durationBaseTime = isset($vcomponent->DTSTART) ? $vcomponent->DTSTART : $vcomponent->DUE;
$alarmTime = $this->_convertToTinebaseDateTime($durationBaseTime);
$alarmTime->setTimezone('UTC');
preg_match('/(?P<invert>[+-]?)(?P<spec>P.*)/', $valarm->TRIGGER->getValue(), $matches);
$duration = new DateInterval($matches['spec']);
$duration->invert = !!($matches['invert'] === '-');
$alarm = new Tinebase_Model_Alarm(array('alarm_time' => $alarmTime->add($duration), 'minutes_before' => $duration->format('%d') * 60 * 24 + $duration->format('%h') * 60 + $duration->format('%i'), 'model' => $this->_modelName));
if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' Adding DURATION alarm ' . print_r($alarm->toArray(), true));
}
}
if ($valarm->ACKNOWLEDGED) {
$dtack = $valarm->ACKNOWLEDGED->getDateTime();
Calendar_Controller_Alarm::setAcknowledgeTime($alarm, $dtack);
}
$record->alarms->addRecord($alarm);
}
}
示例14: testCreateRecurEventWithRruleUntil
/**
* testCreateRecurEventWithRruleUntil
*
* @see 0008906: rrule_until is saved in usertime
*/
public function testCreateRecurEventWithRruleUntil()
{
$eventData = $this->testCreateRecurEvent();
$localMidnight = Tinebase_DateTime::now()->setTime(23, 59, 59)->toString();
$eventData['rrule']['until'] = $localMidnight;
//$eventData['rrule']['freq'] = 'WEEKLY';
$updatedEventData = $this->_uit->saveEvent($eventData);
$this->assertGreaterThanOrEqual($localMidnight, $updatedEventData['rrule']['until']);
// check db record
$calbackend = new Calendar_Backend_Sql();
$db = $calbackend->getAdapter();
$select = $db->select();
$select->from(array($calbackend->getTableName() => $calbackend->getTablePrefix() . $calbackend->getTableName()), array('rrule_until', 'rrule'))->limit(1);
$select->where($db->quoteIdentifier($calbackend->getTableName() . '.id') . ' = ?', $updatedEventData['id']);
$stmt = $db->query($select);
$queryResult = $stmt->fetch();
// echo Tinebase_Core::getUserTimezone();
// echo date_default_timezone_get();
$midnightInUTC = new Tinebase_DateTime($queryResult['rrule_until']);
$this->assertEquals(Tinebase_DateTime::now()->setTime(23, 59, 59)->toString(), $midnightInUTC->setTimezone(Tinebase_Core::getUserTimezone(), TRUE)->toString());
}
示例15: _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
//.........这里部分代码省略.........