示例#1
0
 /**
  * Renders grid column
  *
  * @param \Magento\Framework\Object $row
  * @return string
  */
 public function render(\Magento\Framework\Object $row)
 {
     //@todo: check this logic manually
     if ($data = $row->getData($this->getColumn()->getIndex())) {
         switch ($this->getColumn()->getPeriodType()) {
             case 'month':
                 $dateFormat = 'yyyy-MM';
                 break;
             case 'year':
                 $dateFormat = 'yyyy';
                 break;
             default:
                 $dateFormat = \Magento\Framework\Stdlib\DateTime::DATE_INTERNAL_FORMAT;
                 break;
         }
         $format = $this->_getFormat();
         try {
             $data = $this->getColumn()->getGmtoffset() ? \IntlDateFormatter::formatObject($this->_localeDate->date(new \DateTime($data)), $format) : \IntlDateFormatter::formatObject($this->_localeDate->date(new \DateTime($data), null, false), $format);
         } catch (\Exception $e) {
             $data = $this->getColumn()->getTimezone() ? \IntlDateFormatter::formatObject($this->_localeDate->date(new \DateTime($data)), $format) : \IntlDateFormatter::formatObject($this->_localeDate->date(new \DateTime($data), null, false), $format);
         }
         return $data;
     }
     return $this->getColumn()->getDefault();
 }
 /**
  * {@inheritdoc}
  */
 public function formatObject($object, $format = null, $locale = null)
 {
     if ($this->useIntlFormatObject) {
         return \IntlDateFormatter::formatObject($object, $format, $locale);
     }
     return $this->doFormatObject($object, $format, $locale);
 }
示例#3
0
 /**
  * Renders grid column
  *
  * @param   \Magento\Framework\Object $row
  * @return  string
  */
 public function render(\Magento\Framework\Object $row)
 {
     if ($data = $row->getData($this->getColumn()->getIndex())) {
         $format = $this->_getFormat();
         return \IntlDateFormatter::formatObject($this->_localeDate->date(new \DateTime($data)), $format);
     }
     return $this->getColumn()->getDefault();
 }
示例#4
0
 /**
  * @param string|null $index
  * @return string
  */
 public function getEscapedValue($index = null)
 {
     $value = $this->getValue($index);
     if ($value instanceof \DateTime) {
         return \IntlDateFormatter::formatObject($value, $this->_localeDate->getDateFormat(\IntlDateFormatter::SHORT));
     }
     return $value;
 }
示例#5
0
 /**
  * Format given time [+ date] in current locale without changing timezone
  *
  * @param string $time
  * @param string $date
  * @return string
  */
 public function formatDeliveryTime($time, $date = null)
 {
     if (!empty($date)) {
         $time = $date . ' ' . $time;
     }
     $format = $this->_localeDate->getTimeFormat(\IntlDateFormatter::SHORT);
     return \IntlDateFormatter::formatObject($this->_localeDate->date(new \DateTime($time)), $format);
 }
 /**
  * {@inheritdoc}
  */
 public function formatObject($object, $format = null, $locale = null)
 {
     $locale = (null === $locale) ? $this->getLocaleResolver()->getLocale() : $locale;
     if ($this->useIntlFormatObject) {
         return \IntlDateFormatter::formatObject($object, $format, $locale);
     }
     return $this->doFormatObject($object, $format, $locale);
 }
 /**
  * @param \IntlCalendar|\DateTime $object
  * @param string|int|array|null $format
  * @param string|null $locale
  * @param boolean $useIntlFormatObject
  * @dataProvider dataProviderFormatObject
  */
 public function testFormatObject($object, $format = null, $locale = null, $useIntlFormatObject = false)
 {
     $dateTimeFormatter = $this->objectManager->getObject('Magento\\Framework\\Stdlib\\DateTime\\DateTimeFormatter', ['useIntlFormatObject' => $useIntlFormatObject]);
     $reflection = new \ReflectionClass(get_class($dateTimeFormatter));
     $reflectionProperty = $reflection->getProperty('localeResolver');
     $reflectionProperty->setAccessible(true);
     $reflectionProperty->setValue($dateTimeFormatter, $this->localeResolverMock);
     $this->assertEquals(\IntlDateFormatter::formatObject($object, $format, null === $locale ? 'fr-FR' : $locale), $dateTimeFormatter->formatObject($object, $format, $locale));
 }
