getToken()) { return; } /* @var $user User */ $user = $tokenStorage->getToken()->getUser(); $timezone = date_default_timezone_get(); if ($user instanceof User && null !== $user->getPreferenceValue('timezone')) { $timezone = $user->getPreferenceValue('timezone'); } $this->timezone = new \DateTimeZone($timezone); } /** * @return \DateTimeZone */ public function getTimezone() { return $this->timezone; } /** * @return \DateTime */ public function getStartOfMonth() { $date = $this->createDateTime('first day of this month'); $date->setTime(0, 0, 0); return $date; } /** * @return \DateTime */ public function getEndOfMonth() { $date = $this->createDateTime('last day of this month'); $date->setTime(23, 59, 59); return $date; } /** * @param string $datetime * @return \DateTime */ public function createDateTime(string $datetime = 'now') { $date = new \DateTime($datetime, $this->timezone); return $date; } }