File tree 29 files changed +336
-89
lines changed
29 files changed +336
-89
lines changed Original file line number Diff line number Diff line change @@ -1400,8 +1400,8 @@ The function modifies this object.</para></listitem></varlistentry>'>
1400
1400
<parameter >object</parameter ></term ><listitem ><para >Procedural style only: A <classname >DateTimeZone</classname > object
1401
1401
returned by <function >timezone_open</function ></para ></listitem ></varlistentry >'>
1402
1402
1403
- <!ENTITY date.datetime.return.modifiedobjectorfalseforfailure 'Returns the <classname xmlns =" http://docbook.org/ns/docbook" >DateTime</classname > object for method chaining&return.falseforfailure; .'>
1404
- <!ENTITY date.datetimeimmutable.return.modifiedobjectorfalseforfailure 'Returns a new modified <classname xmlns =" http://docbook.org/ns/docbook" >DateTimeImmutable</classname > object &return.falseforfailure; .'>
1403
+ <!ENTITY date.datetime.return.modifiedobjectorfalseforfailure 'Returns the modified <classname xmlns =" http://docbook.org/ns/docbook" >DateTime</classname > object for method chaining&return.falseforfailure; .'>
1404
+ <!ENTITY date.datetimeimmutable.return.modifiedobjectorfalseforfailure 'Returns a new <classname xmlns =" http://docbook.org/ns/docbook" >DateTimeImmutable</classname > object with the modified data &return.falseforfailure; .'>
1405
1405
1406
1406
<!ENTITY date.timezone.dbversion 'This list is based upon the timezone database version'>
1407
1407
Original file line number Diff line number Diff line change 10
10
<preface xml : id =" intro.datetime" >
11
11
&reftitle.intro;
12
12
<para >
13
- These functions allow you to get the date and time from the server
14
- where your PHP scripts are running. You can use these functions to format the
15
- date and time in many different ways.
13
+ The <classname >DateTimeImmutable</classname > and related classes allow you
14
+ represent date/time information. The objects can be created by passing in a
15
+ string presentation of date/time information, or from the current system's
16
+ time.
17
+ </para >
18
+ <para >
19
+ A rich set of methods is supplied to modify and format this information
20
+ as well, including handling timezones and DST transitions.
16
21
</para >
17
22
<para >
18
23
The date and time information is internally stored as a 64-bit number so
19
24
all conceivably useful dates (including negative years) are supported. The
20
25
range is from about 292 billion years in the past to the same in the
21
26
future.
22
27
</para >
23
- <note >
24
- <simpara >
25
- Please keep in mind that these functions are dependent on
26
- the locale settings of your server. Make sure to take
27
- daylight saving time (use e.g.
28
- <literal >$date = $date->modify('+7 days')</literal > and not
29
- <literal >$date += 7*24*60*60</literal >)
30
- and leap years into consideration when working
31
- with these functions.
32
- </simpara >
33
- </note >
34
28
<note >
35
29
<simpara >
36
30
The timezones referenced in this section can be found in the
Original file line number Diff line number Diff line change 18
18
except objects are modified itself when modification methods such as
19
19
<function >DateTime::modify</function > are called.
20
20
</para >
21
- <para >
22
- Using <classname >DateTimeImmutable</classname > over this class is
23
- recommended.
24
- </para >
21
+ <warning >
22
+ <para >
23
+ Calling methods on objects of the class <classname >DateTime</classname >
24
+ will change the information encapsulated in these objects, if you want to
25
+ prevent that you will have to use <literal >clone</literal > operator to
26
+ create a new object. Use the <classname >DateTimeInterface</classname >
27
+ instead of <classname >DateTime</classname > to obtain this recommended
28
+ behaviour by default.
29
+ </para >
30
+ </warning >
25
31
</section >
26
32
<!-- }}} -->
27
33
83
89
on <classname >DateTimeInterface</classname >.
84
90
</entry >
85
91
</row >
92
+ <row >
93
+ <entry >7.1.0</entry >
94
+ <entry >
95
+ The <classname >DateTime</classname > constructor now includes the
96
+ current microseconds in the constructed value. Before this, it would
97
+ always initialise the microseconds to <literal >0</literal >.
98
+ </entry >
99
+ </row >
100
+ <row >
101
+ <entry >5.2.2</entry >
102
+ <entry >
103
+ Support for microseconds was added in both date/time parser, and
104
+ <methodname >DateTime::format</methodname > through the
105
+ <literal >'u'</literal > modifier.
106
+ </entry >
107
+ </row >
86
108
</tbody >
87
109
</tgroup >
88
110
</informaltable >
Original file line number Diff line number Diff line change 86
86
</para >
87
87
</refsect1 >
88
88
89
+ <refsect1 role =" changelog" >
90
+ &reftitle.changelog;
91
+ <informaltable >
92
+ <tgroup cols =" 2" >
93
+ <thead >
94
+ <row >
95
+ <entry >&Version; </entry >
96
+ <entry >&Description; </entry >
97
+ </row >
98
+ </thead >
99
+ <tbody >
100
+ <row >
101
+ <entry >8.1.0</entry >
102
+ <entry >The behaviour with double existing hours (during the fall-back
103
+ DST transition) changed. Previously PHP would pick the second occurrence
104
+ (after the DST transition), instead of the first occurrence (before DST
105
+ transition).
106
+ </row >
107
+ <row >
108
+ <entry >7.1.0</entry >
109
+ <entry >The <parameter >microsecond</parameter > parameter was added.</entry >
110
+ </row >
111
+ </tbody >
112
+ </tgroup >
113
+ </informaltable >
114
+ </refsect1 >
115
+
89
116
<refsect1 role =" seealso" >
90
117
&reftitle.seealso;
91
118
<simplelist >
Original file line number Diff line number Diff line change 53
53
<refsect1 role =" returnvalues" >
54
54
&reftitle.returnvalues;
55
55
<para >
56
- Returns the <classname >DateTime</classname > object for method chaining.
56
+ Returns the <classname >DateTime</classname > object for method chaining. The
57
+ underlaying point-in-time is not changed when calling this method.
57
58
</para >
58
59
</refsect1 >
59
60
Original file line number Diff line number Diff line change 25
25
<methodparam ><type >DateInterval</type ><parameter >interval</parameter ></methodparam >
26
26
</methodsynopsis >
27
27
<para >
28
- Subtracts the specified < classname >DateInterval</ classname > object from the specified DateTime
29
- object.
28
+ Modifies the specified DateTime object, by subtracting the specified
29
+ < classname >DateInterval</ classname > object.
30
30
</para >
31
31
<para >
32
32
Like <methodname >DateTimeImmutable::sub</methodname > but works with
Original file line number Diff line number Diff line change 60
60
61
61
</section >
62
62
63
+ <section role =" changelog" xml : id =" datetimeimmutable.changelog" ><!-- {{{ -->
64
+ &reftitle.changelog;
65
+ <para >
66
+ <informaltable >
67
+ <tgroup cols =" 2" >
68
+ <thead >
69
+ <row >
70
+ <entry >&Version; </entry >
71
+ <entry >&Description; </entry >
72
+ </row >
73
+ </thead >
74
+ <tbody >
75
+ <row >
76
+ <entry >7.1.0</entry >
77
+ <entry >
78
+ The <classname >DateTimeImmutable</classname > constructor now includes the
79
+ current microseconds in the constructed value. Before this, it would
80
+ always initialise the microseconds to <literal >0</literal >.
81
+ </entry >
82
+ </row >
83
+ </tbody >
84
+ </tgroup >
85
+ </informaltable >
86
+ </para >
87
+ </section ><!-- }}} -->
63
88
</partintro >
64
89
65
90
&reference.datetime.entities.datetimeimmutable;
Original file line number Diff line number Diff line change 15
15
<methodparam ><type >DateInterval</type ><parameter >interval</parameter ></methodparam >
16
16
</methodsynopsis >
17
17
<para >
18
- Adds the specified <classname >DateInterval </classname > object to the
19
- specified <classname >DateTime </classname > object, and returns a new
20
- < classname >DateTimeImmutable</ classname > object to represent this new state .
18
+ Creates a new <classname >DateTimeImmutable </classname > object, and adds the
19
+ specified <classname >DateInterval </classname > object to this, to represent
20
+ the new value .
21
21
</para >
22
22
</refsect1 >
23
23
24
24
<refsect1 role =" parameters" >
25
25
&reftitle.parameters;
26
26
<variablelist >
27
- &date.datetime.description.modified;
28
27
<varlistentry >
29
28
<term >
30
29
<parameter >interval</parameter >
Original file line number Diff line number Diff line change 57
57
<parameter >$datetime</parameter > parameter either
58
58
is a UNIX timestamp (e.g. <literal >@946684800</literal >)
59
59
or specifies a timezone
60
- (e.g. <literal >2010-01-28T15:00:00+02:00</literal >).
60
+ (e.g. <literal >2010-01-28T15:00:00+02:00</literal >, or
61
+ <literal >2010-07-05T06:00:00Z</literal >).
61
62
</para >
62
63
</note >
63
64
</listitem >
@@ -185,6 +186,48 @@ echo $date->format('Y-m-d H:i:sP') . "\n";
185
186
2010-04-25 02:24:16+12:00
186
187
2000-01-01 00:00:00+00:00
187
188
2000-03-01 00:00:00-05:00
189
+ ]]>
190
+ </screen >
191
+ </example >
192
+
193
+ <example >
194
+ <title >Changing the associated timezone</title >
195
+ <programlisting role =" php" >
196
+ <![CDATA[
197
+ <?php
198
+ $timeZone = new \DateTimeZone('Asia/Tokyo');
199
+
200
+ $time = new \DateTimeImmutable();
201
+ $time = $time->setTimezone($timeZone);
202
+
203
+ echo $time->format('Y/m/d H:i:s'), "\n";
204
+ ?>
205
+ ]]>
206
+ </programlisting >
207
+ &example.outputs.similar;
208
+ <screen >
209
+ <![CDATA[
210
+ 2022/08/12 23:49:23
211
+ ]]>
212
+ </screen >
213
+ </example >
214
+ </refsect1 >
215
+
216
+ <example >
217
+ <title >Using a relative date/time string</title >
218
+ <programlisting role =" php" >
219
+ <![CDATA[
220
+ <?php
221
+ $time = new \DateTimeImmutable("-1 year");
222
+
223
+ echo $time->format('Y/m/d H:i:s'), "\n";
224
+ ?>
225
+ ]]>
226
+ </programlisting >
227
+ &example.outputs.similar;
228
+ <screen >
229
+ <![CDATA[
230
+ 2021/08/12 15:43:51
188
231
]]>
189
232
</screen >
190
233
</example >
Original file line number Diff line number Diff line change 41
41
formatting options below. In most cases, the same letters as for the
42
42
<function >date</function > can be used.
43
43
</para >
44
+ <para >
45
+ ALl fields are initialised with the current date/time. In most cases you
46
+ would want to reset these to "zero" (the Unix epoch, <literal >1970-01-01
47
+ 00:00:00 UTC</literal >). You do that by including the
48
+ <literal >!</literal > character as first character in your
49
+ <parameter >format</parameter >, or <literal >|</literal > as your last.
50
+ Please see the documentation for each character below for more
51
+ information.
52
+ </para >
44
53
<para >
45
54
The format is parsed from left to right, which means that in some
46
55
situations the order in which the format characters are present effects
Original file line number Diff line number Diff line change 35
35
&reftitle.examples;
36
36
<example >
37
37
<title ><function >DateTimeImmutable::getLastErrors</function > example</title >
38
- <para >&style.oop; </para >
39
38
<programlisting role =" php" >
40
39
<![CDATA[
41
40
<?php
Original file line number Diff line number Diff line change 21
21
<refsect1 role =" parameters" >
22
22
&reftitle.parameters;
23
23
<variablelist >
24
- &date.datetime.description.modified;
25
24
<varlistentry >
26
25
<term ><parameter >modifier</parameter ></term >
27
26
<listitem >
Original file line number Diff line number Diff line change 23
23
<refsect1 role =" parameters" >
24
24
&reftitle.parameters;
25
25
<variablelist >
26
- &date.datetime.description.modified;
27
26
<varlistentry >
28
27
<term ><parameter >year</parameter ></term >
29
28
<listitem >
Original file line number Diff line number Diff line change 23
23
<refsect1 role =" parameters" >
24
24
&reftitle.parameters;
25
25
<variablelist >
26
- &date.datetime.description.modified;
27
26
<varlistentry >
28
27
<term ><parameter >hour</parameter ></term >
29
28
<listitem >
77
76
</row >
78
77
</thead >
79
78
<tbody >
79
+ <row >
80
+ <entry >8.1.0</entry >
81
+ <entry >The behaviour with double existing hours (during the fall-back
82
+ DST transition) changed. Previously PHP would pick the second occurrence
83
+ (after the DST transition), instead of the first occurrence (before DST
84
+ transition).
85
+ </row >
80
86
<row >
81
87
<entry >7.1.0</entry >
82
88
<entry >The <parameter >microsecond</parameter > parameter was added.</entry >
Original file line number Diff line number Diff line change 13
13
<methodparam ><type >int</type ><parameter >timestamp</parameter ></methodparam >
14
14
</methodsynopsis >
15
15
<para >
16
- Returns a new DateTimeImmutable object with the date and time set based on an Unix timestamp.
16
+ Returns a new <type >DateTimeImmutable</type > object constructed from the
17
+ old one, with the date and time set based on an Unix timestamp.
17
18
</para >
18
19
</refsect1 >
19
20
20
21
<refsect1 role =" parameters" >
21
22
&reftitle.parameters;
22
23
<variablelist >
23
- &date.datetime.description.modified;
24
24
<varlistentry >
25
25
<term ><parameter >timestamp</parameter ></term >
26
26
<listitem >
Original file line number Diff line number Diff line change 20
20
<refsect1 role =" parameters" >
21
21
&reftitle.parameters;
22
22
<variablelist >
23
- &date.datetime.description.modified;
24
23
<varlistentry >
25
24
<term ><parameter >timezone</parameter ></term >
26
25
<listitem >
36
35
<refsect1 role =" returnvalues" >
37
36
&reftitle.returnvalues;
38
37
<para >
39
- Returns a new modified <classname >DateTimeImmutable</classname > object for method chaining.
38
+ Returns a new modified <classname >DateTimeImmutable</classname > object for
39
+ method chaining. The underlaying point-in-time is not changed when calling
40
+ this method.
40
41
</para >
41
42
</refsect1 >
42
43
Original file line number Diff line number Diff line change 15
15
<methodparam ><type >DateInterval</type ><parameter >interval</parameter ></methodparam >
16
16
</methodsynopsis >
17
17
<para >
18
- Returns a new DateTimeImmutable object, with the specified
18
+ Returns a new < classname > DateTimeImmutable</ classname > object, with the specified
19
19
<classname >DateInterval</classname > object subtracted from the specified
20
20
DateTimeImmutable object.
21
21
</para >
24
24
<refsect1 role =" parameters" >
25
25
&reftitle.parameters;
26
26
<variablelist >
27
- &date.datetime.description.modified;
28
27
<varlistentry >
29
28
<term >
30
29
<parameter >interval</parameter >
You can’t perform that action at this time.
0 commit comments