Loading twitter status...

When I signed up for twitter not too long ago, they had a nice item right in their xml file called relative_created_at that would return a time in relation to ‘now’ instead of the ugly ‘created_at’ which is a normal timestamp. The have since removed this item from their xml file (for caching reasons that are very understandable) so I went ahead and created a tiny plugin that provides you with a filter to use that form of time in any of your liquid plugins. You can pass any date as a string and this filter will convert the string to a Ruby date object and return the relative time from now that the date was. Check out the README or the source.

script/plugin install -x http://svn.dnite.org/mephisto_relative_time

The installation is quite easy. Just run the above and restart mephisto. To use the filter in your blog, do one of the following in any liquid template file.

Something happened {{ date_variable | relative_time_ago }} ago.
My birthday was {{ "2006-07-17" | relative_time_ago }} ago.
My birthday is coming up in {{ "2007-07-17" | relative_time_to }}
date_variable is just some liquid variable that contains a string with a date in it. The other 2 are examples that you can create any date in a string as long as Ruby can convert it correctly into a date object. The relative_time_ago function will return how long in the past from now said date happened, and the relative_time_to method will give you roughly how long until said date is reached. Piece of cake, eh? Now have fun with it!

Leave a Comment

back to top

micro theme by seaofclouds, edited by me, and powered with Mephisto