当前位置: 首页>>代码示例>>PHP>>正文


PHP Time::parseDate方法代码示例

本文整理汇总了PHP中Cake\I18n\Time::parseDate方法的典型用法代码示例。如果您正苦于以下问题:PHP Time::parseDate方法的具体用法?PHP Time::parseDate怎么用?PHP Time::parseDate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cake\I18n\Time的用法示例。


在下文中一共展示了Time::parseDate方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: render

    /**
     * Renders a date time widget.
     *
     * @param array $data Data to render with.
     * @param \Cake\View\Form\ContextInterface $context The current form context.
     * @return string A generated select box.
     * @throws \RuntimeException When option data is invalid.
     */
    public function render(array $data, ContextInterface $context)
    {
        $id = $data['id'];
        $name = $data['name'];
        $val = $data['val'];
        $type = $data['type'];
        $required = $data['required'] ? 'required' : '';
        $disabled = isset($data['disabled']) && $data['disabled'] ? 'disabled' : '';
        $role = isset($data['role']) ? $data['role'] : 'datetime-picker';
        $format = null;
        $locale = isset($data['locale']) ? $data['locale'] : I18n::locale();
        $timezoneAware = Configure::read('CrudView.timezoneAwareDateTimeWidget');
        $timestamp = null;
        $timezoneOffset = null;
        if (isset($data['data-format'])) {
            $format = $this->_convertPHPToMomentFormat($data['data-format']);
        }
        if (!$val instanceof DateTimeInterface && !empty($val)) {
            $val = $type === 'date' ? Time::parseDate($val) : Time::parseDateTime($val);
        }
        if ($val) {
            if ($timezoneAware) {
                $timestamp = $val->format('U');
                $dateTimeZone = new DateTimeZone(date_default_timezone_get());
                $timezoneOffset = $dateTimeZone->getOffset($val) / 60;
            }
            $val = $val->format($type === 'date' ? 'Y-m-d' : 'Y-m-d H:i:s');
        }
        if (!$format) {
            $format = $type === 'date' ? 'L' : 'L LT';
        }
        $widget = <<<html
            <div class="input-group {$type}">
                <input
                    type="text"
                    class="form-control"
                    name="{$name}"
                    value="{$val}"
                    id="{$id}"
                    role="{$role}"
                    data-locale="{$locale}"
                    data-format="{$format}"
html;
        if ($timezoneAware && isset($timestamp, $timezoneOffset)) {
            $widget .= <<<html
                    data-timestamp="{$timestamp}"
                    data-timezone-offset="{$timezoneOffset}"
html;
        }
        $widget .= <<<html
                    {$required}
                    {$disabled}
                />
                <label for="{$id}" class="input-group-addon">
                    <span class="glyphicon glyphicon-calendar"></span>
                </label>
            </div>
html;
        return $widget;
    }
开发者ID:friendsofcake,项目名称:crud-view,代码行数:68,代码来源:DateTimeWidget.php

示例2: render

 /**
  * Render a LilDate field.
  *
  * This method accepts a number of keys:
  *
  * - `text` The text of the button. Unlike all other form controls, buttons
  *   do not escape their contents by default.
  * - `escape` Set to true to enable escaping on all attributes.
  * - `type` The button type defaults to 'submit'.
  *
  * Any other keys provided in $data will be converted into HTML attributes.
  *
  * @param array            $data    The data to build a button with.
  * @param ContextInterface $context The form context.
  * 
  * @return string
  */
 public function render(array $data, ContextInterface $context)
 {
     $data += ['val' => '', 'name' => ''];
     if (is_a($data['val'], 'Cake\\I18n\\Time') || is_a($data['val'], 'Cake\\I18n\\Date') || is_a($data['val'], 'Cake\\I18n\\FrozenTime') || is_a($data['val'], 'Cake\\I18n\\FrozenDate')) {
         $data['value'] = $data['val']->toDateString();
     } else {
         if ($theDate = Time::parseDate($data['val'], 'yyyy-MM-dd')) {
             $data['value'] = $theDate->toDateString();
         }
     }
     // default field type is HTML5 date
     $fieldType = 'date';
     // localized date input with jquery date picker
     if (Configure::read('Lil.legacyDateFields')) {
         $fieldType = 'text';
         if ($theDate = Time::parseDate($data['value'], 'yyyy-MM-dd')) {
             $parts = str_split(Configure::read('Lil.dateFormat'));
             for ($i = 0; $i < sizeof($parts); $i++) {
                 $parts[$i] = strtr($parts[$i], ['D' => str_pad($theDate->day, 2, '0', STR_PAD_LEFT), 'M' => str_pad($theDate->month, 2, '0', STR_PAD_LEFT), 'Y' => $theDate->year]);
             }
             $data['value'] = implode(Configure::read('Lil.dateSeparator'), $parts);
         }
         $this->view->Lil->jsReady(sprintf('$("#%1$s").datepicker(%2$s);', $data['id'], $this->_jsOptions()));
     }
     return $this->templates->format('input', ['type' => $fieldType, 'name' => $data['name'], 'attrs' => $this->templates->formatAttributes($data, ['name', 'val'])]);
 }
