reference/datetime/datetime/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="datetime.sub" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
5
4
<refnamediv>
6
5
<refname>DateTime::sub</refname>
...
...
@@ -14,19 +13,27 @@
14
13
<refsect1 role="description">
15
14
&reftitle.description;
16
15
<para>&style.oop;</para>
17
-
<methodsynopsis role="oop">
16
+
<methodsynopsis role="DateTime">
18
17
<modifier>public</modifier> <type>DateTime</type><methodname>DateTime::sub</methodname>
19
18
<methodparam><type>DateInterval</type><parameter>interval</parameter></methodparam>
20
19
</methodsynopsis>
21
20
<para>&style.procedural;</para>
22
-
<methodsynopsis role="procedural">
21
+
<methodsynopsis>
23
22
<type>DateTime</type><methodname>date_sub</methodname>
24
23
<methodparam><type>DateTime</type><parameter>object</parameter></methodparam>
25
24
<methodparam><type>DateInterval</type><parameter>interval</parameter></methodparam>
26
25
</methodsynopsis>
27
26
<para>
28
-
Subtracts the specified <classname>DateInterval</classname> object from the specified DateTime
29
-
object.
27
+
Modifies the specified DateTime object, by subtracting the specified
28
+
<classname>DateInterval</classname> object.
29
+
</para>
30
+
<para>
31
+
Like <methodname>DateTimeImmutable::sub</methodname> but works with
32
+
<classname>DateTime</classname>.
33
+
</para>
34
+
<para>
35
+
The procedural version takes the <classname>DateTime</classname> object as
36
+
its first argument.
30
37
</para>
31
38
</refsect1>
32
39

...
...
@@ -50,109 +57,53 @@
50
57
<refsect1 role="returnvalues">
51
58
&reftitle.returnvalues;
52
59
<para>
53
-
&date.datetime.return.modifiedobjectorfalseforfailure;
60
+
&date.datetime.return.modifiedobject;
54
61
</para>
55
62
</refsect1>
56
63

57
-
<refsect1 role="examples">
58
-
&reftitle.examples;
59
-
<example>
60
-
<title><function>DateTime::sub</function> example</title>
61
-
<para>&style.oop;</para>
62
-
<programlisting role="php">
63
-
<![CDATA[
64
-
<?php
65
-
$date = new DateTime('2000-01-20');
66
-
$date->sub(new DateInterval('P10D'));
67
-
echo $date->format('Y-m-d') . "\n";
68
-
?>
69
-
]]>
70
-
</programlisting>
71
-
<para>&style.procedural;</para>
72
-
<programlisting role="php">
73
-
<![CDATA[
74
-
<?php
75
-
$date = date_create('2000-01-20');
76
-
date_sub($date, date_interval_create_from_date_string('10 days'));
77
-
echo date_format($date, 'Y-m-d');
78
-
?>
79
-
]]>
80
-
</programlisting>
81
-
&examples.outputs;
82
-
<screen>
83
-
<![CDATA[
84
-
2000-01-10
85
-
]]>
86
-
</screen>
87
-
</example>
88
-
<example>
89
-
<title>Further <function>DateTime::sub</function> examples</title>
90
-
<programlisting role="php">
91
-
<![CDATA[
92
-
<?php
93
-
$date = new DateTime('2000-01-20');
94
-
$date->sub(new DateInterval('PT10H30S'));
95
-
echo $date->format('Y-m-d H:i:s') . "\n";
96
-

97
-
$date = new DateTime('2000-01-20');
98
-
$date->sub(new DateInterval('P7Y5M4DT4H3M2S'));
99
-
echo $date->format('Y-m-d H:i:s') . "\n";
100
-
?>
101
-
]]>
102
-
</programlisting>
103
-
&example.outputs;
104
-
<screen>
105
-
<![CDATA[
106
-
2000-01-19 13:59:30
107
-
1992-08-15 19:56:58
108
-
]]>
109
-
</screen>
110
-
</example>
111
-
<example>
112
-
<title>Beware when subtracting months</title>
113
-
<programlisting role="php">
114
-
<![CDATA[
115
-
<?php
116
-
$date = new DateTime('2001-04-30');
117
-
$interval = new DateInterval('P1M');
118
-

119
-
$date->sub($interval);
120
-
echo $date->format('Y-m-d') . "\n";
121
-

122
-
$date->sub($interval);
123
-
echo $date->format('Y-m-d') . "\n";
124
-
?>
125
-
]]>
126
-
</programlisting>
127
-
&example.outputs;
128
-
<screen>
129
-
<![CDATA[
130
-
2001-03-30
131
-
2001-03-02
132
-
]]>
133
-
</screen>
134
-
</example>
135
-
</refsect1>
136
-

137
-
<refsect1 role="notes">
138
-
&reftitle.notes;
64
+
<refsect1 role="errors">
65
+
&reftitle.errors;
139
66
<para>
140
-
<function>DateTime::modify</function>
141
-
is an alternative when using PHP 5.2.
67
+
Object Orientated API only: If an unsupported operation is attempted, such as using a
68
+
<classname>DateInterval</classname> object representing relative time
69
+
specifications such as <literal>next weekday</literal>, a
70
+
<exceptionname>DateInvalidOperationException</exceptionname> is thrown.
142
71
</para>
143
72
</refsect1>
144
73

74
+
<refsect1 role="changelog">
75
+
&reftitle.changelog;
76
+
<informaltable>
77
+
<tgroup cols="2">
78
+
<thead>
79
+
<row>
80
+
<entry>&Version;</entry>
81
+
<entry>&Description;</entry>
82
+
</row>
83
+
</thead>
84
+
<tbody>
85
+
<row>
86
+
<entry>8.3.0</entry>
87
+
<entry>
88
+
Now throws a
89
+
<exceptionname>DateInvalidOperationException</exceptionname> with
90
+
<methodname>DateTime::sub</methodname>, instead of
91
+
a warning when an unsupported operation is attempted.
92
+
<function>date_sub</function> has not been changed.
93
+
</entry>
94
+
</row>
95
+
</tbody>
96
+
</tgroup>
97
+
</informaltable>
98
+
</refsect1>
99
+

145
100
<refsect1 role="seealso">
146
101
&reftitle.seealso;
147
102
<simplelist>
148
-
<member><function>DateTime::add</function></member>
149
-
<member><function>DateTime::diff</function></member>
150
-
<member><function>DateTime::modify</function></member>
103
+
<member><function>DateTimeImmutable::sub</function></member>
151
104
</simplelist>
152
105
</refsect1>
153
-

154
106
</refentry>
155
-

156
107
<!-- Keep this comment at the end of the file
157
108
Local variables:
158
109
mode: sgml
159
110