本文整理汇总了PHP中IntlDateFormatter::getPattern方法的典型用法代码示例。如果您正苦于以下问题:PHP IntlDateFormatter::getPattern方法的具体用法?PHP IntlDateFormatter::getPattern怎么用?PHP IntlDateFormatter::getPattern使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IntlDateFormatter
的用法示例。
在下文中一共展示了IntlDateFormatter::getPattern方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: finishView
/**
* {@inheritdoc}
*/
public function finishView(FormView $view, FormInterface $form, array $options)
{
$format = $options['format'];
if (isset($options['date_format']) && is_string($options['date_format'])) {
$format = $options['date_format'];
} elseif (is_int($format)) {
$timeFormat = $options['dp_pick_time'] ? DateTimeType::DEFAULT_TIME_FORMAT : \IntlDateFormatter::NONE;
$intlDateFormatter = new \IntlDateFormatter(\Locale::getDefault(), $format, $timeFormat, null, \IntlDateFormatter::GREGORIAN, null);
$format = $intlDateFormatter->getPattern();
}
// use seconds if it's allowe in format
$options['dp_use_seconds'] = strpos($format, 's') !== false;
$view->vars['moment_format'] = $this->formatConverter->convert($format);
$view->vars['type'] = 'text';
$dpOptions = array();
foreach ($options as $key => $value) {
if (false !== strpos($key, "dp_")) {
// We remove 'dp_' and camelize the options names
$dpKey = substr($key, 3);
$dpKey = preg_replace_callback('/_([a-z])/', function ($c) {
return strtoupper($c[1]);
}, $dpKey);
$dpOptions[$dpKey] = $value;
}
}
$view->vars['datepicker_use_button'] = empty($options['datepicker_use_button']) ? false : true;
$view->vars['dp_options'] = $dpOptions;
}
示例2: buildForm
public function buildForm(FormBuilderInterface $builder, array $options)
{
$format = $options['format'];
$pattern = null;
$allowedFormatOptionValues = array(\IntlDateFormatter::FULL, \IntlDateFormatter::LONG, \IntlDateFormatter::MEDIUM, \IntlDateFormatter::SHORT);
// If $format is not in the allowed options, it's considered as the pattern of the formatter if it is a string
if (!in_array($format, $allowedFormatOptionValues, true)) {
if (is_string($format)) {
$format = self::DEFAULT_FORMAT;
$pattern = $options['format'];
} else {
throw new CreationException('The "format" option must be one of the IntlDateFormatter constants (FULL, LONG, MEDIUM, SHORT) or a string representing a custom pattern');
}
}
$formatter = new \IntlDateFormatter(\Locale::getDefault(), $format, \IntlDateFormatter::NONE, 'UTC', \IntlDateFormatter::GREGORIAN, $pattern);
$formatter->setLenient(false);
$builder->addViewTransformer(new DateTimeToLocalizedStringTransformer($options['data_timezone'], $options['user_timezone'], $format, \IntlDateFormatter::NONE, \IntlDateFormatter::GREGORIAN, $pattern));
if ('string' === $options['input']) {
$builder->addModelTransformer(new ReversedTransformer(new DateTimeToStringTransformer($options['data_timezone'], $options['data_timezone'], 'Y-m-d')));
} elseif ('timestamp' === $options['input']) {
$builder->addModelTransformer(new ReversedTransformer(new DateTimeToTimestampTransformer($options['data_timezone'], $options['data_timezone'])));
} elseif ('array' === $options['input']) {
$builder->addModelTransformer(new ReversedTransformer(new DateTimeToArrayTransformer($options['data_timezone'], $options['data_timezone'], array('year', 'month', 'day'))));
}
$builder->setAttribute('date_pattern', $formatter->getPattern());
}
示例3: configureOptions
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$format = function (Options $options) {
$date_format = \IntlDateFormatter::NONE;
$time_format = \IntlDateFormatter::NONE;
if ($options['date_picker']) {
$date_format = \IntlDateFormatter::SHORT;
}
if ($options['time_picker']) {
$time_format = $options['with_seconds'] ? \IntlDateFormatter::MEDIUM : \IntlDateFormatter::SHORT;
}
$formater = new \IntlDateFormatter($options['locale'], $date_format, $time_format, $options['user_timezone'], \IntlDateFormatter::GREGORIAN, null);
$formater->setLenient(false);
$pattern = $formater->getPattern();
if (false === strpos($pattern, 'yyyy')) {
if (false !== strpos($pattern, 'yy')) {
$pattern = str_replace('yy', 'yyyy', $pattern);
} elseif (false !== strpos($pattern, 'y')) {
$pattern = str_replace('y', 'yyyy', $pattern);
}
}
return $pattern;
};
$resolver->setDefaults(array('widget' => 'single_text', 'locale' => \Locale::getDefault(), 'user_timezone' => null, 'date_picker' => true, 'time_picker' => true, 'time_picker_first' => false, 'button_id' => null, 'open_focus' => true, 'hour_min' => null, 'hour_max' => null, 'hour_step' => null, 'minute_min' => null, 'minute_max' => null, 'minute_step' => null, 'second_min' => null, 'second_max' => null, 'second_step' => null, 'format' => $format, 'empty_value' => null, 'with_minutes' => true, 'with_seconds' => false));
}
示例4: getFormat
/**
* {@inheritdoc}
*/
public function getFormat($locale)
{
if (isset($this->dateFormats[$locale])) {
return $this->dateFormats[$locale];
}
$formatter = new \IntlDateFormatter($locale, \IntlDateFormatter::SHORT, \IntlDateFormatter::NONE);
$icuFormat = $formatter->getPattern();
return $this->converter->convert($icuFormat);
}
示例5: getPattern
/**
* {@inheritdoc}
*/
public function getPattern($dateType, $timeType, $locale = null)
{
if (!$locale) {
$locale = $this->localeSettings->getLocale();
}
if ($timeType !== \IntlDateFormatter::NONE) {
$timeType = \IntlDateFormatter::SHORT;
}
$localeFormatter = new \IntlDateFormatter($locale, \IntlDateFormatter::SHORT, $timeType, null, \IntlDateFormatter::GREGORIAN);
$pattern = $localeFormatter->getPattern();
return $this->modifyPattern($pattern, $timeType);
}
示例6: getPattern
public function getPattern()
{
// set order as specified in the pattern
if ($this->getOption('pattern')) {
return $this->getOption('pattern');
}
// set right order with respect to locale (e.g.: de_DE=dd.MM.yy; en_US=M/d/yy)
// lookup various formats at http://userguide.icu-project.org/formatparse/datetime
if (preg_match('/^([yMd]+).+([yMd]+).+([yMd]+)$/', $this->formatter->getPattern())) {
return preg_replace(array('/y+/', '/M+/', '/d+/'), array('{{ year }}', '{{ month }}', '{{ day }}'), $this->formatter->getPattern());
}
// default fallback
return '{{ year }}-{{ month }}-{{ day }}';
}
示例7: getJavascriptPattern
/**
* Create pattern Date Javascript
*
* @param IntlDateFormatter $formatter
*
* @return string pattern date of Javascript
*/
protected function getJavascriptPattern(\IntlDateFormatter $formatter)
{
$pattern = $formatter->getPattern();
$patterns = preg_split('([\\\\/.:_;,\\s-\\ ]{1})', $pattern);
$exits = array();
// Transform pattern for JQuery ui datepicker
foreach ($patterns as $index => $val) {
switch ($val) {
case 'yy':
$exits[$val] = 'y';
break;
case 'y':
case 'yyyy':
$exits[$val] = 'yy';
break;
case 'M':
$exits[$val] = 'm';
break;
case 'MM':
case 'L':
case 'LL':
$exits[$val] = 'mm';
break;
case 'MMM':
case 'LLL':
$exits[$val] = 'M';
break;
case 'MMMM':
case 'LLLL':
$exits[$val] = 'MM';
break;
case 'D':
$exits[$val] = 'o';
break;
case 'E':
case 'EE':
case 'EEE':
case 'eee':
$exits[$val] = 'D';
break;
case 'EEEE':
case 'eeee':
$exits[$val] = 'DD';
break;
}
}
return str_replace(array_keys($exits), array_values($exits), $pattern);
}
示例8: finishView
public function finishView(FormView $view, FormInterface $form, array $options)
{
parent::finishView($view, $form, $options);
$format = $options['format'];
if (is_int($format)) {
$formatter = new \IntlDateFormatter(\Locale::getDefault(), $format, \IntlDateFormatter::NONE);
$format = $formatter->getPattern();
}
$view->vars['locale'] = \Locale::getDefault();
$view->vars['format_php'] = $format;
if ($this->convertPhpFormatToJQueryUI('yyyy') == 'y') {
die('nan');
}
$format = $this->convertPhpFormatToJQueryUI($format);
$view->vars['format_js'] = $format;
}
示例9: setDefaultOptions
/**
* {@inheritdoc}
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$format = function (Options $options, $value) {
if ($options['widget'] === 'single_text') {
$formatter = new \IntlDateFormatter(\Locale::getDefault(), \IntlDateFormatter::SHORT, \IntlDateFormatter::NONE);
$format = $formatter->getPattern();
$this->replaceInString('yy', 'yyyy', $format);
$this->replaceInString('d', 'dd', $format);
return $format;
}
return $value;
};
$resolver->setDefaults(array('format' => $format, 'language' => \Locale::getDefault(), 'leading_zero' => false));
$resolver->setOptional(array('placeholder', 'language', 'leading_zero'));
$resolver->setAllowedTypes(array('placeholder' => array('string'), 'language' => array('string'), 'leading_zero' => array('bool')));
}
示例10: get_livedit
public function get_livedit()
{
$data = new DateTime();
$locale = 'it-it';
$fmt = new IntlDateFormatter($locale, IntlDateFormatter::SHORT, IntlDateFormatter::NONE);
echo $fmt->format($data) . '<br>';
echo 'pattern is ' . $fmt->getPattern() . '<br>';
$locale = 'it_CH';
$fmt = new IntlDateFormatter($locale, IntlDateFormatter::SHORT, IntlDateFormatter::SHORT);
echo $fmt->format($data) . '<br>';
echo 'pattern ' . $fmt->getPattern() . '<br>';
$locale = 'en-US';
$fmt = new IntlDateFormatter($locale, IntlDateFormatter::SHORT, IntlDateFormatter::SHORT);
echo $fmt->format($data) . '<br>';
echo 'pattern ' . $fmt->getPattern() . '<br>';
die('NO');
}
示例11: render
/**
* {@inheritDoc}
*/
public function render(array $attributes = array())
{
if ($this->getOption('widget') === self::INPUT) {
return $this->generator->tag('input', array_merge(array('id' => $this->getId(), 'name' => $this->getName(), 'value' => $this->getDisplayedData(), 'type' => 'text'), $attributes));
} else {
// set order as specified in the pattern
if ($this->getOption('pattern')) {
$pattern = $this->getOption('pattern');
} else {
if (preg_match('/^([yMd]+).+([yMd]+).+([yMd]+)$/', $this->formatter->getPattern())) {
$pattern = preg_replace(array('/y+/', '/M+/', '/d+/'), array('%year%', '%month%', '%day%'), $this->formatter->getPattern());
} else {
$pattern = '%year%-%month%-%day%';
}
}
return str_replace(array('%year%', '%month%', '%day%'), array($this->get('year')->render($attributes), $this->get('month')->render($attributes), $this->get('day')->render($attributes)), $pattern);
}
}
示例12: initPattern
private function initPattern()
{
$formatter = new IntlDateFormatter($this->localeString, IntlDateFormatter::SHORT, IntlDateFormatter::NONE);
$pattern = $formatter->getPattern();
$properties = array('dateFieldDelimiter' => NULL, 'MDY_dayPosition' => NULL, 'MDY_monthPosition' => NULL, 'MDY_yearPosition' => NULL);
$position = 0;
for ($i = 0; $i < strlen($pattern); ++$i) {
switch (substr($pattern, $i, 1)) {
case 'y':
case 'Y':
case 'u':
if (NULL === $properties['MDY_yearPosition']) {
$properties['MDY_yearPosition'] = ++$position;
}
break;
case 'M':
case 'L':
if (NULL === $properties['MDY_monthPosition']) {
$properties['MDY_monthPosition'] = ++$position;
}
break;
case 'd':
if (NULL === $properties['MDY_dayPosition']) {
$properties['MDY_dayPosition'] = ++$position;
}
break;
case ' ':
// ignore
break;
default:
if (NULL === $properties['dateFieldDelimiter']) {
$properties['dateFieldDelimiter'] = substr($pattern, $i, 1);
}
break;
}
}
$this->properties = array_merge($this->properties, $properties);
}
示例13: formatTimestamps
private function formatTimestamps(\IntlDateFormatter $formatter, $regex, array $timestamps)
{
$pattern = $formatter->getPattern();
$timezone = $formatter->getTimezoneId();
if (version_compare(\PHP_VERSION, '5.5.0-dev', '>=')) {
$formatter->setTimeZone(\DateTimeZone::UTC);
} else {
$formatter->setTimeZoneId(\DateTimeZone::UTC);
}
if (preg_match($regex, $pattern, $matches)) {
$formatter->setPattern($matches[0]);
foreach ($timestamps as $key => $timestamp) {
$timestamps[$key] = $formatter->format($timestamp);
}
// I'd like to clone the formatter above, but then we get a
// segmentation fault, so let's restore the old state instead
$formatter->setPattern($pattern);
}
if (version_compare(\PHP_VERSION, '5.5.0-dev', '>=')) {
$formatter->setTimeZone($timezone);
} else {
$formatter->setTimeZoneId($timezone);
}
return $timestamps;
}
示例14: formatTimestamps
private function formatTimestamps(\IntlDateFormatter $formatter, $regex, array $timestamps)
{
$pattern = $formatter->getPattern();
$timezone = $formatter->getTimezoneId();
if ($setTimeZone = method_exists($formatter, 'setTimeZone')) {
$formatter->setTimeZone('UTC');
} else {
$formatter->setTimeZoneId('UTC');
}
if (preg_match($regex, $pattern, $matches)) {
$formatter->setPattern($matches[0]);
foreach ($timestamps as $key => $timestamp) {
$timestamps[$key] = $formatter->format($timestamp);
}
// I'd like to clone the formatter above, but then we get a
// segmentation fault, so let's restore the old state instead
$formatter->setPattern($pattern);
}
if ($setTimeZone) {
$formatter->setTimeZone($timezone);
} else {
$formatter->setTimeZoneId($timezone);
}
return $timestamps;
}
示例15: getPattern
/**
* Get the pattern used for the IntlDateFormatter
*
* @param int|string $dateType Constant of IntlDateFormatter (NONE, FULL, LONG, MEDIUM, SHORT) or it's string name
* @param int|string $timeType Constant IntlDateFormatter (NONE, FULL, LONG, MEDIUM, SHORT) or it's string name
* @param string|null $locale
* @return string
*/
public function getPattern($dateType, $timeType, $locale = null)
{
if (!$locale) {
$locale = $this->localeSettings->getLocale();
}
if (null === $dateType) {
$dateType = static::DEFAULT_DATE_TYPE;
}
if (null === $timeType) {
$timeType = static::DEFAULT_TIME_TYPE;
}
$dateType = $this->parseDateType($dateType);
$timeType = $this->parseDateType($timeType);
$localeFormatter = new \IntlDateFormatter($locale, $dateType, $timeType, null, \IntlDateFormatter::GREGORIAN);
return $localeFormatter->getPattern();
}