Datejs getting the difference between dates
<p>So here is my goal, I want to get how long ago a certain date was as a pretty readable string. Something like: '4 day and 3 hours ago'. I am using datejs and have both my dates currently as epochs. </p>

<p>I know I could subtract one epoch from the other, take the difference and then manually calculate the string to output. But this feels like something datejs would handle. However I see no documentation (of any js lib for that matter) expressing a means of converting a date object, or an epoch to a quantity of time.</p>

<p>any ideas, on how this best should be handled?</p>

<p><strong>UPDATE</strong></p>

<p>Let me be more clear. When I say human readable that means </p>

<ul>
<li>1 day ago is 'yesterday'</li>
<li>2 days go is '2 days ago'</li>
<li>30 seconds ago is 'just now'</li>
<li>1 year and 3 days and 12 seconds ago is '1 year ago'</li>
</ul>

<p><strong>What I ended up doing</strong></p>

<pre><code>    prettyAgo = (ago) -&gt;
        ago = ago.getTime() if typeof ago is 'object'
        diff = ((new Date()).getTime() - ago) / 1000
        dayDiff = Math.floor(diff / 86400)
        return false if isNaN(dayDiff) or dayDiff &lt; 0

        writer = ''

        if dayDiff is 0
            if diff &lt; 1 then writer             = 'just now'
            else if diff &lt; 60 then writer       = Math.floor(diff)+' seconds ago'
            else if diff &lt; 120 then writer      = '1 minute ago'
            else if diff &lt; 3600 then writer     = Math.floor(diff / 60)+' minutes ago'
            else if diff &lt; 7200 then writer     = '1 hour ago'
            else if diff &lt; 86400 then writer    = Math.floor(diff / 3600)+' hours ago'
        else if dayDiff is 1 then writer        = 'yesterday'
        else if dayDiff &lt; 7 then writer         = dayDiff+' days ago'
        else if dayDiff is 7 then writer        = '1 week ago'
        else if dayDiff &lt; 31 then writer        = Math.ceil( dayDiff / 7 )+' weeks ago'
        else writer                             = new Date(ago).toString 'MMM yyyy'

        return writer
</code></pre>
