[wp-trac] [WordPress Trac] #38773: Calculation error in human_time_diff
WordPress Trac
noreply at wordpress.org
Sun Nov 13 15:38:10 UTC 2016
#38773: Calculation error in human_time_diff
----------------------------------------+------------------------------
Reporter: SGr33n | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Date/Time | Version:
Severity: normal | Resolution:
Keywords: has-patch needs-unit-tests | Focuses:
----------------------------------------+------------------------------
Comment (by adamsilverstein):
@SGr33n good catch, thanks for opening the ticket.
I did some testing and can see that a difference of 2h, 30m and 1sec
returns 3 hrs, however for 2 years and 1 hour the function returned 2
years. To get 3 years I had to use 2 years six months and a day.
After my testing, I'm not sure floor is actually better there than round,
for example if 1 year 364 days have elapsed, floor will return 1 year
which seems off. Furthermore, the existing behavior has been in core for
12 years, and changing it is likely to impact users who expect it to work
as is. Finally, the `human_time_diff` filter applied on the returned value
enables developers to adjust the default behavior for all uses.
In [attachment:38773.2.diff] I added a few unit tests to verify the
rounding behavior. All three assertions in `test_rounding` will fail
before with `round` vs `floor` because they round up.
[attachment:38773.3.diff] is the unit tests only, adjusted to match the
current core behavior, these will break if the patch is applied.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/38773#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list