示例#8
0
 public function testRender()
 {
     $testCacheValue = '1433259723';
     $testDatetime = (new \DateTime(null, new \DateTimeZone('UTC')))->setTimestamp($testCacheValue);
     $formattedDate = \IntlDateFormatter::formatObject($testDatetime);
     $htmlId = 'test_HTML_id';
     $label = 'test_label';
     $cacheMock = $this->getMockBuilder('Magento\\Framework\\App\\CacheInterface')->disableOriginalConstructor()->setMethods(['load', 'getFrontend', 'remove', 'save', 'clean'])->getMock();
     $cacheMock->expects($this->any())->method('load')->willReturn($testCacheValue);
     $localeDateMock = $this->getMockBuilder('Magento\\Framework\\Stdlib\\DateTime\\TimezoneInterface')->disableOriginalConstructor()->getMock();
     $localeDateMock->expects($this->any())->method('date')->willReturn($testDatetime);
     $localeDateMock->expects($this->any())->method('getDateTimeFormat')->willReturn(null);
     $elementMock = $this->getMockBuilder('Magento\\Framework\\Data\\Form\\Element\\AbstractElement')->disableOriginalConstructor()->setMethods(['getHtmlId', 'getLabel'])->getMock();
     $elementMock->expects($this->any())->method('getHtmlId')->willReturn($htmlId);
     $elementMock->expects($this->any())->method('getLabel')->willReturn($label);
     $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $notification = $objectManager->getObject('Magento\\Config\\Block\\System\\Config\\Form\\Field\\Notification', ['cache' => $cacheMock, 'localeDate' => $localeDateMock]);
     $html = $notification->render($elementMock);
     $this->assertEquals('<tr id="row_' . $htmlId . '">' . '<td class="label">' . '<label for="' . $htmlId . '">' . $label . '</label>' . '</td>' . '<td class="value">' . $formattedDate . '</td>' . '<td class="scope-label"></td>' . '<td class=""></td>' . '</tr>', $html);
 }
示例#9
0
文件: Date.php 项目: nja78/magento2
 /**
  * Renders grid column
  *
  * @param \Magento\Framework\Object $row
  * @return string
  */
 public function render(\Magento\Framework\Object $row)
 {
     if ($data = $row->getData($this->getColumn()->getIndex())) {
         switch ($this->getColumn()->getPeriodType()) {
             case 'month':
                 $data = $data . '-01';
                 break;
             case 'year':
                 $data = $data . '-01-01';
                 break;
         }
         $format = $this->_getFormat();
         if ($this->getColumn()->getGmtoffset() || $this->getColumn()->getTimezone()) {
             $date = $this->_localeDate->date(new \DateTime($data));
         } else {
             $date = $this->_localeDate->date(new \DateTime($data), null, false);
         }
         return \IntlDateFormatter::formatObject($date, $format);
     }
     return $this->getColumn()->getDefault();
 }
示例#10
0
if ($_SESSION["pit_on"] == "True") {
    ?>
		<div class="last_regulation_view"><?php 
    echo gettext("Last regulation on");
    ?>
 <b><?php 
    echo IntlDateFormatter::formatObject($pit_time_stamp, array(IntlDateFormatter::SHORT, IntlDateFormatter::MEDIUM), $_SESSION["locale"]);
    ?>
</b></div><?php 
}
?>
	<div class="last_measure_view"><?php 
echo gettext("Last measurement on");
?>
 <b><?php 
echo IntlDateFormatter::formatObject($time_stamp, array(IntlDateFormatter::SHORT, IntlDateFormatter::MEDIUM), $_SESSION["locale"]);
?>
</b>
	<?php 
if ($_SESSION["showcpulast"] == "True") {
    echo "<br>";
    $cpuload = new CPULoad();
    $cpuload->get_load();
    $CPULOAD = round($cpuload->load["cpu"], 1);
    echo gettext("CPU utilization") . ": <b>" . $CPULOAD . "% / " . get_cputemp() . $temp_unit_short;
    "</b>";
}
?>
	</div>						 
	<br>
	<div class="clear"></div>
