reference/datetime/datetimeimmutable/sub.xml
d7b51f68698544fb3e0384693809fe2aafa9c69e
...
...
@@ -1,6 +1,5 @@
1
1
<?xml version="1.0" encoding="utf-8"?>
2
2
<!-- $Revision$ -->
3
-

4
3
<refentry xml:id="datetimeimmutable.sub" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
5
4
<refnamediv>
6
5
<refname>DateTimeImmutable::sub</refname>
...
...
@@ -11,18 +10,154 @@
11
10

12
11
<refsect1 role="description">
13
12
&reftitle.description;
14
-
<methodsynopsis role="oop">
13
+
<methodsynopsis role="DateTimeImmutable">
15
14
<modifier>public</modifier> <type>DateTimeImmutable</type><methodname>DateTimeImmutable::sub</methodname>
16
15
<methodparam><type>DateInterval</type><parameter>interval</parameter></methodparam>
17
16
</methodsynopsis>
18
17
<para>
19
-
Like <methodname>DateTime::sub</methodname> but works with
20
-
<classname>DateTimeImmutable</classname>.
18
+
Returns a new <classname>DateTimeImmutable</classname> object, with the specified
19
+
<classname>DateInterval</classname> object subtracted from the specified
20
+
DateTimeImmutable object.
21
21
</para>
22
22
</refsect1>
23
23

24
-
</refentry>
24
+
<refsect1 role="parameters">
25
+
&reftitle.parameters;
26
+
<variablelist>
27
+
<varlistentry>
28
+
<term>
29
+
<parameter>interval</parameter>
30
+
</term>
31
+
<listitem>
32
+
<para>
33
+
A <classname>DateInterval</classname> object
34
+
</para>
35
+
</listitem>
36
+
</varlistentry>
37
+
</variablelist>
38
+
</refsect1>
39
+

40
+
<refsect1 role="returnvalues">
41
+
&reftitle.returnvalues;
42
+
<para>
43
+
&date.datetimeimmutable.return.modifiedobject;
44
+
</para>
45
+
</refsect1>
46
+

47
+
<refsect1 role="errors">
48
+
&reftitle.errors;
49
+
<para>
50
+
If an unsupported operation is attempted, such as using a
51
+
<classname>DateInterval</classname> object representing relative time
52
+
specifications such as <literal>next weekday</literal>, a
53
+
<exceptionname>DateInvalidOperationException</exceptionname> is thrown.
54
+
</para>
55
+
</refsect1>
25
56

57
+
<refsect1 role="changelog">
58
+
&reftitle.changelog;
59
+
<informaltable>
60
+
<tgroup cols="2">
61
+
<thead>
62
+
<row>
63
+
<entry>&Version;</entry>
64
+
<entry>&Description;</entry>
65
+
</row>
66
+
</thead>
67
+
<tbody>
68
+
<row>
69
+
<entry>8.3.0</entry>
70
+
<entry>
71
+
Now throws a
72
+
<exceptionname>DateInvalidOperationException</exceptionname> instead of
73
+
a warning when an unsupported operation is attempted.
74
+
</entry>
75
+
</row>
76
+
</tbody>
77
+
</tgroup>
78
+
</informaltable>
79
+
</refsect1>
80
+

81
+
<refsect1 role="examples">
82
+
&reftitle.examples;
83
+
<example>
84
+
<title><function>DateTimeImmutable::sub</function> example</title>
85
+
<para>&style.oop;</para>
86
+
<programlisting role="php">
87
+
<![CDATA[
88
+
<?php
89
+
$date = new DateTimeImmutable('2000-01-20');
90
+
$newDate = $date->sub(new DateInterval('P10D'));
91
+
echo $newDate->format('Y-m-d') . "\n";
92
+
?>
93
+
]]>
94
+
</programlisting>
95
+
&examples.outputs;
96
+
<screen>
97
+
<![CDATA[
98
+
2000-01-10
99
+
]]>
100
+
</screen>
101
+
</example>
102
+
<example>
103
+
<title>Further <function>DateTimeImmutable::sub</function> examples</title>
104
+
<programlisting role="php">
105
+
<![CDATA[
106
+
<?php
107
+
$date = new DateTimeImmutable('2000-01-20');
108
+
$newDate = $date->sub(new DateInterval('PT10H30S'));
109
+
echo $newDate->format('Y-m-d H:i:s') . "\n";
110
+

111
+
$date = new DateTimeImmutable('2000-01-20');
112
+
$newDate = $date->sub(new DateInterval('P7Y5M4DT4H3M2S'));
113
+
echo $newDate->format('Y-m-d H:i:s') . "\n";
114
+
?>
115
+
]]>
116
+
</programlisting>
117
+
&example.outputs;
118
+
<screen>
119
+
<![CDATA[
120
+
2000-01-19 13:59:30
121
+
1992-08-15 19:56:58
122
+
]]>
123
+
</screen>
124
+
</example>
125
+
<example>
126
+
<title>Beware when subtracting months</title>
127
+
<programlisting role="php">
128
+
<![CDATA[
129
+
<?php
130
+
$date = new DateTimeImmutable('2001-04-30');
131
+
$interval = new DateInterval('P1M');
132
+

133
+
$newDate1 = $date->sub($interval);
134
+
echo $newDate1->format('Y-m-d') . "\n";
135
+

136
+
$newDate2 = $newDate1->sub($interval);
137
+
echo $newDate2->format('Y-m-d') . "\n";
138
+
?>
139
+
]]>
140
+
</programlisting>
141
+
&example.outputs;
142
+
<screen>
143
+
<![CDATA[
144
+
2001-03-30
145
+
2001-03-02
146
+
]]>
147
+
</screen>
148
+
</example>
149
+
</refsect1>
150
+

151
+
<refsect1 role="seealso">
152
+
&reftitle.seealso;
153
+
<simplelist>
154
+
<member><function>DateTimeImmutable::add</function></member>
155
+
<member><function>DateTimeImmutable::diff</function></member>
156
+
<member><function>DateTimeImmutable::modify</function></member>
157
+
</simplelist>
158
+
</refsect1>
159
+

160
+
</refentry>
26
161
<!-- Keep this comment at the end of the file
27
162
Local variables:
28
163
mode: sgml
29
164