Skip to content

Instantly share code, notes, and snippets.

@randallb
Created July 29, 2013 20:08
Show Gist options
  • Save randallb/6107329 to your computer and use it in GitHub Desktop.
Save randallb/6107329 to your computer and use it in GitHub Desktop.
describe 'relativeDate', ->
beforeEach module 'relativeDate'
it 'should return `just now` if the date is within the last minute', inject (relativeDate) ->
referenceDate = new Date
console.log referenceDate
expect(relativeDate(referenceDate)).toBe("just now")
it 'should return `a minute ago` if the date is older than 7/10ths of a minute but less than 1.5 minutes'
it 'should return `x minutes ago` if the date is older than 1.5 minutes but less than 55 minutes'
it 'should return `an hour ago` if the date is more than 55 minutes ago'
it 'should return `x hours ago` if the date is more than 2 hours'
it 'should return `this morning` if the time is more than 12 hours and the date is today'
it 'should return `yesterday morning` if the date is more than 12 hours, and it happened yesterday before 12pm'
it 'should return `yesterday evening` if the date is more than 12 hours, and it happened yesterday after 12pm'
it 'should return `(day of week) morning / evening` if the date is older than 1 day and happens in the same week'
it 'should return `(Month) (dd)` if the date is not this week'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment