本文整理汇总了PHP中Drupal\Core\Datetime\DrupalDateTime::createFromFormat方法的典型用法代码示例。如果您正苦于以下问题:PHP DrupalDateTime::createFromFormat方法的具体用法?PHP DrupalDateTime::createFromFormat怎么用?PHP DrupalDateTime::createFromFormat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Datetime\DrupalDateTime
的用法示例。
在下文中一共展示了DrupalDateTime::createFromFormat方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: valueCallback
/**
* {@inheritdoc}
*/
public static function valueCallback(&$element, $input, FormStateInterface $form_state)
{
if ($input !== FALSE) {
$date_input = $element['#date_date_element'] != 'none' && !empty($input['date']) ? $input['date'] : '';
$time_input = $element['#date_time_element'] != 'none' && !empty($input['time']) ? $input['time'] : '';
$date_format = $element['#date_date_element'] != 'none' ? static::getHtml5DateFormat($element) : '';
$time_format = $element['#date_time_element'] != 'none' ? static::getHtml5TimeFormat($element) : '';
$timezone = !empty($element['#date_timezone']) ? $element['#date_timezone'] : NULL;
// Seconds will be omitted in a post in case there's no entry.
if (!empty($time_input) && strlen($time_input) == 5) {
$time_input .= ':00';
}
try {
$date_time_format = trim($date_format . ' ' . $time_format);
$date_time_input = trim($date_input . ' ' . $time_input);
$date = DrupalDateTime::createFromFormat($date_time_format, $date_time_input, $timezone);
} catch (\Exception $e) {
$date = NULL;
}
$input = array('date' => $date_input, 'time' => $time_input, 'object' => $date);
} else {
$date = $element['#default_value'];
if ($date instanceof DrupalDateTime && !$date->hasErrors()) {
$input = array('date' => $date->format($element['#date_date_format']), 'time' => $date->format($element['#date_time_format']), 'object' => $date);
} else {
$input = array('date' => '', 'time' => '', 'object' => NULL);
}
}
return $input;
}
示例2: getValue
/**
* {@inheritdoc}
*/
public function getValue($langcode = NULL)
{
if ($this->date !== NULL) {
return $this->date;
}
$item = $this->getParent();
$value = $item->{$this->definition->getSetting('date source')};
$storage_format = $item->getFieldDefinition()->getSetting('datetime_type') == 'date' ? DATETIME_DATE_STORAGE_FORMAT : DATETIME_DATETIME_STORAGE_FORMAT;
try {
$date = DrupalDateTime::createFromFormat($storage_format, $value, DATETIME_STORAGE_TIMEZONE);
if ($date instanceof DrupalDateTime && !$date->hasErrors()) {
$this->date = $date;
}
} catch (\Exception $e) {
// @todo Handle this.
}
return $this->date;
}
示例3: providerTestInvalidDateDiff
/**
* Provides data for date tests.
*
* @return array
* An array of arrays, each containing the input parameters for
* DateTimePlusTest::testInvalidDateDiff().
*
* @see DateTimePlusTest::testInvalidDateDiff()
*/
public function providerTestInvalidDateDiff()
{
$settings = ['langcode' => 'en'];
$utc_tz = new \DateTimeZone('UTC');
return array(array('input1' => DrupalDateTime::createFromFormat('U', 3600, $utc_tz, $settings), 'input2' => '1970-01-01 00:00:00', 'absolute' => FALSE), array('input1' => DrupalDateTime::createFromFormat('U', 3600, $utc_tz, $settings), 'input2' => NULL, 'absolute' => FALSE));
}