You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Issue #103 removed a test that would prove this (failing) test with an (almost) identical DateTime (compared to time()) for the |ago filter:
public function testFormatDiffDefaultToIsNull()
{
$from = new \DatetimeImmutable(date('Y-m-d H:i:s', time()));
$to = new \DateTime(null);
$this->assertEquals('diff.empty', $this->formatter->formatDiff($from, $to));
// actually returns 'diff.in.year' - or 'in -1 years' for English translation
}
In a live code scenario it would happen like this in a twig template (here, profile->updatedAt is a simple DateTime, with seconds resolution):
{# profile.updatedAt is a simple DateTime #}
<p>Updated: {{ profile.updatedAt|ago() }}</p>
But, the ago() uses the profile.updatedAt as the first parameter. and defaults to NULL as the second, from the twig filter TimeExtension::diff() (calling TimeHelper::diff()).
TimeHelper::diff(), via getDatetimeObject(), takes the null and makes it a DateTime(), defaulting to 'now' (with microseconds since PHP7.2):
return new DateTime(null);
Hence, the test above, which if you edit a profile and immediately show the updatedAt|ago() in a twig template can show 'in -1 Year' as the result.
If the default, in getDatetimeObject() was return new DateTime(null ?? '@'.time()); solves the issue, but setting it to DateTime('now') would still fail because of the tiny difference in microseconds.
The text was updated successfully, but these errors were encountered:
Issue #103 removed a test that would prove this (failing) test with an (almost) identical DateTime (compared to
time()
) for the|ago
filter:In a live code scenario it would happen like this in a twig template (here, profile->updatedAt is a simple DateTime, with seconds resolution):
But, the
ago()
uses theprofile.updatedAt
as the first parameter. and defaults to NULL as the second, from the twig filter TimeExtension::diff() (calling TimeHelper::diff()).TimeHelper::diff()
, viagetDatetimeObject()
, takes the null and makes it a DateTime(), defaulting to 'now' (with microseconds since PHP7.2):Hence, the test above, which if you edit a profile and immediately show the
updatedAt|ago()
in a twig template can show 'in -1 Year' as the result.If the default, in
getDatetimeObject()
wasreturn new DateTime(null ?? '@'.time());
solves the issue, but setting it toDateTime('now')
would still fail because of the tiny difference in microseconds.The text was updated successfully, but these errors were encountered: