本文整理汇总了PHP中DateTimeUtil::isValidDbFormattedDate方法的典型用法代码示例。如果您正苦于以下问题:PHP DateTimeUtil::isValidDbFormattedDate方法的具体用法?PHP DateTimeUtil::isValidDbFormattedDate怎么用?PHP DateTimeUtil::isValidDbFormattedDate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DateTimeUtil
的用法示例。
在下文中一共展示了DateTimeUtil::isValidDbFormattedDate方法的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: testIsValidDbFormattedDate
public function testIsValidDbFormattedDate()
{
$this->assertTrue(DateTimeUtil::isValidDbFormattedDate('2011-09-23'));
$this->assertTrue(DateTimeUtil::isValidDbFormattedDate('1756-01-01'));
$this->assertFalse(DateTimeUtil::isValidDbFormattedDate('0011-09-23'));
$this->assertFalse(DateTimeUtil::isValidDbFormattedDate('2011-13-32'));
$this->assertFalse(DateTimeUtil::isValidDbFormattedDate('zxczxc'));
}
示例3: getFullCalendarFormattedDateTimeElement
/**
* Gets full calendar formatted date time.
* @param string $dateTime
* @return string formatted in datetime format required for full calendar widget
*/
public static function getFullCalendarFormattedDateTimeElement($dateTime)
{
assert('is_string($dateTime)');
//The reason its put because timezone can vary from -12:00 to +12:00 max so
//if we offset the gmt date by timezoneoffset, on applying offset, correct results
//would come.
if (DateTimeUtil::isValidDbFormattedDate($dateTime)) {
$dateTime = DateTimeUtil::convertDateToDateTimeByTimeZoneOffset($dateTime);
}
$dateTimeObject = new DateTime();
$dateTimeObject->setTimestamp(strtotime($dateTime));
$offset = ZurmoTimeZoneHelper::getTimeZoneOffset();
if ($offset < 0) {
$offset = abs($offset);
$dateTimeObject->sub(new DateInterval('PT' . $offset . 'S'));
} else {
$dateTimeObject->add(new DateInterval('PT' . $offset . 'S'));
}
return $dateTimeObject->format('c');
}