Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions
Datetime Class Reference
Inheritance diagram for Datetime:
Date AbstractFilter AbstractBlock FilterInterface AbstractBlock DataObject BlockInterface

Public Member Functions

 getHtml ()
 
 getEscapedValue ($index=null)
 
- Public Member Functions inherited from Date
 __construct (\Magento\Backend\Block\Context $context, \Magento\Framework\DB\Helper $resourceHelper, \Magento\Framework\Math\Random $mathRandom, \Magento\Framework\Locale\ResolverInterface $localeResolver, DateTimeFormatterInterface $dateTimeFormatter, array $data=[])
 
 getHtml ()
 
 getEscapedValue ($index=null)
 
 getValue ($index=null)
 
 getCondition ()
 
 setValue ($value)
 
- Public Member Functions inherited from AbstractFilter
 __construct (\Magento\Backend\Block\Context $context, \Magento\Framework\DB\Helper $resourceHelper, array $data=[])
 
 setColumn ($column)
 
 getColumn ()
 
 getEscapedValue ($index=null)
 
 getCondition ()
 
 getHtml ()
 
- Public Member Functions inherited from AbstractBlock
 __construct (\Magento\Backend\Block\Context $context, array $data=[])
 
- Public Member Functions inherited from AbstractBlock
 __construct (\Magento\Framework\View\Element\Context $context, array $data=[])
 
 getJsLayout ()
 
 getRequest ()
 
 getParentBlock ()
 
 setLayout (\Magento\Framework\View\LayoutInterface $layout)
 
 getLayout ()
 
 setNameInLayout ($name)
 
 getChildNames ()
 
 setAttribute ($name, $value=null)
 
 setChild ($alias, $block)
 
 addChild ($alias, $block, $data=[])
 
 unsetChild ($alias)
 
 unsetCallChild ($alias, $callback, $result, $params)
 
 unsetChildren ()
 
 getChildBlock ($alias)
 
 getChildHtml ($alias='', $useCache=true)
 
 getChildChildHtml ($alias, $childChildAlias='', $useCache=true)
 
 getBlockHtml ($name)
 
 insert ($element, $siblingName=0, $after=true, $alias='')
 
 append ($element, $alias='')
 
 getGroupChildNames ($groupName)
 
 getChildData ($alias, $key='')
 
 getUiId ($arg1=null, $arg2=null, $arg3=null, $arg4=null, $arg5=null)
 
 getJsId ($arg1=null, $arg2=null, $arg3=null, $arg4=null, $arg5=null)
 
 getUrl ($route='', $params=[])
 
 getViewFileUrl ($fileId, array $params=[])
 
 formatDate ( $date=null, $format=\IntlDateFormatter::SHORT, $showTime=false, $timezone=null)
 
 formatTime ( $time=null, $format=\IntlDateFormatter::SHORT, $showDate=false)
 
 getModuleName ()
 
 escapeHtml ($data, $allowedTags=null)
 
 escapeJs ($string)
 
 escapeHtmlAttr ($string, $escapeSingleQuote=true)
 
 escapeCss ($string)
 
 stripTags ($data, $allowableTags=null, $allowHtmlEntities=false)
 
 escapeUrl ($string)
 
 escapeXssInUrl ($data)
 
 escapeQuote ($data, $addSlashes=false)
 
 escapeJsQuote ($data, $quote='\'')
 
 getNameInLayout ()
 
 getCacheKeyInfo ()
 
 getCacheKey ()
 
 getVar ($name, $module=null)
 
 isScopePrivate ()
 
