Skip to content

Timezone scopeDate method does not respect interface #23359

@sta1r

Description

@sta1r

Preconditions (*)

  1. 2.3-develop

Steps to reproduce (*)

  1. Start with a class similar to this:
<?php

class MyDate
{
    /**
     * @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface
     */
    private $timeZone;

    /**
     * @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $timezone
     */
    public function __construct(
        \Magento\Framework\Stdlib\DateTime\TimezoneInterface $timezone
    ) {
        $this->timeZone = $timezone;

        $scopedDate = $this->timeZone->scopeDate(1, new \DateTime, true);
    }
}
  1. Run the code

Expected result (*)

  1. scopeDate() returns a DateTime scoped to the store 1 locale.
  2. The method should work according to signature in the interface - support all types

Actual result (*)

  1. PHP Fatal error is thrown
PHP Fatal error:  Uncaught TypeError: DateTime::__construct() expects parameter 1 to be string, object given

The scopeDate() method is not implementing its interface (or at least the docBlock of the interface, which indicates this method can take a DateTime as $date).

Metadata

Metadata

Assignees

Labels

Component: Framework/DataFixed in 2.3.xThe issue has been fixed in 2.3 release lineIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentReproduced on 2.3.xThe issue has been reproduced on latest 2.3 release

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions