Search code examples
javascriptjquerytimeago

jQuery TimeAgo library to change color of Text if the DateTime is in the Past?


I am using the Yarp jQuery TimeAgo library in my new App in which I am showing relative timing for a Task records Due Date field.

What I want to do is simply show the date/time value as RED Text once the set Due Date value is in the past tense based on the current date.

So real simple, Future Due Date will show default green text set with CSS on the page:
enter image description here

Past Due Date will show Red text:

enter image description here

The library can be found here: http://timeago.yarp.com/

Can anyone help me to color past due text in Red?

The HTML on the page before the library converts it into a future or past DateTime in words looks like this...

<time id="duedatetimeago"></time>

After the library does it's magic on the element, it simply looks like this...

<time id="duedatetimeago">16 days ago</time>  

So you can see no special CSS classes or data attributes or anything are added so it might be difficult to know when the current time is in the past. If you find out "anybody" then please share with me, thank you


Solution

  • Here's a Gist containing modifications to timeago.js - you can change the default past and future colors within the inPastColor variable on line 49