[buddypress-trac] [BuddyPress] #5017: bp_core_time_since() returns "x minutes" when it means "x minutes, y seconds"
buddypress-trac
noreply at wordpress.org
Fri May 24 13:20:22 UTC 2013
#5017: bp_core_time_since() returns "x minutes" when it means "x minutes, y
seconds"
--------------------------+-------------------------
Reporter: boonebgorges | Owner:
Type: defect (bug) | Status: new
Priority: lowest | Milestone: 1.8
Component: Core | Version: 1.0
Severity: trivial | Keywords: 2nd-opinion
--------------------------+-------------------------
In writing unit tests for #5015, I found that `bp_core_time_since( $now,
$three_minutes_thirty_seconds_ago )` returns "3 minutes ago" rather than
"3 minutes, 30 seconds ago".
This behavior is a result of line
https://buddypress.trac.wordpress.org/browser/tags/1.7.2/bp-core/bp-core-
functions.php#L504, where the comparison check is `( $i + 2 < $j )`.
'seconds' is the last item in the array (of which `$j` is a `count()`),
and so when you get to this point in the iteration, the less-than test
fails. Changing it to `<=` fixes the issue, without affecting any other
time combinations.
I took a spin through the changelog (it was a doozy) and found that the
function has behaved this way since introduced in r204. I'm assuming it
was copied over from somewhere else.
I don't think that this behavior is *intended*. However, I do think that
it's *better* than the intended behavior, because really, who cares about
the difference between 3 minutes and 3 minutes, 30 seconds?
If everyone is in agreement that the current behavior is better, I'll just
write better inline docs and change my failing test. Otherwise, we can
make the <= change suggested above and "fix" the underlying issue (though
this may annoy users).
In the long run (and this is a topic for another ticket) it might be nice
to allow bp_core_time_since() to accept a param or a filter that lets you
set which time intervals will be split into two sections, and which will
be collapsed into a single section.
--
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/5017>
BuddyPress <http://buddypress.org/>
BuddyPress
More information about the buddypress-trac
mailing list