1

I'm attempting to debug a Timezone issue in a custom Magento module. One of the tests I would like to try is to ADD/REMOVE 1hr from whatever is output from this line of code.

I suspect ADDING 1hr could be as simple as implementing a "+1" somehow. And perhaps REMOVING 1hr might involve going back 1 Day and forward 23 hours. But honestly, I don't know what to start with this.

Line

$estimatedDeliveryDate = $this->localeDate->date()->setTime(0,0,0);

Context

class Estimator
{
    private $localeDate;

    public function __construct(
        \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
    ) {
        $this->localeDate = $localeDate;
    }

    public function addEstimatedDeliveryDate(&$items)
    {
        $now = $this->localeDate->date();
        $todayDate = $this->localeDate->date();

         foreach ($items as &$item) {
            $estimatedDeliveryDate = $this->localeDate->date()->setTime(0,0,0);

...
  • this setTime(Hours,Minutes,Seconds); , what do you want to do? – fmsthird Mar 29 at 16:52
  • With Daylight Savings on Sunday, my Delivery Date selector seems to break when trying to choose a date during that period of time. It appears the code was never written to take Daylight into account. So, to test and debug I wanted to see what would happen if I adjusted the code +/- 1hr to see what effect that would have. – Craig Mar 29 at 16:59
  • setTime(Hours,Minutes,Seconds); might work for +1 but not -1. – Craig Mar 29 at 17:00
  • since it is for testing purpose only, you can try like this $estimatedDeliveryDate = $this->localeDate->date('2019-03-30')->setTime(0,0,0)->format('d-m-Y H:i:s'); – fmsthird Mar 29 at 17:12
  • 1
    Gotcha. I'll try that out in a bit, cheers – Craig Mar 29 at 17:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.