Skip to content

Instantly share code, notes, and snippets.

@sdesalas
Created July 3, 2019 08:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sdesalas/ea4377a8f2f6e9b64e10f8d9881d9b5d to your computer and use it in GitHub Desktop.
Save sdesalas/ea4377a8f2f6e9b64e10f8d9881d9b5d to your computer and use it in GitHub Desktop.
Time Ago Dojo
const moment = require('moment')
// TRABAJAR AQUI
module.exports = function timeago(date){
return moment(date).fromNow()
}
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');
})
});
@sdesalas
Copy link
Author

sdesalas commented Jul 3, 2019

mkdir timeago && cd timeago
npm init -y
touch index.js && touch test.js
npm install jest
code .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment