From 9bd321de567074972ce6f21cb3a92b98739e30e1 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Tue, 9 Apr 2024 17:59:15 +0200 Subject: [PATCH] [Clock] Document createFromTimestamp() method --- components/clock.rst | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/components/clock.rst b/components/clock.rst index 45ec484eef5..933f7310d75 100644 --- a/components/clock.rst +++ b/components/clock.rst @@ -229,6 +229,21 @@ The constructor also allows setting a timezone or custom referenced date:: $referenceDate = new \DateTimeImmutable(); $relativeDate = new DatePoint('+1month', reference: $referenceDate); +The ``DatePoint`` class also provides a named constructor to create dates from +timestamps:: + + $dateOfFirstCommitOfSymfonyProject = DatePoint::createFromTimestamp(1129645656); + // equivalent to: + // $dateOfFirstCommitOfSymfonyProject = (new \DateTimeImmutable())->setTimestamp(1129645656); + + // negative timestamps (for dates before January 1, 1970) and fractional timestamps + // (for high precision sub-second datetimes) are also supported + $dateOfFirstMoonLanding = DatePoint::createFromTimestamp(-14182940); + +.. versionadded:: 7.1 + + The ``createFromTimestamp()`` method was introduced in Symfony 7.1. + .. note:: In addition ``DatePoint`` offers stricter return types and provides consistent