Skip to content

Commit

Permalink
make sure to format months ago
Browse files Browse the repository at this point in the history
  • Loading branch information
koddsson committed Jun 5, 2019
1 parent a3ca581 commit d307508
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/relative-time.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export default class RelativeTime {
return formatRelativeTime(this.locale, -day, 'day')
} else if (day < 30) {
return formatRelativeTime(this.locale, -day, 'day')
} else if (day < 45) {
} else if (month < 12) {
return formatRelativeTime(this.locale, -month, 'month')
} else if (month < 18) {
return formatRelativeTime(this.locale, -year, 'year')
Expand Down
14 changes: 14 additions & 0 deletions test/time-ago.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@ suite('time-ago', function() {
assert.equal(root.children[0].textContent, 'now')
})

test('rewrites from now past datetime to months ago', function() {
const now = new Date(Date.now() - 3 * 30 * 24 * 60 * 60 * 1000).toISOString()
const time = document.createElement('time-ago')
time.setAttribute('datetime', now)
assert.equal(time.textContent, '3 months ago')
})

test('rewrites from now past datetime to years ago', function() {
const now = new Date(Date.now() - 12 * 30 * 24 * 60 * 60 * 1000).toISOString()
const time = document.createElement('time-ago')
time.setAttribute('datetime', now)
assert.equal(time.textContent, 'last year')
})

test('micro formats years', function() {
const now = new Date(Date.now() - 10 * 365 * 24 * 60 * 60 * 1000).toISOString()
const time = document.createElement('time-ago')
Expand Down

0 comments on commit d307508

Please sign in to comment.