svn: /phpdoc/en/trunk/reference/datetime/datetime/ add.xml sub.xml

From: Date: Sun, 25 Apr 2010 19:26:45 +0000
Subject: svn: /phpdoc/en/trunk/reference/datetime/datetime/ add.xml sub.xml
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-6480@lists.php.net to get a copy of this message
danielc Sun, 25 Apr 2010 19:26:45 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=298551 Log: Add example of how adding/subtracting months can be problematic. Changed paths: U phpdoc/en/trunk/reference/datetime/datetime/add.xml U phpdoc/en/trunk/reference/datetime/datetime/sub.xml Modified: phpdoc/en/trunk/reference/datetime/datetime/add.xml =================================================================== --- phpdoc/en/trunk/reference/datetime/datetime/add.xml 2010-04-25 19:17:16 UTC (rev 298550) +++ phpdoc/en/trunk/reference/datetime/datetime/add.xml 2010-04-25 19:26:45 UTC (rev 298551) @@ -83,6 +83,30 @@ ]]> </screen> </example> + <example> + <title>Beware when adding months</title> + <programlisting role="php"> +<![CDATA[ +<?php +$date = new DateTime('2000-12-31'); +$interval = new DateInterval('P1M'); + +$date->add($interval); +echo $date->format('Y-m-d') . "\n"; + +$date->add($interval); +echo $date->format('Y-m-d') . "\n"; +?> +]]> + </programlisting> + &example.outputs; + <screen> +<![CDATA[ +2001-01-31 +2001-03-03 +]]> + </screen> + </example> </refsect1> <refsect1 role="notes"> Modified: phpdoc/en/trunk/reference/datetime/datetime/sub.xml =================================================================== --- phpdoc/en/trunk/reference/datetime/datetime/sub.xml 2010-04-25 19:17:16 UTC (rev 298550) +++ phpdoc/en/trunk/reference/datetime/datetime/sub.xml 2010-04-25 19:26:45 UTC (rev 298551) @@ -83,6 +83,30 @@ ]]> </screen> </example> + <example> + <title>Beware when subtracting months</title> + <programlisting role="php"> +<![CDATA[ +<?php +$date = new DateTime('2001-04-30'); +$interval = new DateInterval('P1M'); + +$date->sub($interval); +echo $date->format('Y-m-d') . "\n"; + +$date->sub($interval); +echo $date->format('Y-m-d') . "\n"; +?> +]]> + </programlisting> + &example.outputs; + <screen> +<![CDATA[ +2001-03-30 +2001-03-02 +]]> + </screen> + </example> </refsect1> <refsect1 role="notes">

« previous php.doc.cvs (#6480) next »