mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-15 08:28:54 +00:00
Fixed bug #74054: New DateInterval properties based on
This commit is contained in:
parent
e8fb9384ca
commit
4586854a24
4 changed files with 226 additions and 16 deletions
|
@ -573,6 +573,8 @@ is highly discouraged.</simpara></warning>
|
|||
|
||||
<!ENTITY example.outputs.81 '<para xmlns="http://docbook.org/ns/docbook">Output of the above example in PHP 8.1:</para>'>
|
||||
|
||||
<!ENTITY example.outputs.82 '<para xmlns="http://docbook.org/ns/docbook">Output of the above example in PHP 8.2:</para>'>
|
||||
|
||||
<!ENTITY example.outputs.32bit '<para xmlns="http://docbook.org/ns/docbook">Output of the above example on 32 bit machines:</para>'>
|
||||
|
||||
<!ENTITY example.outputs.64bit '<para xmlns="http://docbook.org/ns/docbook">Output of the above example on 64 bit machines:</para>'>
|
||||
|
|
|
@ -16,7 +16,8 @@
|
|||
<para>
|
||||
A date interval stores either a fixed amount of time (in years, months,
|
||||
days, hours etc) or a relative time string in the format that
|
||||
<classname>DateTime</classname>'s constructor supports.
|
||||
<classname>DateTimeImmutable</classname>'s and
|
||||
<classname>DateTime</classname>'s constructors support.
|
||||
</para>
|
||||
<para>
|
||||
More specifically, the information in an object of the
|
||||
|
@ -26,7 +27,7 @@
|
|||
<para>
|
||||
A common way to create a <classname>DateInterval</classname> object
|
||||
is by calculating the difference between two date/time objects through
|
||||
<function>DateTimeInterface::diff</function>.
|
||||
<methodname>DateTimeInterface::diff</methodname>.
|
||||
</para>
|
||||
<para>
|
||||
Since there is no well defined way to compare date intervals,
|
||||
|
@ -97,6 +98,16 @@
|
|||
<type>mixed</type>
|
||||
<varname linkend="dateinterval.props.days">days</varname>
|
||||
</fieldsynopsis>
|
||||
<fieldsynopsis>
|
||||
<modifier>public</modifier>
|
||||
<type>bool</type>
|
||||
<varname linkend="dateinterval.props.from-string">from_string</varname>
|
||||
</fieldsynopsis>
|
||||
<fieldsynopsis>
|
||||
<modifier>public</modifier>
|
||||
<type>string</type>
|
||||
<varname linkend="dateinterval.props.date-string">date_string</varname>
|
||||
</fieldsynopsis>
|
||||
|
||||
<classsynopsisinfo role="comment">&Methods;</classsynopsisinfo>
|
||||
<xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook) xpointer(id('class.dateinterval')/db:refentry/db:refsect1[@role='description']/descendant::db:constructorsynopsis[not(@role='procedural')])">
|
||||
|
@ -185,12 +196,36 @@
|
|||
<listitem>
|
||||
<para>
|
||||
If the DateInterval object was created by
|
||||
<function>DateTime::diff</function>, then this is the total number of
|
||||
days between the start and end dates. Otherwise,
|
||||
<methodname>DateTimeImmutable::diff</methodname> or
|
||||
<methodname>DateTime::diff</methodname>, then this is the
|
||||
total number of days between the start and end dates. Otherwise,
|
||||
<varname>days</varname> will be &false;.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
<varlistentry xml:id="dateinterval.props.from-string">
|
||||
<term><varname>from_string</varname></term>
|
||||
<listitem>
|
||||
<para>
|
||||
If the DateInterval object was created by
|
||||
<methodname>DateInterval::createFromDateString</methodname>, then
|
||||
this property's value will be &true;, and the
|
||||
<varname>date_string</varname> property will be populated. Otherwise,
|
||||
the value will be &false;, and the <varname>y</varname> to
|
||||
<varname>f</varname>, <varname>invert</varname>, and
|
||||
<varname>days</varname> properties will be populated.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
<varlistentry xml:id="dateinterval.props.date-string">
|
||||
<term><varname>date_string</varname></term>
|
||||
<listitem>
|
||||
<para>
|
||||
The string used as argument to
|
||||
<methodname>DateInterval::createFromDateString</methodname>.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
</section>
|
||||
|
||||
|
@ -206,13 +241,22 @@
|
|||
</row>
|
||||
</thead>
|
||||
<tbody>
|
||||
<row>
|
||||
<entry>7.4.0</entry>
|
||||
<entry>
|
||||
<classname>DateInterval</classname> instances are incomparable now;
|
||||
previously, all <classname>DateInterval</classname> instances were considered equal.
|
||||
</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>8.2.0</entry>
|
||||
<entry>
|
||||
The <varname>from_string</varname> and <varname>date_string</varname>
|
||||
properties were added for <classname>DateInterval</classname>
|
||||
instances that were created using the
|
||||
<methodname>DateInterval::createFromDateString</methodname> method.
|
||||
</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>7.4.0</entry>
|
||||
<entry>
|
||||
<classname>DateInterval</classname> instances are incomparable now;
|
||||
previously, all <classname>DateInterval</classname> instances were considered equal.
|
||||
</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>7.1.0</entry>
|
||||
<entry>The <varname>f</varname> property was added.</entry>
|
||||
|
|
|
@ -137,6 +137,14 @@
|
|||
</row>
|
||||
</thead>
|
||||
<tbody>
|
||||
<row>
|
||||
<entry>8.2.0</entry>
|
||||
<entry>
|
||||
Only the <literal>y</literal> to <literal>f</literal>,
|
||||
<literal>invert</literal>, and <literal>days</literal> will be visible,
|
||||
including a new <literal>from_string</literal> boolean property.
|
||||
</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>8.0.0</entry>
|
||||
<entry>
|
||||
|
@ -163,6 +171,33 @@ var_dump($interval);
|
|||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
&example.outputs.82;
|
||||
<screen role="php">
|
||||
<![CDATA[
|
||||
object(DateInterval)#1 (10) {
|
||||
["y"]=>
|
||||
int(0)
|
||||
["m"]=>
|
||||
int(0)
|
||||
["d"]=>
|
||||
int(9)
|
||||
["h"]=>
|
||||
int(0)
|
||||
["i"]=>
|
||||
int(0)
|
||||
["s"]=>
|
||||
int(0)
|
||||
["f"]=>
|
||||
float(0)
|
||||
["invert"]=>
|
||||
int(0)
|
||||
["days"]=>
|
||||
bool(false)
|
||||
["from_string"]=>
|
||||
bool(false)
|
||||
}
|
||||
]]>
|
||||
</screen>
|
||||
&example.outputs.8;
|
||||
<screen role="php">
|
||||
<![CDATA[
|
||||
|
|
|
@ -26,11 +26,11 @@
|
|||
<term><parameter>datetime</parameter></term>
|
||||
<listitem>
|
||||
<para>
|
||||
A date with relative parts. Specifically, the
|
||||
<link linkend="datetime.formats.relative">relative formats</link>
|
||||
supported by the parser used for <function>strtotime</function> and
|
||||
<classname>DateTime</classname> will be used to construct the
|
||||
DateInterval.
|
||||
A date with relative parts. Specifically, the <link
|
||||
linkend="datetime.formats.relative">relative formats</link> supported
|
||||
by the parser used for <classname>DateTimeImmutable</classname>,
|
||||
<classname>DateTime</classname>, and <function>strtotime</function>
|
||||
will be used to construct the DateInterval.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
@ -45,6 +45,30 @@
|
|||
</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1 role="changelog">
|
||||
&reftitle.changelog;
|
||||
<informaltable>
|
||||
<tgroup cols="2">
|
||||
<thead>
|
||||
<row>
|
||||
<entry>&Version;</entry>
|
||||
<entry>&Description;</entry>
|
||||
</row>
|
||||
</thead>
|
||||
<tbody>
|
||||
<row>
|
||||
<entry>8.2.0</entry>
|
||||
<entry>
|
||||
Only the <literal>from_string</literal> and
|
||||
<literal>date_string</literal> properties will be visible when a
|
||||
<classname>DateInterval</classname> is created with this method.
|
||||
</entry>
|
||||
</row>
|
||||
</tbody>
|
||||
</tgroup>
|
||||
</informaltable>
|
||||
</refsect1>
|
||||
|
||||
<refsect1 role="examples">
|
||||
&reftitle.examples;
|
||||
<para>
|
||||
|
@ -79,6 +103,111 @@ $i = DateInterval::createFromDateString('3600 seconds');
|
|||
</programlisting>
|
||||
</example>
|
||||
</para>
|
||||
<para>
|
||||
<example>
|
||||
<title>Parsing special relative date intervals</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$i = DateInterval::createFromDateString('last day of next month');
|
||||
var_dump($i);
|
||||
|
||||
$i = DateInterval::createFromDateString('last weekday');
|
||||
var_dump($i);
|
||||
]]>
|
||||
</programlisting>
|
||||
&example.outputs.82;
|
||||
<screen role="php">
|
||||
<![CDATA[
|
||||
object(DateInterval)#1 (2) {
|
||||
["from_string"]=>
|
||||
bool(true)
|
||||
["date_string"]=>
|
||||
string(22) "last day of next month"
|
||||
}
|
||||
object(DateInterval)#2 (2) {
|
||||
["from_string"]=>
|
||||
bool(true)
|
||||
["date_string"]=>
|
||||
string(12) "last weekday"
|
||||
}
|
||||
]]>
|
||||
</screen>
|
||||
&example.outputs.8.similar;
|
||||
<screen role="php">
|
||||
<![CDATA[
|
||||
object(DateInterval)#1 (16) {
|
||||
["y"]=>
|
||||
int(0)
|
||||
["m"]=>
|
||||
int(1)
|
||||
["d"]=>
|
||||
int(0)
|
||||
["h"]=>
|
||||
int(0)
|
||||
["i"]=>
|
||||
int(0)
|
||||
["s"]=>
|
||||
int(0)
|
||||
["f"]=>
|
||||
float(0)
|
||||
["weekday"]=>
|
||||
int(0)
|
||||
["weekday_behavior"]=>
|
||||
int(0)
|
||||
["first_last_day_of"]=>
|
||||
int(2)
|
||||
["invert"]=>
|
||||
int(0)
|
||||
["days"]=>
|
||||
bool(false)
|
||||
["special_type"]=>
|
||||
int(0)
|
||||
["special_amount"]=>
|
||||
int(0)
|
||||
["have_weekday_relative"]=>
|
||||
int(0)
|
||||
["have_special_relative"]=>
|
||||
int(0)
|
||||
}
|
||||
object(DateInterval)#2 (16) {
|
||||
["y"]=>
|
||||
int(0)
|
||||
["m"]=>
|
||||
int(0)
|
||||
["d"]=>
|
||||
int(0)
|
||||
["h"]=>
|
||||
int(0)
|
||||
["i"]=>
|
||||
int(0)
|
||||
["s"]=>
|
||||
int(0)
|
||||
["f"]=>
|
||||
float(0)
|
||||
["weekday"]=>
|
||||
int(0)
|
||||
["weekday_behavior"]=>
|
||||
int(0)
|
||||
["first_last_day_of"]=>
|
||||
int(0)
|
||||
["invert"]=>
|
||||
int(0)
|
||||
["days"]=>
|
||||
bool(false)
|
||||
["special_type"]=>
|
||||
int(1)
|
||||
["special_amount"]=>
|
||||
int(-1)
|
||||
["have_weekday_relative"]=>
|
||||
int(0)
|
||||
["have_special_relative"]=>
|
||||
int(1)
|
||||
}
|
||||
]]>
|
||||
</screen>
|
||||
</example>
|
||||
</para>
|
||||
</refsect1>
|
||||
|
||||
</refentry>
|
||||
|
|
Loading…
Reference in a new issue