jquery-timeago icon indicating copy to clipboard operation
jquery-timeago copied to clipboard

Add a CSS Class or Style Color to Past DateTime

Open jasondavis opened this issue 9 years ago • 6 comments

In my app that is using this TimeAgo library I would like to style the text with a different color using CSS when the DateTime text is past the current DateTime of today.

So if it says 4 days from now it will be regular just how it is normally.
However if it is in the past like 4 days ago then I could have the text be in a different color like red.

Looking in Chrome Dev tools, it does not appear to add any special CSS class or styles to the time element in which would let me target a past date string.

Does anyone know of a simple way, or anyway really that I could change the text color if the date is in the past?

I saw another post on StackOverflow with the same question buit no answers so far here http://stackoverflow.com/questions/30410273/jquery-timeago-library-to-change-color-of-text-if-the-datetime-is-in-the-past

Any ideas or help?

jasondavis avatar May 23 '15 17:05 jasondavis

I don't think I have a good answer here. There's no direct support for this right now, but it's something I would consider.

Perhaps a timeago-past and timeago-future style class could be added to the elements to represent whether the underlying time is in the past or future.

I'd be willing to accept a clean PR to add this feature.

rmm5t avatar May 26 '15 19:05 rmm5t

+1

chaimleib avatar Jul 06 '15 21:07 chaimleib

Here's a Gist of Timeago with colors for tense. You can change the default blue and red to either a color name of hex value from the inPastColor variable. enjoy

jakerb avatar Aug 28 '15 17:08 jakerb

Thanks, but the Gist does not play nicely with internationalization or custom strings. We need something with deeper integration.

chaimleib avatar Aug 28 '15 18:08 chaimleib

Hi @chaimleib, I've rewritten the Gist for this so it works better for internationalisation. Let me know your thoughts on the update.

jakerb avatar Aug 28 '15 21:08 jakerb

@jakerb does this replace the timeagojs or do we need just to add it as source after timeagojs?

PaoloFalomo avatar May 31 '17 09:05 PaoloFalomo