Closed Bug 1920995 Opened 4 months ago Closed 4 months ago

wrong calculation of relative date (rel-time) caused by repeatedly rounding in time_ago

Categories

(bugzilla.mozilla.org :: General, defect)

Production
defect

Tracking

()

RESOLVED FIXED

People

(Reporter: me, Assigned: me)

Details

Attachments

(2 files)

Attached image date-bug.png

Steps to reproduce:

View this page https://bugzilla.mozilla.org/show_bug.cgi?id=1704404 today.
Today is 2024-09-25.

Look at the "relative" or "human-readable" date of the bug description. And mouse hover it.

Actual results:

It shows "4 years ago" and "2021-04-11" and today is 2024-09-25. Screenshot attached.

Expected results:

It should show "3 years ago" or "3 years 5 months 14 days ago" or "3.46 years ago".
I can't imagine how it can be 4 years since 3.46<3.5 so it can't round up any way.

I have understood the bug.

This bug is caused by time_ago subroutine in Util.pm.
https://github.com/mozilla-bteam/bmo/blob/aa712a4fdff9283bb95ad30a98c6af2204d5738d/Bugzilla/Util.pm#L647

At the time of my post, the time delta was 3 years 5 months 14 days 12 hours and some minutes. This function first rounds up 12 hours to a day. Then together with 14 days it becomes 15 days. Then with 5 months it becomes 6 months. Then with 3 years it becomes 4 years. So I was very lucky to find this bug at this particular time. Should I visited the page an hour earlier, it wouldn't be visible.

The correct way is always use the original seconds to calculate the minutes/hours/days/months/years, instead of rounding it repeatedly.

Summary: wrong calculation of relative date (rel-time) → wrong calculation of relative date (rel-time) caused by repeatedly rounding in time_ago
Assignee: nobody → me
Status: UNCONFIRMED → RESOLVED
Closed: 4 months ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: