Skip to content

Commit d8c8473

Browse files
committed
use UTC to convert date in validator (#22833: Short-term admin accounts)
1 parent f185806 commit d8c8473

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

app/code/Magento/Security/Model/UserExpiration/Validator.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@
1616
*/
1717
class Validator extends AbstractValidator
1818
{
19-
/**@var \Magento\Framework\Stdlib\DateTime\DateTime */
20-
private $dateTime;
19+
20+
/**@var \Magento\Framework\Stdlib\DateTime\TimezoneInterface */
21+
private $timezone;
2122

2223
/**
2324
* Validator constructor.
2425
*
25-
* @param \Magento\Framework\Stdlib\DateTime\DateTime $dateTime
26+
* @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $timezone
2627
*/
2728
public function __construct(
28-
\Magento\Framework\Stdlib\DateTime\DateTime $dateTime
29+
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $timezone
2930
) {
30-
31-
$this->dateTime = $dateTime;
31+
$this->timezone = $timezone;
3232
}
3333

3434
/**
@@ -45,8 +45,9 @@ public function isValid($value)
4545
$expiresAt = $value;
4646
$label = 'Expiration date';
4747
if (\Zend_Validate::is($expiresAt, 'NotEmpty')) {
48-
$currentTime = $this->dateTime->gmtTimestamp();
49-
$expiresAt = $this->dateTime->gmtTimestamp($value);
48+
$currentTime = $this->timezone->date()->getTimestamp();
49+
$utcExpiresAt = $this->timezone->convertConfigTimeToUtc($expiresAt);
50+
$expiresAt = $this->timezone->date($utcExpiresAt)->getTimestamp();
5051
if ($expiresAt < $currentTime) {
5152
$messages['expires_at'] = __('"%1" must be later than the current date.', $label);
5253
}

0 commit comments

Comments
 (0)