/** * @expectedException NotSupportedException */ public function testCalculateNewNotSupportedCalculation() { DateTimeCalculatorUtil::calculateNew(1231, new DateTime()); }
/** * Given an integer representing a count of days from the present day, returns a DB formatted date stamp based * on that calculation. This is a wrapper method for @see DateTimeCalculatorUtil::calculateNewByDaysFromNow * @param integer $daysFromNow */ public static function calculateNewDateByDaysFromNow($daysFromNow) { assert('is_int($daysFromNow)'); return DateTimeCalculatorUtil::calculateNewByDaysFromNow($daysFromNow, new DateTime(null, new DateTimeZone(Yii::app()->timeZoneHelper->getForCurrentUser()))); }
public function testSearchFormDynamicAttributesTodayAndBeforeTodayDateSearch() { $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $searchAttributes = array('date__Date' => array('type' => MixedDateTypesSearchFormAttributeMappingRules::TYPE_TODAY), 'date2__Date' => array('type' => MixedDateTypesSearchFormAttributeMappingRules::TYPE_BEFORE_TODAY)); $searchForm = new MixedRelationsModelSearchFormTestModel(new MixedRelationsModel()); $metadataAdapter = new SearchDataProviderMetadataAdapter($searchForm, $super->id, $searchAttributes); $metadata = $metadataAdapter->getAdaptedMetadata(); $today = DateTimeCalculatorUtil::calculateNew(DateTimeCalculatorUtil::TODAY, new DateTime(null, new DateTimeZone(Yii::app()->timeZoneHelper->getForCurrentUser()))); $compareClauses = array(1 => array('attributeName' => 'date', 'operatorType' => 'equals', 'value' => $today), 2 => array('attributeName' => 'date2', 'operatorType' => 'lessThan', 'value' => $today)); $compareStructure = '(1) and (2)'; $this->assertEquals($compareClauses, $metadata['clauses']); $this->assertEquals($compareStructure, $metadata['structure']); }
/** * Override to calculate the */ protected function calculate() { if ($this->value != null) { return DateTimeCalculatorUtil::calculateNew((int) $this->value, new DateTime(null, new DateTimeZone(Yii::app()->timeZoneHelper->getForCurrentUser()))); } }