Thursday, August 4, 2011

ServerSide JavaScript Date Nonsense

Hi.

I want to format some dates in my Express views.

First of all, my employer, i.TV, has a DateTime library that we wrote that is alright:
https://gist.github.com/1125717

But I was hoping this would be something that's more in the view layer than than in the model/controller level.

Here are some libraries and functions that do some version of that:
http://www.datejs.com/
https://github.com/Flamefork/underscore.date
https://github.com/cdcarter/commonjs-date-formatting
http://timeago.yarp.com/

However, none of them did what I wanted. Here is one that did:
http://ejohn.org/blog/javascript-pretty-date/

This is what I did to make it work in my express views:

5 comments:

  1. Hey Jamund,
    Here's a modification to John's script that you might like:
    https://github.com/zachleat/Humane-Dates

    You can check out the tests to see if it meets your needs:
    https://github.com/zachleat/Humane-Dates/blob/master/src-test/humaneDatesTest.js

    ReplyDelete
  2. I wrote a library for date modification called underscore.date that does this same thing. I handles parsing, formatting, and timeago.

    It also handles i18n, so you can customize all the strings.

    https://github.com/timrwood/underscore.date

    ReplyDelete
  3. @washwithcare. your library looks awesome too!

    ReplyDelete
  4. This comment has been removed by a blog administrator.

    ReplyDelete