<?php

$obj = new DateTime('2013-08-20T12:34:56');
print IntlDateFormatter::formatObject($obj, 'eeee dd MMMM y', 'es_ES') . "\n";
print IntlDateFormatter::formatObject($obj, IntlDateFormatter::FULL, 'fr_FR') . "\n";
// First element is date format, second is time format
$formats = array(IntlDateFormatter::FULL, IntlDateFormatter::SHORT);
print IntlDateFormatter::formatObject($obj, $formats, 'de_DE') . "\n";
<?php

$bits = array();
$bits['Hour'] = array('a' => 'Ante/Post Meridiem designation', 'h' => 'Hour, 12-hour clock (1 - 12)', 'K' => 'Hour, 12-hour clock (0 - 11)', 'H' => 'Hour, 24-hour clock (0 - 23)', 'k' => 'Hour, 24-hour clock (1 - 24)');
$bits['Minute'] = array('m' => 'Minute (0 - 59)');
$bits['Second'] = array('s' => 'Second (0 - 59)', 'S' => 'Decisecond (0 - 9)', 'SS' => 'Centisecond (00 - 99)', 'SSS' => 'Millisecond (000 - 999)', 'A' => 'Milliseconds in day');
$bits['Day'] = array('d' => 'Day of month (1 - 31)', 'D' => 'Day of year (1 - 366)', 'EEEEE' => 'Day of week, short abbreviation', 'EEE' => 'Day of week, long abbreviation', 'EEEE' => 'Day of week, name', 'e' => 'Day of week, number (0 or 1 to 6 or 7, localized)', 'F' => 'Day of week in the month (e.g. 3 for "third wednesday")', 'g' => 'Modified Julian Day');
$bits['Week'] = array('w' => 'Week of Year, with localized week start (1 - 52)', 'W' => 'Week of Month (1 - 5)');
$bits['Month'] = array('M' => 'Month (1 - 12)', 'MMMMM' => 'Month, short abbreviation', 'MMM' => 'Month, long abbreviation', 'MMMM' => 'Month, name');
$bits['Year'] = array('y' => 'Year, 4-digit', 'yy' => 'Year, 2-digit');
$bits['Time Zone'] = array('z' => 'Time zone, including Summer Time, abbreviated', 'zzzz' => 'Time zone, including Summer Time, full name', 'Z' => 'Time zone, RFC-822 format', 'ZZZZ' => 'Time zone, as GMT offset', 'ZZZZZ' => 'Time zone, ISO-8601 format', 'v' => 'Time zone, not including Summer Time, abbreviated', 'vvvv' => 'Time zone, not including Summer Time, full name', 'VVVV' => 'Time zone, as location');
$bits['Other'] = array('Q' => 'Quarter, number', 'QQQ' => 'Quarter, number with prefix', 'QQQQ' => 'Quarter, as words', 'G' => 'Era (BC, AD)', "''" => 'Single quote');
/*
standalone
c for e
q for Q
L for M
*/
$when = new DateTime('2004-03-18T15:08:07 America/New_York');
print "|Type|Character|Description|Example\n";
foreach ($bits as $type => $stuff) {
    foreach ($stuff as $char => $desc) {
        $example = IntlDateFormatter::formatObject($when, $char, 'en_US');
        print "|{$type}|{$char}|{$desc}|{$example}\n";
    }
}
 /**
  * @param \IntlCalendar|\DateTime $object
  * @param string|int|array|null $format
  * @param string|null $locale
  * @dataProvider dataProviderFormatObject
  */
 public function testFormatObject($object, $format = null, $locale = null)
 {
     $this->assertEquals(\IntlDateFormatter::formatObject($object, $format, $locale), $this->dateTimeFormatter->formatObject($object, $format, $locale));
 }