- Public Member Functions inherited from DataObject
 __construct (array $data=[])
 
 addData (array $arr)
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 getData ($key='', $index=null)
 
 getDataByPath ($path)
 
 getDataByKey ($key)
 
 setDataUsingMethod ($key, $args=[])
 
 getDataUsingMethod ($key, $args=null)
 
 hasData ($key='')
 
 toArray (array $keys=[])
 
 convertToArray (array $keys=[])
 
 toXml (array $keys=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 convertToXml (array $arrAttributes=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 toJson (array $keys=[])
 
 convertToJson (array $keys=[])
 
 toString ($format='')
 
 __call ($method, $args)
 
 isEmpty ()
 
 serialize ($keys=[], $valueSeparator='=', $fieldSeparator=' ', $quote='"')
 
 debug ($data=null, &$objects=[])
 
 offsetSet ($offset, $value)
 
 offsetExists ($offset)
 
 offsetUnset ($offset)
 
 offsetGet ($offset)
 
- Public Member Functions inherited from BlockInterface
 toHtml ()
 

Data Fields

const END_OF_DAY_IN_SECONDS = 86399
 
- Data Fields inherited from AbstractBlock
const CACHE_GROUP = \Magento\Framework\App\Cache\Type\Block::TYPE_IDENTIFIER
 
const CACHE_KEY_PREFIX = 'BLOCK_'
 

Protected Member Functions

 _convertDate ($date)
 
- Protected Member Functions inherited from Date
 _convertDate ($date)
 
- Protected Member Functions inherited from AbstractFilter
 _getHtmlName ()
 
 _getHtmlId ()
 
- Protected Member Functions inherited from AbstractBlock
 _construct ()
 
 _prepareLayout ()
 
 _beforeToHtml ()
 
 _afterToHtml ($html)
 
 _toHtml ()
 
 _getNotFoundUrl ($route='', $params=['_direct'=> 'core/index/notFound'])
 
 getCacheTags ()
 
 getCacheLifetime ()
 
 _loadCache ()
 
 _saveCache ($data)
 
 _getSidPlaceholder ($cacheKey=null)
 
- Protected Member Functions inherited from DataObject
 _getData ($key)
 
 _underscore ($name)
 

Additional Inherited Members

- Static Public Member Functions inherited from AbstractBlock
static extractModuleName ($className)
 
- Protected Attributes inherited from Date
 $mathRandom
 
 $localeResolver
 
 $dateTimeFormatter
 
- Protected Attributes inherited from AbstractFilter
 $_column
 
 $_resourceHelper
 
- Protected Attributes inherited from AbstractBlock
 $_authorization
 
- Protected Attributes inherited from AbstractBlock
 $_design
 
 $_session
 
 $_sidResolver
 
 $_nameInLayout
 
 $_layout
 
 $jsLayout = []
 
 $_request
 
 $_urlBuilder
 
 $_eventManager
 
 $_frontController
 
 $_assetRepo
 
 $_viewConfig
 
 $_cacheState
 
 $_logger
 
 $_escaper
 
 $filterManager
 
 $_localeDate
 
 $inlineTranslation
 
 $_isScopePrivate = false
 
 $_scopeConfig
 
 $_cache
 
- Protected Attributes inherited from DataObject
 $_data = []
 
- Static Protected Attributes inherited from DataObject
static $_underscoreCache = []
 

Detailed Description

Date grid column filter

Author
Magento Core Team core@.nosp@m.mage.nosp@m.ntoco.nosp@m.mmer.nosp@m.ce.co.nosp@m.m
Todo:
date format

Definition at line 15 of file Datetime.php.

Member Function Documentation

◆ _convertDate()

_convertDate (   $date)
protected

Convert given date to default (UTC) timezone

Parameters
string$date
Returns
\DateTime|null

Definition at line 64 of file Datetime.php.

65  {
66  if ($this->getColumn()->getFilterTime()) {
67  try {
68  $timezone = $this->getColumn()->getTimezone() !== false
69  ? $this->_localeDate->getConfigTimezone() : 'UTC';
70  $adminTimeZone = new \DateTimeZone($timezone);
71  $simpleRes = new \DateTime($date, $adminTimeZone);
72  $simpleRes->setTimezone(new \DateTimeZone('UTC'));
73  return $simpleRes;
74  } catch (\Exception $e) {
75  return null;
76  }
77  }
78  return parent::_convertDate($date);
79  }

◆ getEscapedValue()

getEscapedValue (   $index = null)

Return escaped value for calendar

Parameters
string | null$index
Returns
array|string|int|float|null

Definition at line 145 of file Datetime.php.

146  {
147  if ($this->getColumn()->getFilterTime()) {
148  $value = $this->getValue($index);
149  if ($value instanceof \DateTimeInterface) {
150  return $this->_localeDate->formatDateTime($value);
151  }
152 
153  if (is_string($value)) {
154  return $this->escapeHtml($value);
155  }
156 
157  return $value;
158  }
159 
160  return parent::getEscapedValue($index);
161  }
$value
Definition: gender.phtml:16
$index
Definition: list.phtml:44

◆ getHtml()

getHtml ( )

Render filter html

Returns
string

Implements FilterInterface.

Definition at line 86 of file Datetime.php.

87  {
88  $htmlId = $this->mathRandom->getUniqueHash($this->_getHtmlId());
89  $format = $this->_localeDate->getDateFormat(\IntlDateFormatter::SHORT);
90  $timeFormat = '';
91 
92  if ($this->getColumn()->getFilterTime()) {
93  $timeFormat = $this->_localeDate->getTimeFormat(
94  \IntlDateFormatter::SHORT
95  );
96  }
97 
98  $html =
99  '<div class="range" id="' . $htmlId . '_range"><div class="range-line date">' . '<input type="text" name="'
100  . $this->_getHtmlName() . '[from]" id="' . $htmlId . '_from"' . ' value="' . $this->getEscapedValue('from')
101  . '" class="input-text admin__control-text no-changes" placeholder="' . __(
102  'From'
103  ) . '" ' . $this->getUiId(
104  'filter',
105  $this->_getHtmlName(),
106  'from'
107  ) . '/>' . '</div>';
108  $html .= '<div class="range-line date">' . '<input type="text" name="' . $this->_getHtmlName() . '[to]" id="'
109  . $htmlId . '_to"' . ' value="' . $this->getEscapedValue(
110  'to'
111  ) . '" class="input-text admin__control-text no-changes" placeholder="' . __(
112  'To'
113  ) . '" ' . $this->getUiId(
114  'filter',
115  $this->_getHtmlName(),
116  'to'
117  ) . '/>' . '</div></div>';
118  $html .= '<input type="hidden" name="' . $this->_getHtmlName() . '[locale]"' . ' value="'
119  . $this->localeResolver->getLocale() . '"/>';
120  $html .= '<script>
121  require(["jquery", "mage/calendar"],function($){
122  $("#' . $htmlId . '_range").dateRange({
123  dateFormat: "' . $format . '",
124  timeFormat: "' . $timeFormat . '",
125  showsTime: ' . ($this->getColumn()->getFilterTime() ? 'true' : 'false') . ',
126  buttonText: "' . $this->escapeHtml(__('Date selector')) . '",
127  from: {
128  id: "' . $htmlId . '_from"
129  },
130  to: {
131  id: "' . $htmlId . '_to"
132  }
133  })
134  });
135  </script>';
136  return $html;
137  }
getUiId($arg1=null, $arg2=null, $arg3=null, $arg4=null, $arg5=null)
__()
Definition: __.php:13
$format
Definition: list.phtml:12

Field Documentation

◆ END_OF_DAY_IN_SECONDS

const END_OF_DAY_IN_SECONDS = 86399

full day is 86400, we need 23 hours:59 minutes:59 seconds = 86399

Definition at line 20 of file Datetime.php.


The documentation for this class was generated from the following file: