I have a bug on one of my feature with timezone, let me explain. The goal of this feature is to copy user events of a week to the next week.
I have a UserEvent
model with this properties
/**
* @ORM\Entity(repositoryClass="AppBundle\Repository\UserEventRepository")
*/
class UserEvent
{
/**
* @ORM\Id()
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\Column(type="datetime")
*/
private $start;
/**
* @ORM\Column(type="datetime")
*/
private $end;
/**
* @ORM\ManyToOne(targetEntity="UserEventType")
* @ORM\JoinColumn(nullable=false)
*/
private $type;
/**
* @ORM\ManyToOne(targetEntity="User", inversedBy="userEvents")
* @ORM\JoinColumn(nullable=false)
*/
private $user;
/* GETTERS AND SETTERS */
}
The datetime are stored in datebase in UTC
timezone, and at the moment the client using the application is in the Europe/Paris
timezone.
This is the logic to copy events to the next week
$newEvents = [];
foreach ($eventsToCopy as $event) {
$newEvent = clone $event;
$newEvent->getStart()->modify('+1 week');
$newEvent->getEnd()->modify('+1 week');
$newEvents[] = $newEvent;
}
The weekend are exlude from the week The problem appear on this weeks
WEEK A: 2017-10-23 to 2017-10-27
WEEK B: 2017-10-30 to 2017-11-03
There is a time change schedules between week A and week B therefore the planified hours on the second week are shifted on hour forward.
I can't do a high level change to handling DateTime and timezone, I can only modify this code (legacy application)
I'm not very confortable with timezone, maybe I'm missing something obvious.
Please give me your magic guideline to fix this case ! :)