From 0e42d1d3a6fb34b8205666abdb95f95481781655 Mon Sep 17 00:00:00 2001 From: Daniel Convissor Date: Wed, 28 Apr 2010 15:58:26 +0000 Subject: [PATCH] Reworked examples to new oop/procedural combination format. Changed several titles. Simplified some initial examples and moved some parts to new examples. Per discussion on php-doc. git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@298705 c90b9560-bf6c-de11-be94-00142212c4b1 --- reference/datetime/datetime/add.xml | 32 +++++++++-- reference/datetime/datetime/construct.xml | 27 +++++++++ .../datetime/datetime/createfromformat.xml | 29 +++++++++- reference/datetime/datetime/diff.xml | 13 ++--- reference/datetime/datetime/format.xml | 23 ++++---- reference/datetime/datetime/getlasterrors.xml | 21 ++++++- reference/datetime/datetime/getoffset.xml | 29 +++++++++- reference/datetime/datetime/gettimezone.xml | 13 ++++- reference/datetime/datetime/setdate.xml | 57 ++++++++++++------- reference/datetime/datetime/setisodate.xml | 43 ++++++++++++-- reference/datetime/datetime/settime.xml | 55 +++++++++++++++--- reference/datetime/datetime/settimezone.xml | 17 +++++- reference/datetime/datetime/sub.xml | 32 +++++++++-- 13 files changed, 321 insertions(+), 70 deletions(-) diff --git a/reference/datetime/datetime/add.xml b/reference/datetime/datetime/add.xml index 92e9891212..94790e86d2 100644 --- a/reference/datetime/datetime/add.xml +++ b/reference/datetime/datetime/add.xml @@ -56,14 +56,39 @@ &reftitle.examples; - <function>date_add</function> example + <function>DateTime::add</function> example + &style.oop; add(new DateInterval('P10D')); -echo $date->format('Y-m-d H:i:s') . "\n"; - +echo $date->format('Y-m-d') . "\n"; +?> +]]> + + &style.procedural; + + +]]> + + &examples.outputs; + + + + + + Further <function>DateTime::add</function> examples + +add(new DateInterval('PT10H30S')); echo $date->format('Y-m-d H:i:s') . "\n"; @@ -77,7 +102,6 @@ echo $date->format('Y-m-d H:i:s') . "\n"; &example.outputs; diff --git a/reference/datetime/datetime/construct.xml b/reference/datetime/datetime/construct.xml index 55a608c14a..559965cc72 100644 --- a/reference/datetime/datetime/construct.xml +++ b/reference/datetime/datetime/construct.xml @@ -82,6 +82,33 @@ &reftitle.examples; <function>DateTime::__construct</function> example + &style.oop; + +format('Y-m-d'); +?> +]]> + + &style.procedural; + + +]]> + + &examples.outputs; + + + + + + Intricacies of <function>DateTime::__construct</function> &reftitle.examples; - <methodname>DateTime::createFromFormat</methodname> example + <function>DateTime::createFromFormat</function> example + &style.oop; + +format('Y-m-d'); +?> +]]> + + &style.procedural; + + +]]> + + &examples.outputs; + + + + + + Intricacies of <function>DateTime::createFromFormat</function> &reftitle.examples; - Object oriented style example of <function>DateTime::diff</function> + <function>DateTime::diff</function> example + &style.oop; format('%R%d days'); ?> ]]> - - - Procedural style example of <function>date_diff</function> + &style.procedural; format('%R%d days'); ?> ]]> - &example.outputs; + &examples.outputs; &reftitle.examples; - Displaying the date and time using the procedural form - - -]]> - - - - Displaying the date and time using the object oriented form + <function>DateTime::format</function> example + &style.oop; format('Y-m-d H:i:s'); ?> +]]> + + &style.procedural; + + ]]> &example.outputs; diff --git a/reference/datetime/datetime/getlasterrors.xml b/reference/datetime/datetime/getlasterrors.xml index efa5683878..a06219bf3d 100644 --- a/reference/datetime/datetime/getlasterrors.xml +++ b/reference/datetime/datetime/getlasterrors.xml @@ -40,15 +40,32 @@ &reftitle.examples; <function>DateTime::getLastErrors</function> example + &style.oop; + +getMessage(); +} +?> +]]> + + &style.procedural; ]]> - &example.outputs; + &examples.outputs; &reftitle.examples; - Comparing offsets between Summer and Winter + <function>DateTime::getOffset</function> example + &style.oop; getOffset() . "\n"; // "-18000" (-5 hours) -echo $summer->getOffset() . "\n"; // "-14400" (-4 hours) +echo $winter->getOffset() . "\n"; +echo $summer->getOffset() . "\n"; ?> ]]> + &style.procedural; + +getOffset() . "\n"; +echo $summer->getOffset() . "\n"; +?> +]]> + + &examples.outputs; + + + + + Note: -18000 = -5 hours, -14400 = -4 hours. + diff --git a/reference/datetime/datetime/gettimezone.xml b/reference/datetime/datetime/gettimezone.xml index 767f4ded76..9a3a337333 100644 --- a/reference/datetime/datetime/gettimezone.xml +++ b/reference/datetime/datetime/gettimezone.xml @@ -39,6 +39,7 @@ &reftitle.examples; <function>DateTime::getTimezone</function> example + &style.oop; getName(); ?> ]]> - &example.outputs; + &style.procedural; + + +]]> + + &examples.outputs; &reftitle.examples; - Object oriented example usage + <function>DateTime::setDate</function> example + &style.oop; + +setDate(2001, 2, 3); +echo $date->format('Y-m-d'); +?> +]]> + + &style.procedural; + + +]]> + + &examples.outputs; + + + + + + Values exceeding ranges are added to their parent values setDate(2001, 2, 3); +$date->setDate(2001, 2, 28); +echo $date->format('Y-m-d') . "\n"; + +$date->setDate(2001, 2, 29); echo $date->format('Y-m-d') . "\n"; -// Values exceeding ranges are added to their parent values. $date->setDate(2001, 14, 3); echo $date->format('Y-m-d') . "\n"; ?> -]]> - - - - Procedural example usage - - ]]> &example.outputs; diff --git a/reference/datetime/datetime/setisodate.xml b/reference/datetime/datetime/setisodate.xml index fa46662b6f..db66e2cd21 100644 --- a/reference/datetime/datetime/setisodate.xml +++ b/reference/datetime/datetime/setisodate.xml @@ -88,7 +88,8 @@ &reftitle.examples; - Finding the date from a week number and day offset + <function>DateTime::setISODate</function> example + &style.oop; setISODate(2008, 2); echo $date->format('Y-m-d') . "\n"; -$date->setISODate(2008, 2, 1); +$date->setISODate(2008, 2, 7); echo $date->format('Y-m-d') . "\n"; +?> +]]> + + &style.procedural; + + +]]> + + &examples.outputs; + + + + + + Values exceeding ranges are added to their parent values + +setISODate(2008, 2, 7); echo $date->format('Y-m-d') . "\n"; -// Values exceeding ranges are added to their parent values. $date->setISODate(2008, 2, 8); echo $date->format('Y-m-d') . "\n"; + +$date->setISODate(2008, 53, 7); +echo $date->format('Y-m-d') . "\n"; ?> ]]> &example.outputs; diff --git a/reference/datetime/datetime/settime.xml b/reference/datetime/datetime/settime.xml index 968dddaf74..349da12b46 100644 --- a/reference/datetime/datetime/settime.xml +++ b/reference/datetime/datetime/settime.xml @@ -87,32 +87,71 @@ &reftitle.examples; - Changing the time of a DateTime object + <function>DateTime::setTime</function> example + &style.oop; format('Y-m-d H:i:s') . "\n"; +$date = new DateTime('2001-01-01'); $date->setTime(14, 55); echo $date->format('Y-m-d H:i:s') . "\n"; $date->setTime(14, 55, 24); echo $date->format('Y-m-d H:i:s') . "\n"; +?> +]]> + + &style.procedural; + + +]]> + + &examples.outputs.similar; + + + + + + Values exceeding ranges are added to their parent values + +setTime(14, 55, 24); +echo $date->format('Y-m-d H:i:s') . "\n"; + +$date->setTime(14, 55, 65); +echo $date->format('Y-m-d H:i:s') . "\n"; -// Values exceeding ranges are added to their parent values. $date->setTime(14, 65, 24); echo $date->format('Y-m-d H:i:s') . "\n"; + +$date->setTime(25, 55, 24); +echo $date->format('Y-m-d H:i:s') . "\n"; ?> ]]> &example.outputs; diff --git a/reference/datetime/datetime/settimezone.xml b/reference/datetime/datetime/settimezone.xml index 01daa9bf38..9f5180bae0 100644 --- a/reference/datetime/datetime/settimezone.xml +++ b/reference/datetime/datetime/settimezone.xml @@ -71,7 +71,8 @@ &reftitle.examples; - Setting and getting DateTimeZone objects + <function>DateTime::setTimeZone</function> example + &style.oop; format('Y-m-d H:i:sP') . "\n"; ?> ]]> - &example.outputs; + &style.procedural; + + +]]> + + &examples.outputs; &reftitle.examples; - <function>date_sub</function> example + <function>DateTime::sub</function> example + &style.oop; sub(new DateInterval('P10D')); -echo $date->format('Y-m-d H:i:s') . "\n"; - +echo $date->format('Y-m-d') . "\n"; +?> +]]> + + &style.procedural; + + +]]> + + &examples.outputs; + + + + + + Further <function>DateTime::sub</function> examples + +sub(new DateInterval('PT10H30S')); echo $date->format('Y-m-d H:i:s') . "\n"; @@ -77,7 +102,6 @@ echo $date->format('Y-m-d H:i:s') . "\n"; &example.outputs;