本文整理汇总了PHP中DateTimeUtil::convertTimestampToDbFormatDate方法的典型用法代码示例。如果您正苦于以下问题:PHP DateTimeUtil::convertTimestampToDbFormatDate方法的具体用法?PHP DateTimeUtil::convertTimestampToDbFormatDate怎么用?PHP DateTimeUtil::convertTimestampToDbFormatDate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DateTimeUtil
的用法示例。
在下文中一共展示了DateTimeUtil::convertTimestampToDbFormatDate方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sanitizeValue
/**
* Given a value, attempt to convert the value to a db date format based on the format provided. If the value
* does not convert properly, meaning the value is not really in the format specified, then a
* InvalidValueToSanitizeException will be thrown.
* @param mixed $value
* @return sanitized value
* @throws InvalidValueToSanitizeException
*/
public function sanitizeValue($value)
{
if ($value == null) {
return $value;
}
$timeStamp = CDateTimeParser::parse($value, $this->mappingRuleData['format']);
if ($timeStamp === false) {
throw new InvalidValueToSanitizeException(Zurmo::t('ImportModule', 'Invalid date format.'));
}
$dbDateValue = DateTimeUtil::convertTimestampToDbFormatDate($timeStamp);
return $dbDateValue;
}
示例2: sanitizeValue
/**
* Given a value, attempt to convert the value to a db date format based on the format provided. If the value
* does not convert properly, meaning the value is not really in the format specified, then a
* InvalidValueToSanitizeException will be thrown.
* @param string $modelClassName
* @param string $attributeName
* @param mixed $value
* @param array $mappingRuleData
*/
public static function sanitizeValue($modelClassName, $attributeName, $value, $mappingRuleData)
{
assert('is_string($modelClassName)');
assert('is_string($attributeName)');
assert('isset($mappingRuleData["format"])');
if ($value == null) {
return $value;
}
$timeStamp = CDateTimeParser::parse($value, $mappingRuleData['format']);
if ($timeStamp === false) {
throw new InvalidValueToSanitizeException(Zurmo::t('ImportModule', 'Invalid date format.'));
}
$dbDateValue = DateTimeUtil::convertTimestampToDbFormatDate($timeStamp);
return $dbDateValue;
}
示例3: resolveValueAndSetToModel
/**
* Utilized to create or update model attribute values after a workflow's triggers are fired as true.
* @param WorkflowActionProcessingModelAdapter $adapter
* @param $attribute
* @throws NotSupportedException
*/
public function resolveValueAndSetToModel(WorkflowActionProcessingModelAdapter $adapter, $attribute)
{
assert('is_string($attribute)');
if ($this->type == static::TYPE_STATIC) {
$adapter->getModel()->{$attribute} = $this->value;
} elseif ($this->type == self::TYPE_DYNAMIC_FROM_TRIGGERED_DATE) {
$adapter->getModel()->{$attribute} = DateTimeUtil::convertTimestampToDbFormatDate(time() + $this->value);
} elseif ($this->type == self::TYPE_DYNAMIC_FROM_EXISTING_DATE) {
if (!DateTimeUtil::isDateStringNull($adapter->getModel()->{$attribute})) {
$existingTimeStamp = DateTimeUtil::convertDbFormatDateTimeToTimestamp(DateTimeUtil::resolveDateAsDateTime($adapter->getModel()->{$attribute}));
$newDate = DateTimeUtil::convertTimestampToDbFormatDate($existingTimeStamp + $this->value);
$adapter->getModel()->{$attribute} = $newDate;
}
} else {
throw new NotSupportedException();
}
}
示例4: testDateResolveValueAndSetToModelUpdateAsDynamicFromTriggeredDate
public function testDateResolveValueAndSetToModelUpdateAsDynamicFromTriggeredDate()
{
$form = new DateWorkflowActionAttributeForm('WorkflowsTestModule', 'WorkflowModelTestItem');
$form->type = DateWorkflowActionAttributeForm::TYPE_DYNAMIC_FROM_TRIGGERED_DATE;
$form->durationInterval = '1';
$model = new WorkflowModelTestItem();
$model->date = '1980-06-03';
$adapter = new WorkflowActionProcessingModelAdapter($model, Yii::app()->user->userModel);
$form->resolveValueAndSetToModel($adapter, 'date');
$this->assertEquals(DateTimeUtil::convertTimestampToDbFormatDate(time() + 86400), $model->date);
}
示例5: testTriggerBeforeSaveLessThanXAfterTriggeredDate
/**
* @depends testTriggerBeforeSaveAtLeastXBeforeTriggeredDate
*/
public function testTriggerBeforeSaveLessThanXAfterTriggeredDate()
{
$workflow = self::makeOnSaveWorkflowAndTriggerForDateOrDateTime('date', 'Less Than X After Triggered Date', null, 'WorkflowsTestModule', 'WorkflowModelTestItem', null, 5, TimeDurationUtil::DURATION_TYPE_DAY);
$model = new WorkflowModelTestItem();
$model->lastName = 'someLastName';
$model->string = 'something';
//At this point the date value is null, so it should not trigger
$this->assertFalse(WorkflowTriggersUtil::areTriggersTrueBeforeSave($workflow, $model));
//Set the date to some time within the last day. it should pass
$model->date = DateTimeUtil::convertTimestampToDbFormatDate(time() - 86400);
$this->assertTrue(WorkflowTriggersUtil::areTriggersTrueBeforeSave($workflow, $model));
$model->date = DateTimeUtil::convertTimestampToDbFormatDate(time() + 86400);
$this->assertTrue(WorkflowTriggersUtil::areTriggersTrueBeforeSave($workflow, $model));
$model = self::saveAndReloadModel($model);
//Even though it changed, it changed to null, so it should not fire
$model->date = null;
$this->assertFalse(WorkflowTriggersUtil::areTriggersTrueBeforeSave($workflow, $model));
$model = self::saveAndReloadModel($model);
//This date is way in the future, so it should definitely not fire
$model->date = '2020-07-03';
$this->assertFalse(WorkflowTriggersUtil::areTriggersTrueBeforeSave($workflow, $model));
//The date is 6 days in the future, it should not fire
$model->date = DateTimeUtil::convertTimestampToDbFormatDate(time() + 86400 * 6);
$this->assertFalse(WorkflowTriggersUtil::areTriggersTrueBeforeSave($workflow, $model));
//This date is 5 days in the future, it should not fire
$model->date = DateTimeUtil::convertTimestampToDbFormatDate(time() + 86400 * 5);
$this->assertFalse(WorkflowTriggersUtil::areTriggersTrueBeforeSave($workflow, $model));
}
示例6: __construct
/**
* @param SavedCalendarSubscriptions $savedCalendarSubscriptions
* @param array $config
*/
public function __construct(SavedCalendarSubscriptions $savedCalendarSubscriptions, array $config = array())
{
$this->savedCalendarSubscriptions = $savedCalendarSubscriptions;
foreach ($config as $key => $value) {
$this->{$key} = $value;
}
$this->startDate = DateTimeUtil::convertTimestampToDbFormatDate(strtotime($this->startDate));
$this->endDate = DateTimeUtil::convertTimestampToDbFormatDate(strtotime($this->endDate));
$this->_itemCount = 0;
}