Skip to content

Instantly share code, notes, and snippets.

@jorinvo
Last active November 12, 2015 05:18
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 jorinvo/b4eaa64bca5348aa2709 to your computer and use it in GitHub Desktop.
Save jorinvo/b4eaa64bca5348aa2709 to your computer and use it in GitHub Desktop.
Compare timeago
module.exports = {
emptyDoc: 'Write …',
search: 'Search …',
footer: 'write lite, open source',
share: 'share',
open: 'open',
modified: 'modified',
welcome: require('./welcome.txt'),
secondsAgo: function (x) {
if (x === 1) return 'a second ago';
return x + ' seconds ago';
},
minutesAgo: function (x) {
if (x === 1) return 'a minute ago';
return x + ' minutes ago';
},
hoursAgo: function (x) {
if (x === 1) return 'an hour ago';
return x + ' hours ago';
},
daysAgo: function (x) {
if (x === 1) return 'a day ago';
return x + ' days ago';
},
monthsAgo: function (x) {
if (x === 1) return 'a month ago';
return x + ' months ago';
},
yearsAgo: function (x) {
if (x === 1) return 'a year ago';
return x + ' years ago';
}
};
function plural(word, num) {
var forms = word.split('_');
return num === 1 ? forms[0] : forms[1];
}
module.exports = {
emptyDoc: 'Write …',
search: 'Search …',
footer: 'write lite, open source',
share: 'share',
open: 'open',
modified: 'modified',
welcome: require('./welcome.txt'),
timeAgo: function relativeTimeWithPlural(number, key) {
var format = {
'ss': 'second_seconds',
'mm': 'minute_minutes',
'hh': 'hour_hours',
'dd': 'day_days',
'MM': 'month_months',
'yy': 'year_years'
};
if (number === 1) {
return 'a ' + plural(format[key], +number) + ' ago';
}
else {
return number + ' ' + plural(format[key], +number) + ' ago';
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment