-
Notifications
You must be signed in to change notification settings - Fork 317
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
What about timeago.js ? #90
Comments
TimeAgo does not allow you to manipulate dates, like add, subtract, check if a given date is inside or not a given gap... all it seems to be doing if leverage the |
You are right, but it is a perfect alternative if you only need to print out the elapsed time, no? |
... the vanilla JS version for that functionality alone is a ~10-15 line JS snippet. export function ago(timestamp: Number, max = 5) {
var strTime = ["second", "minute", "hour", "day", "month", "year"];
var length = ["60", "60", "24", "30", "12", "10"];
var diff:any = Math.floor(Date.now() / 1000) - timestamp;
if (diff >= 0) {
for (var i = 0; diff >= length[i] && i < max - 1; i++) {
diff = diff / length[i]
}
diff = Math.round(diff);
return diff + " " + strTime[i] + (diff > 1 ? "s" : "") + " ago";
}
} |
Another approach I found useful combining with the native Intl.RelativeTimeFormat:
Works for times in the past and future always showing the smallest time unit that is smaller than the unit limit, e.g.
|
What about timeago.js as alternative (2kb) ?
https://github.com/hustcc/timeago.js
The text was updated successfully, but these errors were encountered: