From 020c691275a3fd96060963588c344819421e05c9 Mon Sep 17 00:00:00 2001 From: Derick Rethans Date: Thu, 25 Aug 2022 17:20:54 +0100 Subject: [PATCH] Incorporate useful information from notes (take #2) --- reference/datetime/dateinterval.xml | 15 +++- reference/datetime/dateinterval/construct.xml | 26 +++++++ .../dateinterval/createfromdatestring.xml | 31 +++++++- reference/datetime/dateinterval/format.xml | 5 ++ reference/datetime/dateperiod.xml | 33 +++++++++ reference/datetime/dateperiod/construct.xml | 74 ++++++++++++++++++- reference/datetime/functions/date-create.xml | 3 +- 7 files changed, 179 insertions(+), 8 deletions(-) diff --git a/reference/datetime/dateinterval.xml b/reference/datetime/dateinterval.xml index 7149d052ca26..491295828877 100644 --- a/reference/datetime/dateinterval.xml +++ b/reference/datetime/dateinterval.xml @@ -123,6 +123,12 @@
&reftitle.properties; + + + The available properties listed below depend on PHP version, and should + be considered as readonly. + + y @@ -198,7 +204,7 @@ If the DateInterval object was created by DateTimeImmutable::diff or DateTime::diff, then this is the - total number of days between the start and end dates. Otherwise, + total number of full days between the start and end dates. Otherwise, days will be &false;. @@ -250,6 +256,13 @@ DateInterval::createFromDateString method. + + 8.2.0 + + Only the y to f, + invert, and days will be visible. + + 7.4.0 diff --git a/reference/datetime/dateinterval/construct.xml b/reference/datetime/dateinterval/construct.xml index 25cb148b8077..86dc0c5b329e 100644 --- a/reference/datetime/dateinterval/construct.xml +++ b/reference/datetime/dateinterval/construct.xml @@ -158,6 +158,32 @@ &reftitle.examples; + + + Constructing and using <classname>DateInterval</classname> objects + +add($interval); + +// Convert interval to string +echo $interval->format("%d"); +]]> + + &example.outputs; + +7 + + + + <classname>DateInterval</classname> example diff --git a/reference/datetime/dateinterval/createfromdatestring.xml b/reference/datetime/dateinterval/createfromdatestring.xml index b59190f5fe21..832143c943d4 100644 --- a/reference/datetime/dateinterval/createfromdatestring.xml +++ b/reference/datetime/dateinterval/createfromdatestring.xml @@ -13,8 +13,10 @@ stringdatetime - Uses the normal date parsers and sets up a DateInterval from the relative - parts of the parsed string. + Uses the date/time parsers as used in the + DateTimeImmutable constructor to create a + DateInterval from the relative parts of the parsed + string. @@ -32,6 +34,10 @@ DateTime, and strtotime will be used to construct the DateInterval. + + To use an ISO-8601 format string like P7D, you must + use the contructor. + @@ -103,6 +109,27 @@ $i = DateInterval::createFromDateString('3600 seconds'); + + + Parsing combinations and negative intervals + +format('%d %h %i'), "\n"; + +$i = DateInterval::createFromDateString('1 year - 10 days'); +echo $i->format('%y %d'), "\n"; +?> +]]> + + &example.outputs; + +449 2 70 +1 -10 + + + Parsing special relative date intervals diff --git a/reference/datetime/dateinterval/format.xml b/reference/datetime/dateinterval/format.xml index eab044f9528d..59b17812c0d6 100644 --- a/reference/datetime/dateinterval/format.xml +++ b/reference/datetime/dateinterval/format.xml @@ -162,6 +162,11 @@ + + 7.2.12 + The F and f format + will now always be positive. + 7.1.0 The F and f format diff --git a/reference/datetime/dateperiod.xml b/reference/datetime/dateperiod.xml index 4df26e24ca00..8daf8dfeca98 100644 --- a/reference/datetime/dateperiod.xml +++ b/reference/datetime/dateperiod.xml @@ -46,6 +46,12 @@ DatePeriod::EXCLUDE_START_DATE 1 + + const + int + DatePeriod::INCLUDE_END_DATE + 2 + &Properties; @@ -53,6 +59,11 @@ int recurrences + + public + bool + include_end_date + public bool @@ -102,6 +113,13 @@ + + DatePeriod::INCLUDE_END_DATE + + Include end date, used in DatePeriod::__construct. + + +
@@ -119,6 +137,14 @@ + + include_end_date + + + Whether to include the end date in the set of recurring dates or not. + + + include_start_date @@ -173,6 +199,13 @@ + + 8.2.0 + + The DatePeriod::INCLUDE_END_DATE constant and + include_end_date property have been added. + + 8.0.0 diff --git a/reference/datetime/dateperiod/construct.xml b/reference/datetime/dateperiod/construct.xml index 96bbec935a6b..d5f077d54e49 100644 --- a/reference/datetime/dateperiod/construct.xml +++ b/reference/datetime/dateperiod/construct.xml @@ -31,6 +31,18 @@ Creates a new DatePeriod object. + + DatePeriod objects can be used as an iterator to + generate a number of DateTimeImmutable or + DateTime object from a start + date, a interval, and an end + date or the number of recurrences. + + + The class of returned objects is equivalent to the + DateTimeImmutable or DateTime + ancester class of the start object. + @@ -41,7 +53,7 @@ start - The start date of the period. + The start date of the period. Included by default in the result set. @@ -57,7 +69,9 @@ recurrences - The number of recurrences. Must be greater than 0. + The number of recurrences. The number of returned results is + one higher than this, as the start date is included in the result set + by default. Must be greater than 0. @@ -65,7 +79,7 @@ end - The end date of the period. + The end date of the period. Excluded by default in the result set. @@ -83,10 +97,19 @@ options - Can be set to DatePeriod::EXCLUDE_START_DATE to + A bit field which can be used to control certain behaviour with start- + and end- dates. + + + With DatePeriod::EXCLUDE_START_DATE you exclude the start date from the set of recurring dates within the period. + + With DatePeriod::INCLUDE_END_DATE you + include the end date from the set of recurring dates within the + period. + @@ -105,6 +128,12 @@ + + 8.2.0 + + The DatePeriod::INCLUDE_END_DATE constant has been added. + + 7.2.19, 7.3.6, 7.4.0 @@ -185,6 +214,43 @@ foreach ($period as $date) { 2012-07-15 2012-07-22 2012-07-29 +]]> + + + + + + DatePeriod example showing all last Thursdays in a year + +format('l Y-m-d'), "\n"; +} +?> +]]> + + &example.outputs; + + diff --git a/reference/datetime/functions/date-create.xml b/reference/datetime/functions/date-create.xml index cd439cda8962..51a60889c6f0 100644 --- a/reference/datetime/functions/date-create.xml +++ b/reference/datetime/functions/date-create.xml @@ -42,8 +42,9 @@ &reftitle.seealso; - DateTime::__construct DateTimeImmutable::__construct + DateTimeImmutable::createFromFormat + DateTime::__construct