示例#14
0
 /**
  * Add refresh statistics links
  *
  * @param string $flagCode
  * @param string $refreshCode
  * @return $this
  */
 protected function _showLastExecutionTime($flagCode, $refreshCode)
 {
     $flag = $this->_objectManager->create('Magento\\Reports\\Model\\Flag')->setReportFlagCode($flagCode)->loadSelf();
     $updatedAt = 'undefined';
     if ($flag->hasData()) {
         $updatedAt = \IntlDateFormatter::formatObject($this->_objectManager->get('Magento\\Framework\\Stdlib\\DateTime\\TimezoneInterface')->scopeDate(0, $flag->getLastUpdate(), true));
     }
     $refreshStatsLink = $this->getUrl('reports/report_statistics');
     $directRefreshLink = $this->getUrl('reports/report_statistics/refreshRecent', ['code' => $refreshCode]);
     $this->messageManager->addNotice(__('Last updated: %1. To refresh last day\'s <a href="%2">statistics</a>, ' . 'click <a href="%3">here</a>.', $updatedAt, $refreshStatsLink, $directRefreshLink));
     return $this;
 }
ini_set("intl.default_locale", "pt_PT");
ini_set("date.timezone", "Europe/Lisbon");
var_dump(IntlDateFormatter::formatObject());
var_dump(IntlDateFormatter::formatObject(1));
var_dump(IntlDateFormatter::formatObject(new stdclass()));
class A extends IntlCalendar
{
    function __construct()
    {
    }
}
var_dump(IntlDateFormatter::formatObject(new A()));
class B extends DateTime
{
    function __construct()
    {
    }
}
var_dump(IntlDateFormatter::formatObject(new B()));
$cal = IntlCalendar::createInstance();
var_dump(IntlDateFormatter::formatObject($cal, -2));
var_dump(IntlDateFormatter::formatObject($cal, array()));
var_dump(IntlDateFormatter::formatObject($cal, array(1, 2, 3)));
var_dump(IntlDateFormatter::formatObject($cal, array(array(), 1)));
var_dump(IntlDateFormatter::formatObject($cal, array(1, -2)));
var_dump(IntlDateFormatter::formatObject($cal, ""));
var_dump(IntlDateFormatter::formatObject($cal, "YYYY", array()));
?>
==DONE==

示例#16
0
 /**
  * @param AbstractElement $element
  * @return string
  * @codeCoverageIgnore
  */
 protected function _getElementHtml(AbstractElement $element)
 {
     $format = $this->_localeDate->getDateTimeFormat(\IntlDateFormatter::MEDIUM);
     return \IntlDateFormatter::formatObject($this->_localeDate->date(intval($element->getValue())), $format);
 }
示例#17
0
 /**
  * @param AbstractElement $element
  * @return string
  */
 protected function _getElementHtml(AbstractElement $element)
 {
     $element->setValue($this->_cache->load('admin_notifications_lastcheck'));
     $format = $this->_localeDate->getDateTimeFormat(\IntlDateFormatter::MEDIUM);
     return \IntlDateFormatter::formatObject($this->_localeDate->date(intval($element->getValue())), $format);
 }
示例#18
0
 /**
  * Prepare data for save
  *
  * @return $this
  * @throws LocalizedException
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function beforeSave()
 {
     // prevent overriding product data
     if (isset($this->_data['attribute_code']) && $this->reservedAttributeList->isReservedAttribute($this)) {
         throw new LocalizedException(__('The attribute code \'%1\' is reserved by system. Please try another attribute code', $this->_data['attribute_code']));
     }
     /**
      * Check for maximum attribute_code length
      */
     if (isset($this->_data['attribute_code']) && !\Zend_Validate::is($this->_data['attribute_code'], 'StringLength', ['max' => self::ATTRIBUTE_CODE_MAX_LENGTH])) {
         throw new LocalizedException(__('An attribute code must be fewer than %1 characters.', self::ATTRIBUTE_CODE_MAX_LENGTH));
     }
     $defaultValue = $this->getDefaultValue();
     $hasDefaultValue = (string) $defaultValue != '';
     if ($this->getBackendType() == 'decimal' && $hasDefaultValue) {
         $numberFormatter = new \NumberFormatter($this->_localeResolver->getLocale(), \NumberFormatter::DECIMAL);
         $defaultValue = $numberFormatter->parse($defaultValue);
         if ($defaultValue === false) {
             throw new LocalizedException(__('Invalid default decimal value'));
         }
         $this->setDefaultValue($defaultValue);
     }
     if ($this->getBackendType() == 'datetime') {
         if (!$this->getBackendModel()) {
             $this->setBackendModel('Magento\\Eav\\Model\\Entity\\Attribute\\Backend\\Datetime');
         }
         if (!$this->getFrontendModel()) {
             $this->setFrontendModel('Magento\\Eav\\Model\\Entity\\Attribute\\Frontend\\Datetime');
         }
         // save default date value as timestamp
         if ($hasDefaultValue) {
             $format = $this->_localeDate->getDateFormat(\IntlDateFormatter::SHORT);
             try {
                 $defaultValue = \IntlDateFormatter::formatObject(new \DateTime($defaultValue), $format);
                 $this->setDefaultValue($defaultValue);
             } catch (\Exception $e) {
                 throw new LocalizedException(__('Invalid default date'));
             }
         }
     }
     if ($this->getBackendType() == 'gallery') {
         if (!$this->getBackendModel()) {
             $this->setBackendModel('Magento\\Eav\\Model\\Entity\\Attribute\\Backend\\DefaultBackend');
         }
     }
     return parent::beforeSave();
 }
