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

M2 Respect configuration time format in timeline (8809) #60

Open
wants to merge 3 commits into
base: mautic-2-16-2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/bundles/CoreBundle/Config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@
'%mautic.date_format_dateonly%',
'%mautic.date_format_timeonly%',
'translator',
'mautic.helper.core_parameters',
],
'alias' => 'date',
],
Expand Down
16 changes: 12 additions & 4 deletions app/bundles/CoreBundle/Templating/Helper/DateHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Mautic\CoreBundle\Templating\Helper;

use Mautic\CoreBundle\Helper\CoreParametersHelper;
use Mautic\CoreBundle\Helper\DateTimeHelper;
use Symfony\Component\Templating\Helper\Helper;
use Symfony\Component\Translation\TranslatorInterface;
Expand All @@ -32,6 +33,11 @@ class DateHelper extends Helper
*/
protected $translator;

/**
* @var CoreParametersHelper
*/
private $coreParametersHelper;

/**
* DateHelper constructor.
*
Expand All @@ -46,7 +52,8 @@ public function __construct(
$dateShortFormat,
$dateOnlyFormat,
$timeOnlyFormat,
TranslatorInterface $translator
TranslatorInterface $translator,
CoreParametersHelper $coreParametersHelper
) {
$this->formats = [
'datetime' => $dateFullFormat,
Expand All @@ -55,8 +62,9 @@ public function __construct(
'time' => $timeOnlyFormat,
];

$this->helper = new DateTimeHelper(null, null, 'local');
$this->translator = $translator;
$this->helper = new DateTimeHelper(null, null, 'local');
$this->translator = $translator;
$this->coreParametersHelper = $coreParametersHelper;
}

/**
Expand Down Expand Up @@ -176,7 +184,7 @@ public function toText($datetime, $timezone = 'local', $fromFormat = 'Y-m-d H:i:
$dt = $this->helper->getLocalDateTime();

if ($textDate) {
return $this->translator->trans('mautic.core.date.'.$textDate, ['%time%' => $dt->format('g:i a')]);
return $this->translator->trans('mautic.core.date.'.$textDate, ['%time%' => $dt->format($this->coreParametersHelper->getParameter('date_format_timeonly'))]);
} else {
$interval = $this->helper->getDiff('now', null, true);

Expand Down