Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix timezone issue segment rebuild #8652

Closed
8 changes: 4 additions & 4 deletions app/bundles/CoreBundle/Helper/DateTimeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ public function __construct($string = '', $fromFormat = 'Y-m-d H:i:s', $timezone
*/
public function setDateTime($datetime = '', $fromFormat = 'Y-m-d H:i:s', $timezone = 'local')
{
$localTimezone = date_default_timezone_get();
$localTimezone = ArrayHelper::getValue('default_timezone', (new ParamsLoaderHelper())->getParameters(), date_default_timezone_get());

if ('local' == $timezone) {
$timezone = $localTimezone;
} elseif (empty($timezone)) {
Expand All @@ -71,9 +72,8 @@ public function setDateTime($datetime = '', $fromFormat = 'Y-m-d H:i:s', $timezo

$this->format = (empty($fromFormat)) ? 'Y-m-d H:i:s' : $fromFormat;
$this->timezone = $timezone;

$this->utc = new \DateTimeZone('UTC');
$this->local = new \DateTimeZone($localTimezone);
$this->utc = new \DateTimeZone('UTC');
$this->local = new \DateTimeZone($localTimezone);

if ($datetime instanceof \DateTimeInterface) {
$this->datetime = $datetime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ public function getParameterValue(ContactSegmentFilterCrate $contactSegmentFilte

$operator = $this->getOperator($contactSegmentFilterCrate);
$format = 'Y-m-d';

// set now datetime for relative dates like -8 hours, -24 minutes with gt/lt types of operator
if ($contactSegmentFilterCrate->hasTimeParts() && in_array($contactSegmentFilterCrate->getOperator(), ['!gt', 'gt', 'gte', '!lt', 'lt', 'lte'])) {
$format = 'Y-m-d H:i:s';
}

if ('like' === $operator || 'notLike' === $operator) {
$format .= '%';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,13 @@ public function getDefaultDate($hasTimePart)
*/
$timezone = $hasTimePart ? 'UTC' : $this->coreParametersHelper->get('default_timezone', 'UTC');

$date = new \DateTime('midnight today', new \DateTimeZone($timezone));
$time = 'midnight today';

if ($hasTimePart) {
$time = 'now';
}

$date = new \DateTime($time, new \DateTimeZone($timezone));

return new DateTimeHelper($date, null, $timezone);
}
Expand Down