# timelib diff working wrong on with years

- Thread: https://externals.io/message/70586
- Original archive: https://news-web.php.net/php.internals/70586
- Started by Nikita Nefedov on 2013-12-11T09:38:26+00:00
- Messages: 5
- 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

---

## #70586 — Nikita Nefedov — 2013-12-11T09:38:26+00:00

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

Hi,

today I stumbled upon this bug, but I actually don't know should I call it  
bug or is it right behavior?

So for example lets get diff between 2013-10-25 and 2014-10-25:
var_dump((new DateTime("2013-03-25"))->diff(new DateTime("2014-03-25")))

We'll get one full year.

Then if we try to get diff between 2012-03-25 and 2013-03-25 we'll also  
get one year.

But if we have 2012-03-01 and 2013-03-01 then we get 11 months and 30 days  
(365 in int->days member)...

Should we consider this as a bug or not?

---

## #70587 — Tjerk Meesters — 2013-12-11T10:02:54+00:00

URL: https://externals.io/message/70586#70587 · In reply to: #70586

> Hi,
>
> today I stumbled upon this bug, but I actually don't know should I call it
> bug or is it right behavior?
>
> So for example lets get diff between 2013-10-25 and 2014-10-25:
> var_dump((new DateTime("2013-03-25"))->diff(new DateTime("2014-03-25")))
>
> We'll get one full year.
>
> Then if we try to get diff between 2012-03-25 and 2013-03-25 we'll also
> get one year.
>
> But if we have 2012-03-01 and 2013-03-01 then we get 11 months and 30 days
> (365 in int->days member)...
>

It gets interesting when you look one day around it:

2012-02-28 -> 2013-02-28 = 366 total, 1 year
2012-02-29 -> 2013-03-01 = 366 total, 1 year
2012-03-01 -> 2013-03-01 = 365 total, 11 months, 30 days
2013-03-02 -> 2013-03-02 = 365 total, 1 year



>
> Should we consider this as a bug or not?


Seems like it; the total days is correct in all cases, but the breakdown
doesn't look right.

---

## #70588 — Derick Rethans — 2013-12-11T10:13:07+00:00

URL: https://externals.io/message/70586#70588 · In reply to: #70586

> Hi,
> 
> today I stumbled upon this bug, but I actually don't know should I call it bug
> or is it right behavior?
> 
> So for example lets get diff between 2013-10-25 and 2014-10-25:
> var_dump((new DateTime("2013-03-25"))->diff(new DateTime("2014-03-25")))
> 
> We'll get one full year.
> 
> Then if we try to get diff between 2012-03-25 and 2013-03-25 we'll also get
> one year.
> 
> But if we have 2012-03-01 and 2013-03-01 then we get 11 months and 30 days
> (365 in int->days member)...
> 
> Should we consider this as a bug or not?

I did some fixes for this already - which version of PHP is this?

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

---

## #70589 — Nikita Nefedov — 2013-12-11T11:42:36+00:00

URL: https://externals.io/message/70586#70589 · In reply to: #70588

> 
>
> > […]
>
> I did some fixes for this already - which version of PHP is this?
>
> cheers,
> Derick
>

Hi Derick,

I can reproduce this on 5.5.7RC1 tag. (can't check it on the other  
versions at the moment)

---

## #70590 — Derick Rethans — 2013-12-11T12:50:31+00:00

URL: https://externals.io/message/70586#70590 · In reply to: #70589

> 
> 
> > […]
> 
> I can reproduce this on 5.5.7RC1 tag. (can't check it on the other 
> versions at the moment)

Please file a bug. I'll try to get at it at the weekend (don't you love 
christmas hacking time!)

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
