本文整理汇总了PHP中DateTimeUtil::isValidDbFormattedDateTime方法的典型用法代码示例。如果您正苦于以下问题:PHP DateTimeUtil::isValidDbFormattedDateTime方法的具体用法?PHP DateTimeUtil::isValidDbFormattedDateTime怎么用?PHP DateTimeUtil::isValidDbFormattedDateTime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DateTimeUtil
的用法示例。
在下文中一共展示了DateTimeUtil::isValidDbFormattedDateTime方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validateAttribute
/**
* Validates the attribute of the model.
* If there is any error, the error message is added to the model.
* @param RedBeanModel $model the model being validated
* @param string $attribute the attribute being validated
*/
protected function validateAttribute($object, $attribute)
{
$value = $object->{$attribute};
if ($this->allowEmpty && $this->isEmpty($value)) {
return;
}
switch ($this->type) {
case 'blob':
case 'longblob':
return;
case 'integer':
$valid = preg_match('/^[-+]?[0-9]+$/', trim($value));
// Not Coding Standard
break;
case 'float':
$valid = preg_match('/^[-+]?([0-9]*\\.)?[0-9]+([eE][-+]?[0-9]+)?$/', trim($value));
// Not Coding Standard
break;
case 'date':
$valid = DateTimeUtil::isValidDbFormattedDate($value);
break;
case 'time':
$valid = CDateTimeParser::parse($value, $this->timeFormat) !== false;
break;
case 'datetime':
$valid = DateTimeUtil::isValidDbFormattedDateTime($value);
break;
case 'array':
$valid = is_array($value);
break;
case 'string':
default:
return;
}
if (!$valid) {
if ($this->message !== null) {
$message = $this->message;
} else {
$message = Zurmo::t('Core', '{attribute} must be {type}.');
}
$this->addError($object, $attribute, $message, array('{type}' => $this->type));
}
}
示例2: testIsValidDbFormattedDateTime
public function testIsValidDbFormattedDateTime()
{
$this->assertTrue(DateTimeUtil::isValidDbFormattedDateTime('2011-09-23 23:23:23'));
$this->assertTrue(DateTimeUtil::isValidDbFormattedDateTime('1756-01-01 00:59:59'));
$this->assertFalse(DateTimeUtil::isValidDbFormattedDateTime('0011-09-23 23:23:23'));
$this->assertFalse(DateTimeUtil::isValidDbFormattedDateTime('2011-13-32 23:23:23'));
$this->assertFalse(DateTimeUtil::isValidDbFormattedDateTime('1011-09-23 24:23:23'));
$this->assertFalse(DateTimeUtil::isValidDbFormattedDateTime('2011-12-32 23:23:23'));
$this->assertFalse(DateTimeUtil::isValidDbFormattedDateTime('2011-12-32 23:60:23'));
$this->assertFalse(DateTimeUtil::isValidDbFormattedDateTime('2011-12-32 23:23:60'));
$this->assertFalse(DateTimeUtil::isValidDbFormattedDateTime('cascacasc'));
}
示例3: processGetModifiedItems
/**
* Get array of modified items since beginning or since datetime in past
* @param $params
* @return ApiResult
* @throws ApiException
*/
public function processGetModifiedItems($params)
{
try {
$modelClassName = $this->getModelName();
$stateMetadataAdapterClassName = $this->resolveStateMetadataAdapterClassName();
if (!isset($params['sinceDateTime'])) {
$sinceTimestamp = 0;
} else {
if (DateTimeUtil::isValidDbFormattedDateTime($params['sinceDateTime'])) {
$sinceTimestamp = DateTimeUtil::convertDbFormatDateTimeToTimestamp($params['sinceDateTime']);
} else {
$message = 'sinceDateTime format is not correct. sinceDateTime should be in "YYYY-MM-DD HH:MM:SS" format';
throw new ApiException($message);
}
}
$pageSize = Yii::app()->pagination->getGlobalValueByType('apiListPageSize');
if (isset($params['pagination']['pageSize'])) {
$pageSize = (int) $params['pagination']['pageSize'];
}
// Get offset. Please note that API client provide page number, and we need to convert it into offset,
// which is parameter of RedBeanModel::getSubset function
if (isset($params['pagination']['page']) && (int) $params['pagination']['page'] > 0) {
$currentPage = (int) $params['pagination']['page'];
} else {
$currentPage = 1;
}
$offset = $this->getOffsetFromCurrentPageAndPageSize($currentPage, $pageSize);
$models = ModelStateChangesSubscriptionUtil::getUpdatedModels($modelClassName, $pageSize, $offset, $sinceTimestamp, $stateMetadataAdapterClassName, Yii::app()->user->userModel);
$totalItems = ModelStateChangesSubscriptionUtil::getUpdatedModelsCount($modelClassName, $sinceTimestamp, $stateMetadataAdapterClassName, Yii::app()->user->userModel);
$data = array('totalCount' => $totalItems, 'pageSize' => $pageSize, 'currentPage' => $currentPage);
if (is_array($models) && !empty($models)) {
foreach ($models as $model) {
$data['items'][] = static::getModelToApiDataUtilData($model);
}
$result = new ApiResult(ApiResponse::STATUS_SUCCESS, $data, null, null);
} else {
$result = new ApiResult(ApiResponse::STATUS_SUCCESS, $data, null, null);
}
} catch (Exception $e) {
$message = $e->getMessage();
throw new ApiException($message);
}
return $result;
}