Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/code/Magento/Newsletter/Model/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ public function setQueueStartAtByString($startAt)
if ($startAt === null || $startAt == '') {
$this->setQueueStartAt(null);
} else {
$this->setQueueStartAt($this->timezone->convertConfigTimeToUtc($startAt));
$startAt = $this->timezone->convertConfigTimeToUtcWithPattern($startAt, 'Y-m-d H:i:s', null);
$this->setQueueStartAt($startAt);
}
return $this;
}
Expand Down
107 changes: 94 additions & 13 deletions lib/internal/Magento/Framework/Stdlib/DateTime/Timezone.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,23 +85,31 @@ public function __construct(
}

/**
* {@inheritdoc}
* Return path to default timezone
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You shouldn't duplicate descriptions in the implementation. They are in the interface. Please return them to {@inheritdoc}

Copy link
Copy Markdown
Contributor Author

@bnymn bnymn Sep 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the explanation @slavvka . So should I just ignore these warnings then?
https://travis-ci.org/magento/magento2/jobs/429304963

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically you could ignore those since {@inheritdoc} may be used in such cases and there's a bug in our sniffer. But it would be good if you make changes according to this guide https://devdocs.magento.com/guides/v2.3/coding-standards/docblock-standard-general.html#inheritdoc. As you could see there should be enough to remove curly braces {}

*
* @return string
*/
public function getDefaultTimezonePath()
{
return $this->_defaultTimezonePath;
}

/**
* {@inheritdoc}
* Retrieve timezone code
*
* @return string
*/
public function getDefaultTimezone()
{
return 'UTC';
}

/**
* {@inheritdoc}
* Gets the scope config timezone
*
* @param string $scopeType
* @param string $scopeCode
* @return string
*/
public function getConfigTimezone($scopeType = null, $scopeCode = null)
{
Expand All @@ -113,7 +121,10 @@ public function getConfigTimezone($scopeType = null, $scopeCode = null)
}

/**
* {@inheritdoc}
* Retrieve ISO date format
*
* @param int $type
* @return string
*/
public function getDateFormat($type = \IntlDateFormatter::SHORT)
{
Expand All @@ -125,7 +136,9 @@ public function getDateFormat($type = \IntlDateFormatter::SHORT)
}

/**
* {@inheritdoc}
* Retrieve short date format with 4-digit year
*
* @return string
*/
public function getDateFormatWithLongYear()
{
Expand All @@ -137,7 +150,10 @@ public function getDateFormatWithLongYear()
}

/**
* {@inheritdoc}
* Retrieve ISO time format
*
* @param string $type
* @return string
*/
public function getTimeFormat($type = \IntlDateFormatter::SHORT)
{
Expand All @@ -149,15 +165,24 @@ public function getTimeFormat($type = \IntlDateFormatter::SHORT)
}

/**
* {@inheritdoc}
* Retrieve ISO datetime format
*
* @param string $type
* @return string
*/
public function getDateTimeFormat($type)
{
return $this->getDateFormat($type) . ' ' . $this->getTimeFormat($type);
}

