本文整理汇总了PHP中DatabaseCompatibilityUtil::getDateFormat方法的典型用法代码示例。如果您正苦于以下问题:PHP DatabaseCompatibilityUtil::getDateFormat方法的具体用法?PHP DatabaseCompatibilityUtil::getDateFormat怎么用?PHP DatabaseCompatibilityUtil::getDateFormat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DatabaseCompatibilityUtil
的用法示例。
在下文中一共展示了DatabaseCompatibilityUtil::getDateFormat方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testDefaultCalculatedDates
public function testDefaultCalculatedDates()
{
$now = time();
$thing = new ThingWithCalculatedDates();
$thingNowValue = $thing->now;
$this->assertEquals(DateTimeUtil::convertTimestampToDbFormatDateTime($now), $thing->now);
$this->assertTrue($thing->save());
$this->assertEquals($thingNowValue, $thing->now);
$stamp = Yii::app()->dateFormatter->format(DatabaseCompatibilityUtil::getDateFormat(), $now);
$this->assertEquals($stamp, $thing->today);
$stamp = Yii::app()->dateFormatter->format(DatabaseCompatibilityUtil::getDateFormat(), $now + 24 * 60 * 60);
$this->assertEquals($stamp, $thing->tomorrow);
$stamp = Yii::app()->dateFormatter->format(DatabaseCompatibilityUtil::getDateFormat(), $now - 24 * 60 * 60);
$this->assertEquals($stamp, $thing->yesterday);
}
示例2: populateModel
public function populateModel(&$model)
{
assert('$model instanceof Opportunity');
$opportunityRandomData = ZurmoRandomDataUtil::getRandomDataByModuleAndModelClassNames('OpportunitiesModule', 'Opportunity');
parent::populateModel($model);
$name = RandomDataUtil::getRandomValueFromArray($opportunityRandomData['names']);
$model->name = $name;
$stage = RandomDataUtil::getRandomValueFromArray(static::getCustomFieldDataByName('SalesStages'));
$source = RandomDataUtil::getRandomValueFromArray(static::getCustomFieldDataByName('LeadSources'));
$model->stage->value = $stage;
$model->source->value = $source;
$futureTimeStamp = time() + mt_rand(1, 200) * 60 * 60 * 24;
$closeDate = Yii::app()->dateFormatter->format(DatabaseCompatibilityUtil::getDateFormat(), $futureTimeStamp);
$model->closeDate = $closeDate;
$model->amount->value = mt_rand(5, 350) * 1000;
}
示例3: testValidAndInvalidDateDateTimeValidation
public function testValidAndInvalidDateDateTimeValidation()
{
$language = Yii::app()->getLanguage();
$this->assertEquals($language, 'en');
$this->assertEquals(false, CDateTimeParser::parse('04:04:1980', DatabaseCompatibilityUtil::getDateFormat()));
$this->assertEquals(null, DateTimeUtil::resolveValueForDateLocaleFormattedDisplay('04:04:1980'));
$model = new DateDateTime();
$model->aDate = '04:04:1980';
$model->aDateTime = 'notATimeStamp';
$saved = $model->save();
$this->assertFalse($saved);
$compareData = array('aDate' => array('A Date must be date.'), 'aDateTime' => array('A Date Time must be datetime.'));
$this->assertEquals($compareData, $model->getErrors());
//Now test setting an integer for dateTime which is wrong
$model = new DateDateTime();
$model->aDate = '1981-07-05';
$model->aDateTime = 1241341412421;
$saved = $model->save();
$this->assertFalse($saved);
$compareData = array('aDateTime' => array('A Date Time must be datetime.'));
$this->assertEquals($compareData, $model->getErrors());
//Now test a successful validation.
$this->assertEquals('M/d/yy', DateTimeUtil::getLocaleDateFormat());
$model = new DateDateTime();
$model->aDate = '1981-07-05';
$model->aDateTime = '1981-07-05 04:04:04';
$saved = $model->save();
$this->assertEquals(array(), $model->getErrors());
$this->assertTrue($saved);
$this->assertNull($model->aDateTime2);
//now set DateTime2 and test if you save and then clear it that it is behaving properly.
$model->aDateTime2 = '1981-07-05 04:04:04';
$saved = $model->save();
$this->assertTrue($saved);
$this->assertEquals('1981-07-05 04:04:04', $model->aDateTime2);
$model->aDateTime2 = null;
$saved = $model->save();
$this->assertTrue($saved);
$id = $model->id;
$model->forget();
$model = DateDateTime::getById($id);
$this->assertNull($model->aDateTime2);
}
示例4: testCalculateNew
public function testCalculateNew()
{
//Test Today.
$todayDateStamp = DateTimeCalculatorUtil::calculateNew(DateTimeCalculatorUtil::TODAY, new DateTime(null, new DateTimeZone(Yii::app()->timeZoneHelper->getForCurrentUser())));
$todayDateTime = new DateTime(null, new DateTimeZone(Yii::app()->timeZoneHelper->getForCurrentUser()));
$today = Yii::app()->dateFormatter->format(DatabaseCompatibilityUtil::getDateFormat(), $todayDateTime->getTimeStamp());
$this->assertEquals($today, $todayDateStamp);
//Test Tomorrow.
$tomorrowDateStamp = DateTimeCalculatorUtil::calculateNew(DateTimeCalculatorUtil::TOMORROW, new DateTime(null, new DateTimeZone(Yii::app()->timeZoneHelper->getForCurrentUser())));
$tomorrowDateTime = new DateTime(null, new DateTimeZone(Yii::app()->timeZoneHelper->getForCurrentUser()));
$tomorrow = Yii::app()->dateFormatter->format(DatabaseCompatibilityUtil::getDateFormat(), $tomorrowDateTime->getTimeStamp() + 60 * 60 * 24);
$this->assertEquals($tomorrow, $tomorrowDateStamp);
//Test Yesterday.
$yesterdayDateStamp = DateTimeCalculatorUtil::calculateNew(DateTimeCalculatorUtil::YESTERDAY, new DateTime(null, new DateTimeZone(Yii::app()->timeZoneHelper->getForCurrentUser())));
$yesterdayDateTime = new DateTime(null, new DateTimeZone(Yii::app()->timeZoneHelper->getForCurrentUser()));
$yesterday = Yii::app()->dateFormatter->format(DatabaseCompatibilityUtil::getDateFormat(), $yesterdayDateTime->getTimeStamp() - 60 * 60 * 24);
$this->assertEquals($yesterday, $yesterdayDateStamp);
//Test Now.
$nowDateTimeStamp = DateTimeCalculatorUtil::calculateNew(DateTimeCalculatorUtil::NOW, new DateTime(null, new DateTimeZone(Yii::app()->timeZoneHelper->getForCurrentUser())));
$nowDateTime = new DateTime(null, new DateTimeZone(Yii::app()->timeZoneHelper->getForCurrentUser()));
$this->assertWithinTolerance($nowDateTime->getTimeStamp(), DateTimeUtil::convertDbFormatDateTimeToTimestamp($nowDateTimeStamp), 1);
//Now test all calculations using a different time zone.
$this->assertNotEquals('Europe/Malta', Yii::app()->timeZoneHelper->getForCurrentUser());
//Test Today.
$todayDateStamp = DateTimeCalculatorUtil::calculateNew(DateTimeCalculatorUtil::TODAY, new DateTime(null, new DateTimeZone('Europe/Malta')));
$todayDateTime = new DateTime(null, new DateTimeZone('Europe/Malta'));
$today = Yii::app()->dateFormatter->format(DatabaseCompatibilityUtil::getDateFormat(), $todayDateTime->getTimeStamp());
$this->assertEquals($today, $todayDateStamp);
//Test Tomorrow.
$tomorrowDateStamp = DateTimeCalculatorUtil::calculateNew(DateTimeCalculatorUtil::TOMORROW, new DateTime(null, new DateTimeZone('Europe/Malta')));
$tomorrowDateTime = new DateTime(null, new DateTimeZone('Europe/Malta'));
$tomorrow = Yii::app()->dateFormatter->format(DatabaseCompatibilityUtil::getDateFormat(), $tomorrowDateTime->getTimeStamp() + 60 * 60 * 24);
$this->assertEquals($tomorrow, $tomorrowDateStamp);
//Test Yesterday.
$yesterdayDateStamp = DateTimeCalculatorUtil::calculateNew(DateTimeCalculatorUtil::YESTERDAY, new DateTime(null, new DateTimeZone('Europe/Malta')));
$yesterdayDateTime = new DateTime(null, new DateTimeZone('Europe/Malta'));
$yesterday = Yii::app()->dateFormatter->format(DatabaseCompatibilityUtil::getDateFormat(), $yesterdayDateTime->getTimeStamp() - 60 * 60 * 24);
$this->assertEquals($yesterday, $yesterdayDateStamp);
//Test Now.
$nowDateTimeStamp = DateTimeCalculatorUtil::calculateNew(DateTimeCalculatorUtil::NOW, new DateTime(null, new DateTimeZone('Europe/Malta')));
$nowDateTime = new DateTime(null, new DateTimeZone('Europe/Malta'));
$this->assertWithinTolerance($nowDateTime->getTimeStamp(), DateTimeUtil::convertDbFormatDateTimeToTimestamp($nowDateTimeStamp), 1);
}
示例5: setAndGetDateAttribute
protected function setAndGetDateAttribute($attributeName, $withDefaultData)
{
$this->assertTrue(isset($attributeName) && $attributeName != '');
$this->assertTrue(isset($withDefaultData) && is_bool($withDefaultData));
$attributeForm = new DateAttributeForm();
$attributeForm->attributeName = $attributeName;
$attributeForm->attributeLabels = array('de' => 'Test Date 2 de', 'en' => 'Test Date 2 en', 'es' => 'Test Date 2 es', 'fr' => 'Test Date 2 fr', 'it' => 'Test Date 2 it');
$attributeForm->isAudited = true;
$attributeForm->isRequired = true;
if ($withDefaultData) {
$attributeForm->defaultValueCalculationType = DateTimeCalculatorUtil::YESTERDAY;
}
$modelAttributesAdapterClassName = $attributeForm::getModelAttributeAdapterNameForSavingAttributeFormData();
$adapter = new $modelAttributesAdapterClassName(new Account());
try {
$adapter->setAttributeMetadataFromForm($attributeForm);
} catch (FailedDatabaseSchemaChangeException $e) {
echo $e->getMessage();
$this->fail();
}
$attributeForm = AttributesFormFactory::createAttributeFormByAttributeName(new Account(), $attributeName . 'Cstm');
$this->assertEquals('Date', $attributeForm->getAttributeTypeName());
$this->assertEquals($attributeName . 'Cstm', $attributeForm->attributeName);
$compareAttributeLabels = array('de' => 'Test Date 2 de', 'en' => 'Test Date 2 en', 'es' => 'Test Date 2 es', 'fr' => 'Test Date 2 fr', 'it' => 'Test Date 2 it');
$this->assertEquals($compareAttributeLabels, $attributeForm->attributeLabels);
$this->assertEquals(true, $attributeForm->isAudited);
$this->assertEquals(true, $attributeForm->isRequired);
if ($withDefaultData) {
$this->assertEquals(DateTimeCalculatorUtil::YESTERDAY, $attributeForm->defaultValueCalculationType);
//Confirm default calculation loads correct default value for Account.
$account = new Account();
$yesterdayDateTime = new DateTime(null, new DateTimeZone(Yii::app()->timeZoneHelper->getForCurrentUser()));
$yesterday = Yii::app()->dateFormatter->format(DatabaseCompatibilityUtil::getDateFormat(), $yesterdayDateTime->getTimeStamp() - 60 * 60 * 24);
$this->assertEquals($yesterday, $account->{$attributeName . 'Cstm'});
} else {
$account = new Account();
$this->assertEquals(null, $attributeForm->defaultValueCalculationType);
$this->assertEquals(null, $account->{$attributeName . 'Cstm'});
}
}
示例6: testGetMetadataForDynamicDateTimeAttributeThatIsOnManyRelatedModel
public function testGetMetadataForDynamicDateTimeAttributeThatIsOnManyRelatedModel()
{
$super = User::getByUsername('super');
Yii::app()->user->userModel = $super;
$searchForm = new ASearchFormTestModel(new MixedRelationsModel());
//Make sure the timeZone is different than UTC for testing.
Yii::app()->user->userModel->timeZone = 'America/Chicago';
//TEST when no value present
$metadata = SearchFormAttributesToSearchDataProviderMetadataUtil::getMetadata($searchForm, 'dateDateTimeADate__Date', null);
$compareData = array(array('manyMany' => array('value' => array('aDate' => null))));
$this->assertEquals($compareData, $metadata);
//Test Date = Today
$value = array();
$value['type'] = MixedDateTypesSearchFormAttributeMappingRules::TYPE_TODAY;
$metadata = SearchFormAttributesToSearchDataProviderMetadataUtil::getMetadata($searchForm, 'dateDateTimeADateTime__DateTime', $value);
$todayDateTime = new DateTime(null, new DateTimeZone(Yii::app()->timeZoneHelper->getForCurrentUser()));
$today = Yii::app()->dateFormatter->format(DatabaseCompatibilityUtil::getDateFormat(), $todayDateTime->getTimeStamp());
$compareData = array(array('manyMany' => array('value' => array('aDateTime' => DateTimeUtil::convertDateIntoTimeZoneAdjustedDateTimeBeginningOfDay($today)), 'operatorType' => 'greaterThanOrEqualTo', 'appendStructureAsAnd' => true)), array('manyMany' => array('value' => array('aDateTime' => DateTimeUtil::convertDateIntoTimeZoneAdjustedDateTimeEndOfDay($today)), 'operatorType' => 'lessThanOrEqualTo', 'appendStructureAsAnd' => true)));
$this->assertEquals($compareData, $metadata);
}
开发者ID:youprofit,项目名称:Zurmo,代码行数:20,代码来源:SearchFormAttributesToSearchDataProviderMetadataUtilTest.php
示例7: testGetDateFormat
public function testGetDateFormat()
{
$this->assertEquals('yyyy-MM-dd', DatabaseCompatibilityUtil::getDateFormat());
}
示例8: testSearchFormDynamicAttributes
public function testSearchFormDynamicAttributes()
{
$super = User::getByUsername('super');
Yii::app()->user->userModel = $super;
$searchAttributes = array('aaaMember' => 'Vomitorio Corp', 'bbb' => array('relatedData' => true, 'ccc' => array('relatedData' => true, 'date__Date' => array('type' => MixedDateTypesSearchFormAttributeMappingRules::TYPE_AFTER, 'firstDate' => '1991-03-04'), 'dateTime__DateTime' => array('type' => MixedDateTypesSearchFormAttributeMappingRules::TYPE_TODAY), 'dateTime2__DateTime' => array('value' => null), 'eee' => array('relatedData' => true, 'eeeMember' => 'eeeMemberValue'), 'iii' => array('relatedData' => true, 'date__Date' => array('type' => MixedDateTypesSearchFormAttributeMappingRules::TYPE_AFTER, 'firstDate' => '1991-03-04'), 'dateTime__DateTime' => array('type' => MixedDateTypesSearchFormAttributeMappingRules::TYPE_TODAY), 'dateTime2__DateTime' => array('value' => null)))));
$metadataAdapter = new SearchDataProviderMetadataAdapter(new AAA(false), 1, $searchAttributes);
$todayDateTime = new DateTime(null, new DateTimeZone(Yii::app()->timeZoneHelper->getForCurrentUser()));
$today = Yii::app()->dateFormatter->format(DatabaseCompatibilityUtil::getDateFormat(), $todayDateTime->getTimeStamp());
$todayPlus7Days = MixedDateTypesSearchFormAttributeMappingRules::calculateNewDateByDaysFromNow(7);
$metadata = $metadataAdapter->getAdaptedMetadata();
$compareClauses = array(1 => array('attributeName' => 'aaaMember', 'operatorType' => 'startsWith', 'value' => 'Vomitorio Corp'), 2 => array('attributeName' => 'bbb', 'relatedModelData' => array('attributeName' => 'ccc', 'relatedModelData' => array('attributeName' => 'date', 'operatorType' => 'greaterThanOrEqualTo', 'value' => '1991-03-04'))), 3 => array('attributeName' => 'bbb', 'relatedModelData' => array('attributeName' => 'ccc', 'relatedModelData' => array('attributeName' => 'dateTime', 'operatorType' => 'greaterThanOrEqualTo', 'value' => DateTimeUtil::convertDateIntoTimeZoneAdjustedDateTimeBeginningOfDay($today)))), 4 => array('attributeName' => 'bbb', 'relatedModelData' => array('attributeName' => 'ccc', 'relatedModelData' => array('attributeName' => 'dateTime', 'operatorType' => 'lessThanOrEqualTo', 'value' => DateTimeUtil::convertDateIntoTimeZoneAdjustedDateTimeEndOfDay($today)))), 5 => array('attributeName' => 'bbb', 'relatedModelData' => array('attributeName' => 'ccc', 'relatedModelData' => array('attributeName' => 'eee', 'relatedModelData' => array('attributeName' => 'eeeMember', 'operatorType' => 'startsWith', 'value' => 'eeeMemberValue')))), 6 => array('attributeName' => 'bbb', 'relatedModelData' => array('attributeName' => 'ccc', 'relatedModelData' => array('attributeName' => 'iii', 'relatedModelData' => array('attributeName' => 'date', 'operatorType' => 'greaterThanOrEqualTo', 'value' => '1991-03-04')))), 7 => array('attributeName' => 'bbb', 'relatedModelData' => array('attributeName' => 'ccc', 'relatedModelData' => array('attributeName' => 'iii', 'relatedModelData' => array('attributeName' => 'dateTime', 'operatorType' => 'greaterThanOrEqualTo', 'value' => DateTimeUtil::convertDateIntoTimeZoneAdjustedDateTimeBeginningOfDay($today))))), 8 => array('attributeName' => 'bbb', 'relatedModelData' => array('attributeName' => 'ccc', 'relatedModelData' => array('attributeName' => 'iii', 'relatedModelData' => array('attributeName' => 'dateTime', 'operatorType' => 'lessThanOrEqualTo', 'value' => DateTimeUtil::convertDateIntoTimeZoneAdjustedDateTimeEndOfDay($today))))));
$compareStructure = '1 and (2) and (3 and 4) and 5 and (6) and (7 and 8)';
$this->assertEquals($compareClauses, $metadata['clauses']);
$this->assertEquals($compareStructure, $metadata['structure']);
}
开发者ID:maruthisivaprasad,项目名称:zurmo,代码行数:15,代码来源:SearchDataProviderMetadataAdapterForRecursiveSearchesTest.php
示例9: testSearchFormDynamicAttributes
public function testSearchFormDynamicAttributes()
{
$super = User::getByUsername('super');
Yii::app()->user->userModel = $super;
$searchAttributes = array('date__Date' => array('type' => MixedDateTypesSearchFormAttributeMappingRules::TYPE_AFTER, 'firstDate' => '1991-03-04'), 'dateTime__DateTime' => array('type' => MixedDateTypesSearchFormAttributeMappingRules::TYPE_TODAY), 'dateTime2__DateTime' => array('value' => null));
$searchForm = new MixedRelationsModelSearchFormTestModel(new MixedRelationsModel());
$metadataAdapter = new SearchDataProviderMetadataAdapter($searchForm, $super->id, $searchAttributes);
$todayDateTime = new DateTime(null, new DateTimeZone(Yii::app()->timeZoneHelper->getForCurrentUser()));
$today = Yii::app()->dateFormatter->format(DatabaseCompatibilityUtil::getDateFormat(), $todayDateTime->getTimeStamp());
$todayPlus7Days = MixedDateTypesSearchFormAttributeMappingRules::calculateNewDateByDaysFromNow(7);
$metadata = $metadataAdapter->getAdaptedMetadata();
$compareClauses = array(1 => array('attributeName' => 'date', 'operatorType' => 'greaterThanOrEqualTo', 'value' => '1991-03-04'), 2 => array('attributeName' => 'dateTime', 'operatorType' => 'greaterThanOrEqualTo', 'value' => DateTimeUtil::convertDateIntoTimeZoneAdjustedDateTimeBeginningOfDay($today)), 3 => array('attributeName' => 'dateTime', 'operatorType' => 'lessThanOrEqualTo', 'value' => DateTimeUtil::convertDateIntoTimeZoneAdjustedDateTimeEndOfDay($today)));
$compareStructure = '(1) and (2 and 3)';
$this->assertEquals($compareClauses, $metadata['clauses']);
$this->assertEquals($compareStructure, $metadata['structure']);
}
示例10: calculateNewByDaysFromNow
/**
* Given an integer representing a count of days from the present day, returns a DB formatted date stamp based
* on that calculation.
* @param integer $daysFromNow
*/
public static function calculateNewByDaysFromNow($daysFromNow, DateTime $dateTime)
{
assert('is_int($daysFromNow)');
$dateTime->modify($daysFromNow . ' day');
return Yii::app()->dateFormatter->format(DatabaseCompatibilityUtil::getDateFormat(), $dateTime->getTimestamp());
}
示例11: getLastDayOfAMonthDate
public static function getLastDayOfAMonthDate($stringTime = null)
{
assert('is_string($stringTime) || $stringTime == null');
$dateTime = new DateTime($stringTime);
$dateTime->modify('last day of this month');
return Yii::app()->dateFormatter->format(DatabaseCompatibilityUtil::getDateFormat(), $dateTime->getTimestamp());
}
示例12: sanitizeAndResolveThirdValue
protected function sanitizeAndResolveThirdValue()
{
if ($this->trigger->valueEvaluationType == 'Date') {
$todayDate = Yii::app()->dateFormatter->format(DatabaseCompatibilityUtil::getDateFormat(), time());
$todayDateTime = DateTimeUtil::resolveDateAsDateTime($todayDate);
return $this->trigger->resolveNewTimeStampForThirdValueDuration(strtotime($todayDateTime));
} elseif ($this->trigger->valueEvaluationType == 'DateTime') {
$timeZone = date_default_timezone_get();
date_default_timezone_set('GMT');
$timeStamp = $this->trigger->resolveNewTimeStampForThirdValueDuration(time());
date_default_timezone_set($timeZone);
return $timeStamp;
} else {
throw new NotSupportedException();
}
}
示例13: getTomorrowsDate
/**
* Gets tomorrows date.
* @return string
*/
public static function getTomorrowsDate()
{
$dateTime = new DateTime();
$dateTime->modify('tomorrow');
return Yii::app()->dateFormatter->format(DatabaseCompatibilityUtil::getDateFormat(), $dateTime->getTimestamp());
}
示例14: getEndDate
/**
* Gets end date.
* @param string $dateRangeType
* @return string
*/
public static function getEndDate($dateRangeType)
{
assert('is_string($dateRangeType)');
if ($dateRangeType == SavedCalendar::DATERANGE_TYPE_MONTH) {
$dateTime = new DateTime();
$dateTime->modify('first day of next month');
return Yii::app()->dateFormatter->format(DatabaseCompatibilityUtil::getDateFormat(), $dateTime->getTimestamp());
}
if ($dateRangeType == SavedCalendar::DATERANGE_TYPE_WEEK) {
$dateTime = new DateTime('Monday next week');
return Yii::app()->dateFormatter->format(DatabaseCompatibilityUtil::getDateFormat(), $dateTime->getTimestamp());
}
if ($dateRangeType == SavedCalendar::DATERANGE_TYPE_DAY) {
return DateTimeUtil::getTomorrowsDate();
}
}