Skip to content

Commit

Permalink
ENGCOM-5018: Set timezone on DateTime object not in constructor magen…
Browse files Browse the repository at this point in the history
  • Loading branch information
VladimirZaets authored May 14, 2019
2 parents 66b05b3 + fa52657 commit ad2272d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
12 changes: 4 additions & 8 deletions lib/internal/Magento/Framework/Stdlib/DateTime/Timezone.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ public function date($date = null, $locale = null, $useTimezone = true, $include
public function scopeDate($scope = null, $date = null, $includeTime = false)
{
$timezone = $this->_scopeConfig->getValue($this->getDefaultTimezonePath(), $this->_scopeType, $scope);
$date = new \DateTime(is_numeric($date) ? '@' . $date : $date, new \DateTimeZone($timezone));
$date = new \DateTime(is_numeric($date) ? '@' . $date : $date);
$date->setTimezone(new \DateTimeZone($timezone));
if (!$includeTime) {
$date->setTime(0, 0, 0);
}
Expand Down Expand Up @@ -247,13 +248,8 @@ public function isScopeDateInInterval($scope, $dateFrom = null, $dateTo = null)
$toTimeStamp += 86400;
}

$result = false;
if (!$this->_dateTime->isEmptyDate($dateFrom) && $scopeTimeStamp < $fromTimeStamp) {
} elseif (!$this->_dateTime->isEmptyDate($dateTo) && $scopeTimeStamp > $toTimeStamp) {
} else {
$result = true;
}
return $result;
return !(!$this->_dateTime->isEmptyDate($dateFrom) && $scopeTimeStamp < $fromTimeStamp ||
!$this->_dateTime->isEmptyDate($dateTo) && $scopeTimeStamp > $toTimeStamp);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,4 +253,15 @@ private function scopeConfigWillReturnConfiguredTimezone($configuredTimezone)
{
$this->scopeConfig->method('getValue')->with('', '', null)->willReturn($configuredTimezone);
}

public function testCheckIfScopeDateSetsTimeZone()
{
$scopeDate = new \DateTime('now', new \DateTimeZone('America/Vancouver'));
$this->scopeConfig->method('getValue')->willReturn('America/Vancouver');

$this->assertEquals(
$scopeDate->getTimezone(),
$this->getTimezone()->scopeDate(0, $scopeDate->getTimestamp())->getTimezone()
);
}
}

0 comments on commit ad2272d

Please sign in to comment.