Re: DateTime::modify('now') is ignored, why?
| From: | Ivan Enderlin @ Hoa | Date: | Mon, 26 Nov 2012 11:26:23 +0000 |
| Subject: | Re: DateTime::modify('now') is ignored, why? | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-64046@lists.php.net to get a copy of this message | ||
Hi Chris,
You didn't understand. I have a \DateTime object, and I would like to change the date and time to the current date and time = now.
Imagine you have a \DateTime object that was serialized and you would like to “refresh” it, you need to $d->modify('now'). This is strictly equivalent to $d->setTimestamp(time()) but in a more elegant way. But the documentation says that “now” is ignored, and I would like to know why because it is useful.
Thanks.
On 26/11/12 12:23, Chris van Dam wrote:
Hi Ivan, $d = new \DateTime('+1 hour', new \DateTimeZone('Europe/Amsterdam')); Is exactly the same as: // Current timestamp with timezone $d = new \DateTime(null, new \DateTimeZone('Europe/Amsterdam')); // Add 1 hour to the timestamp with timezone $d->modify('+1 hour'); This is what you would like to do right? As modifying the timestamp with another timestamp would make no sense to me. Kind regards, Chris van Dam Op 26-11-12 12:06 schreef Ivan Enderlin @ Hoa <ivan.enderlin@hoa-project.net>:-- Ivan Enderlin Developer of Hoa http://hoa.42/ or http://hoa-project.net/ PhD. student at DISC/Femto-ST (Vesontio) and INRIA (Cassis) http://disc.univ-fcomte.fr/ and http://www.inria.fr/ Member of HTML and WebApps Working Group of W3C http://w3.org/Hi internals, I would to modify a \DateTime object to the current time, thus I wrote this: $d = new \DateTime('+1 hour'); $d->modify('now'); It did not work. Why? Because the documentation (http://php.net/datetime.formats.relative) says: ³Now - this is simply ignored². Really? But the behavior is pretty straightforward isn't? ³modify to now² means ³set to the current date and time and let the timezone unchanged². Thoughts? Best regards. -- Ivan Enderlin Developer of Hoa http://hoa.42/ or http://hoa-project.net/ PhD. student at DISC/Femto-ST (Vesontio) and INRIA (Cassis) http://disc.univ-fcomte.fr/ and http://www.inria.fr/ Member of HTML and WebApps Working Group of W3C http://w3.org/ -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.phpE-mail disclaimer Nederlands De informatie verzonden met dit e-mailbericht is vertrouwelijk en kan wettelijk voorbehouden zijn. Het is uitsluitend bestemd voor de geadresseerde. Gebruik van deze informatie door anderen dan de geadresseerde en zij die gerechtigd zijn daarvan kennis te nemen is verboden. Trace staat niet in voor de juiste en volledige overbrenging van de inhoud van een verzonden e-mail, noch voor tijdige ontvangst daarvan. E-mail disclaimer English The information contained in this communication is confidential and may be legally privileged. It is intended solely for the use of the individual or entity to whom it is addressed and others authorized to receive it. The use of it by others is prohibited. Trace is neither liable for the proper and complete transmission of the information contained in this communication nor for any delay in its receipt.