# DateTime::modify('now') is ignored, why?

- Thread: https://externals.io/message/64043
- Original archive: https://news-web.php.net/php.internals/64043
- Started by Ivan Enderlin @ Hoa on 2012-11-26T11:06:09+00:00
- Messages: 7
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #64043 — Ivan Enderlin @ Hoa — 2012-11-26T11:06:09+00:00

URL: https://externals.io/message/64043#64043

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/

---

## #64045 — Sebastian Krebs — 2012-11-26T11:25:47+00:00

URL: https://externals.io/message/64043#64045 · In reply to: #64043

2012/11/26 Ivan Enderlin @ Hoa <ivan.enderlin@hoa-project.net>

> 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 <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”.
>

It's not like "modify to something", but "modify _with_ something". With
your point of view "modifiy('+7 days')" will _always_ point to next week,
but it should (and it's intuitive right), that it will point to 7 days
after the previous date. So what should "modify with now" mean?

Other way round: You are looking for the "set*()"-methods :) Because you
want to _set_ a date, not modify one.

Regards,
Sebastian


> 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/
>
>
>
> --
> 
> 
>
>


-- 
github.com/KingCrunch

---

## #64047 — Ivan Enderlin @ Hoa — 2012-11-26T11:28:04+00:00

URL: https://externals.io/message/64043#64047 · In reply to: #64045

Hi Sebastien,


> 2012/11/26 Ivan Enderlin @ Hoa <ivan.enderlin@hoa-project.net>
>
> > […]
> It's not like "modify to something", but "modify _with_ something". With
> your point of view "modifiy('+7 days')" will _always_ point to next week,
> but it should (and it's intuitive right), that it will point to 7 days
> after the previous date. So what should "modify with now" mean?
I understand the different, but then, why “now” is declared in the 
documentation :-) ?

>
> Other way round: You are looking for the "set*()"-methods :) Because you
> want to _set_ a date, not modify one.
Exactly, setTimestamp(time()) resolved by problem.

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/

---

## #64048 — Derick Rethans — 2012-11-26T12:02:50+00:00

URL: https://externals.io/message/64043#64048 · In reply to: #64047

> 
> > […]

> I understand the different, but then, why “now” is declared in the
> documentation :-) ?

Because people (like you) have tried it before and found it to not do as 
they thought :-)

Derick

-- 
http://derickrethans.nl | http://xdebug.org
Like Xdebug? Consider a donation: http://xdebug.org/donate.php
twitter: @derickr and @xdebug
Posted with an email client that doesn't mangle email: alpine

---

## #64049 — Ivan Enderlin @ Hoa — 2012-11-26T12:05:34+00:00

URL: https://externals.io/message/64043#64049 · In reply to: #64048

> 
>
> > […]
> Because people (like you) have tried it before and found it to not do as
> they thought :-)
It would have been better never write this keyword ;-).

Thanks.
Have a good day.

PS: In the french version of the documentation, the "it is ignored" was 
missing. I have submitted a patch.

-- 
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/

---

## #64050 — Nikita Nefedov — 2012-11-26T12:36:30+00:00

URL: https://externals.io/message/64043#64050 · In reply to: #64043

On Mon, 26 Nov 2012 15:06:09 +0400, Ivan Enderlin @ Hoa  
<ivan.enderlin@hoa-project.net> wrote:

> 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.
>

Shouldn't DateTime be immutable? What's the point of DateTime object being  
mutable?
I would include my point about why DateTime should be immutable but I even  
can't come with any points except OO-logic and all I can say is I just  
feel like mutable DateTime is wrong. What you think about it?

PS I'm not Nikita Popov (aka nikic) :)

---

## #64051 — Derick Rethans — 2012-11-26T12:50:00+00:00

URL: https://externals.io/message/64043#64051 · In reply to: #64050

> On Mon, 26 Nov 2012 15:06:09 +0400, Ivan Enderlin @ Hoa
> <ivan.enderlin@hoa-project.net> wrote:
> 
> > […]
> 
> Shouldn't DateTime be immutable? What's the point of DateTime object 
> being mutable? I would include my point about why DateTime should be 
> immutable but I even can't come with any points except OO-logic and 
> all I can say is I just feel like mutable DateTime is wrong. What you 
> think about it?

Yes, it should have been immutable. Biggest mistake that I made in this 
API. We can't change it anymore though.

cheers,
Derick

-- 
http://derickrethans.nl | http://xdebug.org
Like Xdebug? Consider a donation: http://xdebug.org/donate.php
twitter: @derickr and @xdebug
Posted with an email client that doesn't mangle email: alpine