/**
* {@inheritdoc}
* Create \DateTime object for current locale
*
* @param mixed $date
* @param string $locale
* @param bool $useTimezone
* @param bool $includeTime
* @return \DateTime
*/
public function date($date = null, $locale = null, $useTimezone = true, $includeTime = true)
{
Expand Down Expand Up @@ -191,7 +216,12 @@ public function date($date = null, $locale = null, $useTimezone = true, $include
}

/**
* {@inheritdoc}
* Create \DateTime object with date converted to scope timezone and scope Locale
*
* @param mixed $scope Information about scope
* @param string|integer|\DateTime|array|null $date date in UTC
* @param boolean $includeTime flag for including time to date
* @return \DateTime
*/
public function scopeDate($scope = null, $date = null, $includeTime = false)
{
Expand All @@ -204,7 +234,12 @@ public function scopeDate($scope = null, $date = null, $includeTime = false)
}

/**
* {@inheritdoc}
* Format date using current locale options and time zone.
*
* @param \DateTime|null $date
* @param int $format
* @param bool $showTime
* @return string
*/
public function formatDate($date = null, $format = \IntlDateFormatter::SHORT, $showTime = false)
{
Expand All @@ -218,7 +253,12 @@ public function formatDate($date = null, $format = \IntlDateFormatter::SHORT, $s
}

/**
* {@inheritdoc}
* Get scope timestamp
*
* Timestamp will be built with scope timezone settings
*
* @param mixed $scope
* @return int
*/
public function scopeTimeStamp($scope = null)
{
Expand All @@ -231,7 +271,12 @@ public function scopeTimeStamp($scope = null)
}

/**
* {@inheritdoc}
* Checks if current date of the given scope (in the scope timezone) is within the range
*
* @param int|string|\Magento\Framework\App\ScopeInterface $scope
* @param string|null $dateFrom
* @param string|null $dateTo
* @return bool
*/
public function isScopeDateInInterval($scope, $dateFrom = null, $dateTo = null)
{
Expand Down Expand Up @@ -300,20 +345,55 @@ public function formatDateTime(

/**
* Convert date from config timezone to Utc.
*
* If pass \DateTime object as argument be sure that timezone is the same with config timezone
*
* @param string|\DateTimeInterface $date
* @param string $format
* @throws LocalizedException
* @return string
* @deprecated
*/
public function convertConfigTimeToUtc($date, $format = 'Y-m-d H:i:s')
{
return $this->convertConfigTimeToUtcWithPattern($date, $format);
}

/**
* Convert date from config timezone to Utc.
*
* If pass \DateTime object as argument be sure that timezone is the same with config timezone
*
* @param string|\DateTimeInterface $date
* @param string $format
* @param string $pattern
* @throws LocalizedException
* @return string
* @deprecated
*/
public function convertConfigTimeToUtcWithPattern($date, $format = 'Y-m-d H:i:s', $pattern = null)
{
if (!($date instanceof \DateTimeInterface)) {
if ($date instanceof \DateTimeImmutable) {
$date = new \DateTime($date->format('Y-m-d H:i:s'), new \DateTimeZone($this->getConfigTimezone()));
} else {
$date = new \DateTime($date, new \DateTimeZone($this->getConfigTimezone()));
$locale = $this->_localeResolver->getLocale();
if ($locale === null) {
$pattern = 'Y-M-dd HH:mm:ss';
}
$formatter = new \IntlDateFormatter(
$locale,
\IntlDateFormatter::MEDIUM,
\IntlDateFormatter::MEDIUM,
$this->getConfigTimezone(),
null,
$pattern
);
$unixTime = $formatter->parse($date);
$dateTime = new DateTime($this);

$dateUniversal = $dateTime->gmtDate(null, $unixTime);
$date = new \DateTime($dateUniversal, new \DateTimeZone($this->getConfigTimezone()));
}
} else {
if ($date->getTimezone()->getName() !== $this->getConfigTimezone()) {
Expand All @@ -331,6 +411,7 @@ public function convertConfigTimeToUtc($date, $format = 'Y-m-d H:i:s')
return $date->format($format);
}


/**
* Retrieve date with time
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public function scopeDate($scope = null, $date = null, $includeTime = false);

/**
* Get scope timestamp
*
* Timestamp will be built with scope timezone settings
*
* @param mixed $scope
Expand Down Expand Up @@ -121,6 +122,7 @@ public function getConfigTimezone($scopeType = null, $scopeCode = null);
public function isScopeDateInInterval($scope, $dateFrom = null, $dateTo = null);

/**
*
* @param string|\DateTimeInterface $date
* @param int $dateType
* @param int $timeType
Expand All @@ -139,10 +141,29 @@ public function formatDateTime(
);

/**
* Convert date from config timezone to Utc.
*
* If pass \DateTime object as argument be sure that timezone is the same with config timezone
*
* @param string|\DateTimeInterface $date
* @param string $format
* @throws LocalizedException
* @return string
* @since 100.1.0
* @deprecated
*/
public function convertConfigTimeToUtc($date, $format = 'Y-m-d H:i:s');

/**
* Convert date from config timezone to Utc.
*
* If pass \DateTime object as argument be sure that timezone is the same with config timezone
*
* @param string|\DateTimeInterface $date
* @param string $format
* @param string $pattern
* @throws LocalizedException
* @return string
* @deprecated
*/
public function convertConfigTimeToUtcWithPattern($date, $format = 'Y-m-d H:i:s', $pattern = 'Y-m-d H:i:s');
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a public method into interface marked as API is backward incompatible and therefore is forbidden (please look BIC guide https://devdocs.magento.com/guides/v2.3/contributor-guide/backward-compatible-development/). Please reimplement it. You can use the possible approach how to do that in the mentioned guide.

}
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,15 @@ public function dateIncludeTimeDataProvider()
* @param string $expectedResult
* @dataProvider getConvertConfigTimeToUtcFixtures
*/
public function testConvertConfigTimeToUtc($date, $configuredTimezone, $expectedResult)
public function testConvertConfigTimeToUtc($date, $configuredTimezone, $configuredLocale, $expectedResult)
{
$this->localeResolver
->method('getLocale')
->willReturn($configuredLocale);

$this->scopeConfigWillReturnConfiguredTimezone($configuredTimezone);

$this->assertEquals($expectedResult, $this->getTimezone()->convertConfigTimeToUtc($date));
$this->assertEquals($expectedResult, $this->getTimezone()->convertConfigTimeToUtcWithPattern($date));
}

/**
Expand All @@ -141,16 +145,37 @@ public function getConvertConfigTimeToUtcFixtures()
'string' => [
'2016-10-10 10:00:00',
'UTC',
null,
'2016-10-10 10:00:00'
],
'string-en_US' => [
'Sep 29, 2018, 6:07:38 PM',
'UTC',
'en_US',
'2018-09-29 18:07:38'
],
'string-pt_BR' => [
'29 de set de 2018 18:07:38',
'UTC',
'pt_BR',
'2018-09-29 18:07:38'
],
'string-tr_TR' => [
'29 Eyl 2018 18:07:38',
'UTC',
'tr_TR',
'2018-09-29 18:07:38'
],
'datetime' => [
new \DateTime('2016-10-10 10:00:00', new \DateTimeZone('UTC')),
'UTC',
null,
'2016-10-10 10:00:00'
],
'datetimeimmutable' => [
new \DateTimeImmutable('2016-10-10 10:00:00', new \DateTimeZone('UTC')),
'UTC',
null,
'2016-10-10 10:00:00'
]
];
Expand Down