Created
July 3, 2019 08:20
-
-
Save sdesalas/ea4377a8f2f6e9b64e10f8d9881d9b5d to your computer and use it in GitHub Desktop.
Time Ago Dojo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const moment = require('moment') | |
// TRABAJAR AQUI | |
module.exports = function timeago(date){ | |
return moment(date).fromNow() | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const assert = require('assert'); | |
const timeago = require('./index'); | |
const ONE_SECOND = 1000; | |
const ONE_MINUTE = ONE_SECOND * 60; | |
const ONE_HOUR = ONE_MINUTE * 60; | |
const ONE_DAY = ONE_HOUR * 24; | |
const ONE_WEEK = ONE_DAY * 7; | |
// TEST 1: | |
// Input Date('2019-06-03T06:00:00.000Z') | |
// Output '3 hours ago' | |
describe('Test time', () => { | |
it('Should return 3 hours ago', () => { | |
const date = new Date(new Date() - 3 * ONE_HOUR) | |
assert.equal(timeago(date), '3 hours ago'); | |
}) | |
}); | |
// TEST 2: | |
// Input Date('2019-06-01T06:00:00.000Z') | |
// Output '2 days ago' | |
describe('Test time', () => { | |
it('Should return 2 days ago', () => { | |
const date = new Date(new Date() - 2 * ONE_DAY) | |
assert.equal(timeago(date), '2 days ago'); | |
}) | |
}); | |
Author
sdesalas
commented
Jul 3, 2019
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment