Time ago/since (formatted time as words)
This is an open discussion with 9 replies, filed under XSLT.
Search
Awesome, Nick, thanks a bunch.
Nick, this is so sweet!
Just wait for the any-number-to-words template that's coming :-)
Thanks! I tried to do this a while ago, but failed miserably. I'm checking this out. :-)
Fixed a bug whereby the number appeared when the "about a year" condition was met. Gist updated.
Seems to have been moved to http://www.getsymphony.com/downloads/xslt/file/20484/. Thanks Nick, works like a charm.
Updated the link. Glad it works for you :-)
This forum uses a modified version for the “Last Active” time in the discussion list.
To incorporate timezone differences you can modify the “now” variable:
<xsl:variable name="now" select="concat($today, 'T', $current-time, ':00', $timezone)" />
This fixed a problem where I was importing a feed including a published date with time zone -07:00 in my website with time zone +02:00, and the time was off by 2 hours. Apparently, XSL assumes a time zone of +00:00 by default.
Just added some extra niceness for this script:
Create an account or sign in to comment.
Ruby on Rails has a handy function time_ago_in_words() to compare two dates and return the difference as words; “about one minute ago”, “2 hours ago”, “4 months from now” and so on.
I’ve ported this to an XSLT template for use within Symphony and added support for dates in the future as well as the past.
Download
http://www.getsymphony.com/downloads/xslt/file/20484/
Usage
Add the
time-ago.xsl
stylesheet to your Utilities and include it in the normal way. Call thetime-ago
template passing a valid ISO date (YYYY-MM-DDThh:mm:ss):In the example above I have a Date field named “Publish Date”. I could have made the template accept just the date XML node itself, but I wanted to use this template in cases where dates are annoyingly stored as Text fields as well (and therefore not formatted with the time attribute in the XML).
Dependencies
$current-time
in the Params list)