1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
|
<?xml version="1.0" encoding="utf-8"?>
<refentry xml:id="dateperiod.createfromiso8601string" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>DatePeriod::createFromISO8601String</refname>
<refpurpose>Creates a new DatePeriod object from an ISO8601 string</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis role="DatePeriod">
<modifier>public</modifier> <modifier>static</modifier> <type>static</type><methodname>DatePeriod::createFromISO8601String</methodname>
<methodparam><type>string</type><parameter>specification</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>options</parameter><initializer>0</initializer></methodparam>
</methodsynopsis>
<para>
Creates a new DatePeriod object from an ISO8601 string, as specified with
<parameter>specification</parameter>.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<variablelist>
<varlistentry>
<term><parameter>specification</parameter></term>
<listitem>
<para>
A subset of the <link xlink:href="&url.iso-8601.repeating_intervals;">ISO 8601 repeating
interval specification</link>.
</para>
<para>
An example of an accepted ISO 8601 interval specifications is
<literal>R5/2008-03-01T13:00:00Z/P1Y2M10DT2H30M</literal>, which
specifies:
</para>
<itemizedlist>
<listitem>
<simpara>
5 iterations (<literal>R5/</literal>)
</simpara>
</listitem>
<listitem>
<simpara>
Starting at <literal>2008-03-01T13:00:00Z</literal>.
</simpara>
</listitem>
<listitem>
<simpara>
Each iteration is an 1 year, 2 months, 10 days, 2 hours, and 30 minute interval
(<literal>/P1Y2M10DT2H30M</literal>).
</simpara>
</listitem>
</itemizedlist>
<para>
Examples of some ISO 8601 interval specification features that PHP does
not support are:
</para>
<orderedlist>
<listitem>
<simpara>
zero occurrences (<literal>R0/</literal>)
</simpara>
</listitem>
<listitem>
<simpara>
time offsets other than UTC (<literal>Z</literal>), such as <literal>+02:00</literal>.
</simpara>
</listitem>
</orderedlist>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>options</parameter></term>
<listitem>
<para>
A bit field which can be used to control certain behaviour with start-
and end- dates.
</para>
<para>
With <constant>DatePeriod::EXCLUDE_START_DATE</constant> you
exclude the start date from the set of recurring dates within the
period.
</para>
<para>
With <constant>DatePeriod::INCLUDE_END_DATE</constant> you
include the end date in the set of recurring dates within the
period.
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Creates a new DatePeriod object.
</para>
<para>
<classname>DatePeriod</classname> objects created with this method can be
used as an iterator to generate a number of
<classname>DateTimeImmutable</classname> objects.
</para>
</refsect1>
<refsect1 role="errors">
&reftitle.errors;
<para>
Throws an <classname>DateMalformedPeriodStringException</classname> when
the <parameter>specification</parameter> cannot be parsed as a valid ISO 8601
period.
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title>DatePeriod::createFromISO8601String example</title>
<programlisting role="php">
<![CDATA[
<?php
$iso = 'R4/2023-07-01T00:00:00Z/P7D';
$period = DatePeriod::createFromISO8601String($iso);
// By iterating over the DatePeriod object, all of the
// recurring dates within that period are printed.
foreach ($period as $date) {
echo $date->format('Y-m-d'), "\n";
}
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
2023-07-01
2023-07-08
2023-07-15
2023-07-22
2023-07-29
]]>
</screen>
</example>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->
|