<?php

ini_set("intl.error_level", E_WARNING);
ini_set("intl.default_locale", "pt_PT");
ini_set("date.timezone", "Europe/Lisbon");
$dt = new DateTime('2012-01-01 00:00:00');
//Europe/Lisbon
echo IntlDateFormatter::formatObject($dt), "\n";
echo IntlDateFormatter::formatObject($dt, IntlDateFormatter::FULL), "\n";
echo IntlDateFormatter::formatObject($dt, null, "en-US"), "\n";
echo IntlDateFormatter::formatObject($dt, array(IntlDateFormatter::SHORT, IntlDateFormatter::FULL), "en-US"), "\n";
echo IntlDateFormatter::formatObject($dt, 'E y-MM-d HH,mm,ss.SSS v', "en-US"), "\n";
$dt = new DateTime('2012-01-01 05:00:00+03:00');
echo IntlDateFormatter::formatObject($dt, IntlDateFormatter::FULL), "\n";
?>
==DONE==

<?php

ini_set("intl.error_level", E_WARNING);
ini_set("intl.default_locale", "pt_PT");
ini_set("date.timezone", "Europe/Lisbon");
$cal = IntlCalendar::fromDateTime('2012-01-01 00:00:00');
//Europe/Lisbon
echo IntlDateFormatter::formatObject($cal), "\n";
echo IntlDateFormatter::formatObject($cal, IntlDateFormatter::FULL), "\n";
echo IntlDateFormatter::formatObject($cal, null, "en-US"), "\n";
echo IntlDateFormatter::formatObject($cal, array(IntlDateFormatter::SHORT, IntlDateFormatter::FULL), "en-US"), "\n";
echo IntlDateFormatter::formatObject($cal, 'E y-MM-d HH,mm,ss.SSS v', "en-US"), "\n";
$cal = IntlCalendar::fromDateTime('2012-01-01 05:00:00+03:00');
echo datefmt_format_object($cal, IntlDateFormatter::FULL), "\n";
$cal = IntlCalendar::createInstance(null, 'en-US@calendar=islamic-civil');
$cal->setTime(strtotime('2012-01-01 00:00:00') * 1000.0);
echo IntlDateFormatter::formatObject($cal), "\n";
echo IntlDateFormatter::formatObject($cal, IntlDateFormatter::FULL, "en-US"), "\n";
?>
==DONE==
示例#21
0
 /**
  * Get json options for button (restore-to-previous)
  *
  * @return string|bool
  */
 protected function _getDataRevertToPrevious()
 {
     $sourceChange = $this->_changeFactory->create();
     $sourceChange->loadByThemeId($this->_themeContext->getEditableTheme()->getId());
     $dateMessage = \IntlDateFormatter::formatObject($this->_localeDate->date($sourceChange->getChangeTime()));
     $message = __('Do you want to restore the version saved at %1?', $dateMessage);
     $data = ['vde-edit-button' => ['event' => 'revert-to-last', 'target' => 'body', 'eventData' => ['url' => $this->getRevertUrl('last_saved'), 'confirm' => ['title' => __('Restore Theme Version'), 'message' => $message]]]];
     return $this->escapeHtml(json_encode($data));
 }