Needs work
Project:
Drupal core
Version:
main
Component:
comment.module
Priority:
Minor
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
13 Jan 2012 at 03:59 UTC
Updated:
25 Mar 2025 at 02:32 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
Everett Zufelt commentedFeature requests are made against Drupal 8.x
Comment #2
dman commentedSounds easy. Tagging as novice as a good exercise in patching.
The question stands whether everyone WANTs to do this - and there may be some discussion needed.
However, the discussion can start on a good basis if someone can provide a patch that actually does the change.
Comment #3
dman commentedTagging for code sprint DDU2012
Comment #4
gro commentedIt does sound easy (and cool!) but turns out not to be a simple string replacement.
The different modules that add the time in this fashion (ie comment) use '@time' (defined by format_interval) and append 'ago' so to change this would require a new function similar to format_interval that could define 'human readable' terms. That could possibly be inappropriate for a core feature request because it's not a functionality improvement and more appropriate as a module.
...but I'm a total novice
Comment #5
dman commentedYeah, we looked at this together and came to the conclusion that to do it "right" would require an additional util function in the family of format_date(), format_duration() - we could also have format_age() in order to provide full, nice support for ["just now", "yesterday", "1 hour ago", etc].
While that would be cool, and a cute project - right now it would also mean touching a few too many places that currently use t('@time ago', ...) as their string constructs.
If folk would like to say "YES, it would be nice to support a set of configurable, translatable, human text strings to represent age" then this work would be nice to do.
But I'd rather test the water and sniff out if there is any chance it would be accepted before suggesting this functionality be developed further.
It can't practically be added as a contrib module (that I can see) ... as I can't see that we could leverage or intercept the t() call enough to rewrite it like that.
Comment #6
jtbayly commentedAs a novice, looking for a place to try out submitting new patches, I'm going to go out on a limb and remove the "novice" tag from this issue. :)
-Joseph
Comment #7
scorchio commentedLet's see how this patch looks. The result is kinda rough, but it's working reasonably well on the recent comments block for example.
Based on dman's suggestions in #5 I've created format_age() and modified the code at several places where "@time ago" was used with format_interval().
Comment #8
tstoecklerNice, that looks quite good already.
A couple notes:
1. $timestamp is not actually a timestamp. Let's call it $interval or $seconds or something. Actually looking at the patch, it is being called with
REQUEST_TIME - $timestampevery single time. So perhaps we should inline that in this function. I.e.:In that case $timestamp would be fine.
2. Instead of calling format_plural() with the singular/plural strings manually, I think it's better to call format_interval() for that. That would allow to simplify the function a bit. Something like:
3. It was suggested above to support things like "Last year" instead of "1 year ago" as well. Don't know how that would fit in, but wanted to mention that.
Comment #9
dman commentedMoving ahead.
Some notes, I think that the t() in
in a few places is redundant.
And I agree that it would be helpful to do the $interval = REQUEST_TIME - $timestamp; for them as tstoeckler suggests. Less redundancy.
That leaves us with just
I'm not sure how translation will deal with
sort of things (I'll assume it all works as required), but it's taking shape.
Ideally, I imagined that there would be a admin-defined sort of granularity so we can choose between "12 hours ago" and "today" depending on preferences. But I don't really know the best algorithm for that sort of flexibility. Or imagine the UI for it. I'm sure there is some prior art on that.
Comment #10
scorchio commentedtstoeckler: sure, $timestamp should be $interval. I've copied that part from format_interval() for starting the patch, so actually this is two minor issue in one :) See #1416218: Improve variable naming in format_interval().
About calling format_interval(): if we would like to display text like "last year" (as my current patch does), we shouldn't call format_interval() - both the English and different localized texts will differ in the two functions.
This patch implements suggestions from #8 and #9. Do you have any ideas on how to improve it further?
Comment #12
tstoecklerI think it makes sense to initizialize the array reversely, so that you don't have to explode the $key. I.e.:
That's what "yesterday" means. :) (Not trying to make fun of you (!), I just had to smile reading that.)
If I read the code below correctly, "a second ago" weill never be called, right?
We don't do the short syntax for if clauses, that should be split into multiple lines. More importantly, though, I don't really like this. :) I think we could merge the part below (the 'just now' part) and cut this part. That would make the whole thing easier to read.
Comment #13
scorchio commentedPlease correct me if I'm wrong, but as I actually use "yesterday" in daily life, it means the last day in the calendar: midnight to midnight. If we modify "a day ago" to "yesterday" it could lead to some confusion, let me show you an example:
If it's actually 6AM...
Comment #14
dman commentedTrue enough. If we are aiming for fully natural language (which I feel is starting to get tricky) then at 1AM a post made 2 hours ago is "yesterday".
My local TV station confuses me when it does this in reverse and an ad comes on at 1AM for shows that will be on "tonight" - meaning the following evening. Anyway.
Yes, I think what scorchio is saying is right. (a day ago/yesterday) isn't just the span of time between now-24 and now-48 .
I knew we'd get into trouble :-)
I tried a really quick search and found things like
http://stackoverflow.com/questions/11/how-do-i-calculate-relative-time
http://www.php.net/manual/en/function.strtotime.php#100773
http://www.ferdychristant.com/blog//archive/DOMM-7QEFK4
And see more quibbles than agreements on the 'right way'. Hm :-(
It seems there is even a jquery solution for it http://timeago.yarp.com/
.. which conveniently manages future times also!!
Could be worth comparing with that algorithm there
https://github.com/rmm5t/jquery-timeago/blob/master/jquery.timeago.js
Comment #15
mototribe commentedwow, I had no idea that my little suggestion created that much work ;-)
Personally, I like the Stackoverflow solution.
Comment #16
scorchio commentedI will check out that timeago plugin and play around with it for a little - it looks nice.
Comment #17
tstoecklerOh yes, you are of course correct. Stupid me!
To calculate whether it is "yesterday" or not, we could use something like
That's just one way, though, if anything else is easier/better/etc. that's fine. It just seemed more intuitive to me, because that way we can hand down the calculation of the day down to PHP.
Comment #18
scorchio commentedI wonder how much we would like to "humanize" our date intervals. Implementing "yesterday" is one thing, but then we should have "last month" instead of "a month ago", "last year" instead of "a year ago" etc. That would mean we should find similar "workarounds" for each one, like in #17.
I don't know which way would be the better, what do you think?
I've checked Timeago and it looks nice, so here is a patch which implements Timeago's algorithm modified a little bit (so we have "just now").
Also,
format_age()in the patch has $end, an optional timestamp argument which defaults toREQUEST_TIME. What do you think about this? Is there situations when setting a different "reference point" could be useful?The thing I really like in Timeago is the idea of implementing fuzzy time calculation on the client's side - every age stays up-to-date all the time. What do you think about having a similar solution in Drupal?
p.s. I'm trying to follow the coding standards as much as possible, so any further advice on that is very welcome.
Comment #20
scorchio commented#18: show_just_now-1403508-18.patch queued for re-testing.
Comment #21
wryz commented#18: show_just_now-1403508-18.patch queued for re-testing.
Comment #23
PavanL commentedComment #24
xjm(Merging "node system" and "node.module" components for 8.x; disregard.)
Comment #25
Robin_K commentedI quite like this idea, I'm going to try to convert this patch into something usable for the current dev.
Comment #28
yoroy commentedStill like this idea :)
Comment #40
aditi saraf commentedAccording to me Fr time interval <= 1 second we should show just now . For rest Drupal it self is handling .
Comment #41
aditi saraf commentedComment #42
smustgrave commentedSeems to contain a lot of out of scope changes.
If a different solution is going to be used the issue summary needs to be updated.
Also no test coverage.
Comment #44
acbramley commentedThe current patch is just changing the output for comments in Olivero, it doesn't seem like there would be a way to do this generically for all themes.
I also can't see any similar strings related to node so moving to comment.module