Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Attributes
Date Class Reference
Inheritance diagram for Date:
AbstractDataType AbstractComponent DataTypeInterface DataObject UiComponentInterface UiComponentInterface BlockInterface BlockInterface

Public Member Functions

 __construct (ContextInterface $context, TimezoneInterface $localeDate, ResolverInterface $localeResolver, array $components=[], array $data=[])
 
 prepare ()
 
 getLocale ()
 
 getComponentName ()
 
 convertDate ($date, $hour=0, $minute=0, $second=0, $setUtcTimeZone=true)
 
- Public Member Functions inherited from AbstractDataType
 validate ()
 
- Public Member Functions inherited from AbstractComponent
 __construct (ContextInterface $context, array $components=[], array $data=[])
 
 getContext ()
 
 getName ()
 
 prepare ()
 
 toHtml ()
 
 render ()
 
 addComponent ($name, UiComponentInterface $component)
 
 getComponent ($name)
 
 getChildComponents ()
 
 renderChildComponent ($name)
 
 getTemplate ()
 
 getConfiguration ()
 
 getJsConfig (UiComponentInterface $component)
 
 setData ($key, $value=null)
 
 getData ($key='', $index=null)
 
 prepareDataSource (array $dataSource)
 
 getDataSourceData ()
 
- 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)
 

Data Fields

const NAME = 'date'
 

Protected Attributes

 $locale
 
 $wrappedComponent
 
- Protected Attributes inherited from AbstractComponent
 $context
 
 $components
 
 $componentData = []
 
 $dataSources = []
 
- Protected Attributes inherited from DataObject
 $_data = []
 

Additional Inherited Members

- Protected Member Functions inherited from AbstractComponent
 prepareChildComponent (UiComponentInterface $component)
 
 initObservers (array & $data=[])
 
- Protected Member Functions inherited from DataObject
 _getData ($key)
 
 _underscore ($name)
 
- Static Protected Attributes inherited from DataObject
static $_underscoreCache = []
 

Detailed Description

Class Date

Definition at line 16 of file Date.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( ContextInterface  $context,
TimezoneInterface  $localeDate,
ResolverInterface  $localeResolver,
array  $components = [],
array  $data = [] 
)

Constructor

Parameters
ContextInterface$context
TimezoneInterface$localeDate
ResolverInterface$localeResolver
array$components
array$data

Definition at line 48 of file Date.php.

54  {
55  $this->locale = $localeResolver->getLocale();
56  $this->localeDate = $localeDate;
57  parent::__construct($context, $components, $data);
58  }

Member Function Documentation

◆ convertDate()

convertDate (   $date,
  $hour = 0,
  $minute = 0,
  $second = 0,
  $setUtcTimeZone = true 
)

Convert given date to default (UTC) timezone

Parameters
int$date
int$hour
int$minute
int$second
bool$setUtcTimeZone
Returns
\DateTime|null

Definition at line 111 of file Date.php.

112  {
113  try {
114  $dateObj = $this->localeDate->date(
115  new \DateTime(
116  $date,
117  new \DateTimeZone($this->localeDate->getConfigTimezone())
118  ),
119  $this->getLocale(),
120  true
121  );
122  $dateObj->setTime($hour, $minute, $second);
123  //convert store date to default date in UTC timezone without DST
124  if ($setUtcTimeZone) {
125  $dateObj->setTimezone(new \DateTimeZone('UTC'));
126  }
127  return $dateObj;
128  } catch (\Exception $e) {
129  return null;
130  }
131  }

◆ getComponentName()

getComponentName ( )

Get component name

Returns
string

Implements UiComponentInterface.

Definition at line 96 of file Date.php.

97  {
98  return static::NAME;
99  }

◆ getLocale()

getLocale ( )

Get locale

Returns
string

Definition at line 86 of file Date.php.

◆ prepare()

prepare ( )

Prepare component configuration

Returns
void

Implements UiComponentInterface.

Definition at line 65 of file Date.php.

66  {
67  $config = $this->getData('config');
68 
69  if (!isset($config['storeTimeZone'])) {
70  $storeTimeZone = $this->localeDate->getConfigTimezone();
71  $config['storeTimeZone'] = $storeTimeZone;
72  }
73  // Set date format pattern by current locale
74  $localeDateFormat = $this->localeDate->getDateFormat();
75  $config['options']['dateFormat'] = $localeDateFormat;
76  $config['options']['storeLocale'] = $this->locale;
77  $this->setData('config', $config);
78  parent::prepare();
79  }
$config
Definition: fraud_order.php:17

Field Documentation

◆ $locale

$locale
protected

Definition at line 25 of file Date.php.

◆ $wrappedComponent

$wrappedComponent
protected

Definition at line 32 of file Date.php.

◆ NAME

const NAME = 'date'

Definition at line 18 of file Date.php.


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