开发者ID:malamalca,项目名称:lil,代码行数:43,代码来源:LilDateWidget.php

示例3: render

    /**
     * Renders a date time widget.
     *
     * @param array $data Data to render with.
     * @param \Cake\View\Form\ContextInterface $context The current form context.
     * @return string A generated select box.
     * @throws \RuntimeException When option data is invalid.
     */
    public function render(array $data, ContextInterface $context)
    {
        $id = $data['id'];
        $name = $data['name'];
        $val = $data['val'];
        $type = $data['type'];
        $required = $data['required'] ? 'required' : '';
        $role = isset($data['role']) ? $data['role'] : 'datetime-picker';
        $format = null;
        $timestamp = null;
        $locale = locale_get_primary_language(I18n::locale());
        if (isset($data['data-format'])) {
            $format = $this->_convertPHPToMomentFormat($data['data-format']);
        }
        if (!$val instanceof DateTime && !empty($val)) {
            $val = $type === 'date' ? Time::parseDate($val) : Time::parseDateTime($val);
        }
        if ($val) {
            $timestamp = $val->format('U');
            $val = $val->format($type === 'date' ? 'Y-m-d' : 'Y-m-d H:i:s');
        }
        if (!$format) {
            $format = $type === 'date' ? 'L' : 'L LT';
        }
        $widget = <<<html
            <div class="input-group {$type}">
                <input
                    type="text"
                    class="form-control"
                    name="{$name}"
                    value="{$val}"
                    id="{$id}"
                    role="{$role}"
                    data-locale="{$locale}"
                    data-format="{$format}"
                    data-timestamp="{$timestamp}"
                    {$required}
                />
                <span class="input-group-addon">
                    <span class="glyphicon glyphicon-calendar"></span>
                </span>
            </div>
html;
        return $widget;
    }
开发者ID:Wouter0100,项目名称:crud-view,代码行数:53,代码来源:DateTimeWidget.php

示例4: testParseDateDifferentTimezone

 /**
  * Tests that parsing a date respects de default timezone in PHP.
  *
  * @return void
  */
 public function testParseDateDifferentTimezone()
 {
     date_default_timezone_set('Europe/Paris');
     Time::$defaultLocale = 'fr-FR';
     $result = Time::parseDate('12/03/2015');
     $this->assertEquals('2015-03-12', $result->format('Y-m-d'));
     $this->assertEquals(new \DateTimeZone('Europe/Paris'), $result->tz);
 }
开发者ID:RogerSchmeier,项目名称:Webtruck,代码行数:13,代码来源:TimeTest.php

示例5: testParseDate

 /**
  * Tests parsing a string into a Time object based on the locale format.
  *
  * @return void
  */
 public function testParseDate()
 {
     $time = Time::parseDate('10/13/2013 12:54am');
     $this->assertNotNull($time);
     $this->assertEquals('2013-10-13 00:00', $time->format('Y-m-d H:i'));
     $time = Time::parseDate('10/13/2013');
     $this->assertNotNull($time);
     $this->assertEquals('2013-10-13 00:00', $time->format('Y-m-d H:i'));
     Time::$defaultLocale = 'fr-FR';
     $time = Time::parseDate('13 10, 2013 12:54');
     $this->assertNotNull($time);
     $this->assertEquals('2013-10-13 00:00', $time->format('Y-m-d H:i'));
     $time = Time::parseDate('13 foo 10 2013 12:54');
     $this->assertNull($time);
     $time = Time::parseDate('13 10, 2013', 'dd M, y');
     $this->assertNotNull($time);
     $this->assertEquals('2013-10-13', $time->format('Y-m-d'));
 }
开发者ID:neilan35,项目名称:betterwindow1,代码行数:23,代码来源:TimeTest.php


注:本文中的Cake\I18n\Time::parseDate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。