#5017 closed defect (bug) (fixed)
bp_core_time_since() returns "x minutes" when it means "x minutes, y seconds"
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 1.8 | Priority: | lowest |
Severity: | trivial | Version: | 1.0 |
Component: | Core | Keywords: | 2nd-opinion |
Cc: |
Description
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.
Change History (4)
#2
@
12 years ago
This was copied from bbPress's bb_since() function, and then iterated on. I agree that the existing functionality is a fortunate mistake, and that keeping it seems best.
I like the idea of allowing customization of the intervals. I'd like to connect some JS to them, and live-update timestamps in the DOM every 30 seconds, too. Lots we can do with timestamps and time-since in the future to make them more flexible and sexy.
In 7101: