Skip to content

Document createFromTimestamp() for DateTime and DateTimeImmutable - #5103

Open
mathroc wants to merge 2 commits into
php:masterfrom
mathroc:datetime-from-timestamp
Open

Document createFromTimestamp() for DateTime and DateTimeImmutable#5103
mathroc wants to merge 2 commits into
php:masterfrom
mathroc:datetime-from-timestamp

Conversation

@mathroc

@mathroc mathroc commented Jan 14, 2026

Copy link
Copy Markdown

disclaimer: first time contributing here and edited from github web IDE. I didn't check if it's remotely close to be OK yet

@Girgias Girgias left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preliminary markup review.

Comment thread reference/datetime/datetimeimmutable/createfromtimestamp.xml Outdated
Comment thread reference/datetime/datetimeimmutable/createfromtimestamp.xml Outdated
Comment thread reference/datetime/datetimeimmutable/createfromtimestamp.xml
Comment thread reference/datetime/datetime/createfromtimestamp.xml Outdated
Comment thread reference/datetime/datetime/createfromtimestamp.xml Outdated
Comment thread reference/datetime/datetime/createfromtimestamp.xml Outdated
Co-authored-by: Gina Peter Banyard <girgias@php.net>
@Girgias
Girgias marked this pull request as ready for review February 6, 2026 14:11
@@ -0,0 +1,71 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="datetimeimmutble.createfromtimestamp" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<refentry xml:id="datetimeimmutble.createfromtimestamp" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refentry xml:id="datetimeimmutable.createfromtimestamp" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">

<programlisting role="php" annotations="non-interactive">
<![CDATA[
<?php
$dt = DateTime::createFromTimestamp( 1403261100 );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe it could be interesting to add an example with a float as a parameter ?

<programlisting role="php" annotations="non-interactive">
<![CDATA[
<?php
$dt = DateTimeImmutable::createFromTimestamp( 1403261100 );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

</simpara>
</refsect1>

<refsect1 role="examples">

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be great to add a section errors and seealso. The implementation throws DateRangeError for NaN or out-of-range float timestamps. Worth documenting it.

&reftitle.description;
<methodsynopsis role="DateTime">
<modifier>public</modifier> <modifier>static</modifier> <type>static</type><methodname>DateTime::createFromTimestamp</methodname>
<methodparam><type>int|float</type><parameter>timestamp</parameter></methodparam>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<methodparam><type>int|float</type><parameter>timestamp</parameter></methodparam>
<methodparam><type class="union"><type>int</type><type>float</type></type><parameter>timestamp</parameter></methodparam>

<refsect1 role="examples">
&reftitle.examples;
<example>
<title>Creating a date time object from a timestamp</title>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<title>Creating a date time object from a timestamp</title>
<title>Creating a <classname>DateTime</classname> object from a timestamp</title>

<programlisting role="php" annotations="non-interactive">
<![CDATA[
<?php
$dt = DateTime::createFromTimestamp( 1403261100 );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$dt = DateTime::createFromTimestamp( 1403261100 );
$dt = DateTime::createFromTimestamp(1403261100);

&reftitle.description;
<methodsynopsis role="DateTimeImmutable">
<modifier>public</modifier> <modifier>static</modifier> <type>static</type><methodname>DateTimeImmutable::createFromTimestamp</methodname>
<methodparam><type>int|float</type><parameter>timestamp</parameter></methodparam>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<methodparam><type>int|float</type><parameter>timestamp</parameter></methodparam>
<methodparam><type class="union"><type>int</type><type>float</type></type><parameter>timestamp</parameter></methodparam>

<refsect1 role="examples">
&reftitle.examples;
<example>
<title>Creating a date time object from a timestamp</title>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<title>Creating a date time object from a timestamp</title>
<title>Creating a <classname>DateTime</classname> object from a timestamp</title>

<programlisting role="php" annotations="non-interactive">
<![CDATA[
<?php
$dt = DateTimeImmutable::createFromTimestamp( 1403261100 );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$dt = DateTimeImmutable::createFromTimestamp( 1403261100 );
$dt = DateTimeImmutable::createFromTimestamp(1403261100);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants