Skip to content

Commit

Permalink
Added optional parameter to ago to allow short output
Browse files Browse the repository at this point in the history
  • Loading branch information
Limero committed Jun 22, 2016
1 parent 21cdaa2 commit 19ec863
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -17,5 +17,5 @@
"type": "git",
"url": "git://github.com/dpweb/time-ago.git"
},
"version": "0.1.1"
"version": "0.1.2"
}
8 changes: 7 additions & 1 deletion test.js
Expand Up @@ -7,7 +7,13 @@ var ta = (typeof module !== 'undefined' && module.exports) ?
console.log(
ta.ago(new Date() - 1000), ta.ago(new Date() - 1000) === '1 second ago',
ta.ago(new Date() - 60000 * 180), ta.ago(new Date() - 60000 * 180) === '3 hours ago',
new Date(1), ta.ago(new Date(1)), ta.ago(new Date(1)) === '45 years ago'
new Date(1), ta.ago(new Date(1)), ta.ago(new Date(1)) === '47 years ago'
);

console.log(
ta.ago(new Date() - 1000, true), ta.ago(new Date() - 1000, true) === '1s',
ta.ago(new Date() - 60000 * 180, true), ta.ago(new Date() - 60000 * 180, true) === '3h',
new Date(1), ta.ago(new Date(1), true), ta.ago(new Date(1), true) === '47y'
);

console.log(
Expand Down
4 changes: 2 additions & 2 deletions timeago.js
Expand Up @@ -13,10 +13,10 @@ var timeago = function() {
};
var obj = {};

obj.ago = function(nd) {
obj.ago = function(nd, s) {
var r = Math.round,
pl = function(v, n) {
return n + ' ' + v + (n > 1 ? 's' : '') + ' ago'
return (s === undefined) ? n + ' ' + v + (n > 1 ? 's' : '') + ' ago' : n + v.substring(0, 1)
},
ts = new Date().getTime() - new Date(nd).getTime(),
ii;
Expand Down

0 comments on commit 19ec863

Please sign in to comment.