![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/mautic.corals.io/app/bundles/LeadBundle/Segment/Decorator/Date/ |
<?php namespace Mautic\LeadBundle\Segment\Decorator\Date; use Mautic\CoreBundle\Helper\CoreParametersHelper; use Mautic\CoreBundle\Helper\DateTimeHelper; class TimezoneResolver { public function __construct( private CoreParametersHelper $coreParametersHelper ) { } /** * @param bool $hasTimePart */ public function getDefaultDate($hasTimePart): DateTimeHelper { /** * $hasTimePart tells us if field in a database is date or datetime * All datetime fields are stored in UTC * Date field, however, is always stored in a local time (there is no time information, so it cannot be converted to UTC). * * We will generate default date according to this. We need midnight as a default date (for relative intervals like "today" or "-1 day" * 1) in UTC for datetime fields * 2) in the local timezone for date fields * * Later we use toLocalString() method - it gives us midnight in UTC for first condition and midnight in local timezone for second option. */ $timezone = $hasTimePart ? 'UTC' : $this->coreParametersHelper->get('default_timezone', 'UTC'); $date = new \DateTime('midnight today', new \DateTimeZone($timezone)); return new DateTimeHelper($date, null, $timezone); } }