Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- getDifference(date_posted: number): string{
- var ret = '';
- var time = Math.abs(date_posted - Date.now());
- var weeks = 0, days = 0, hours = 0, minutes = 0;
- if(time >= this.one_week){
- weeks = Math.abs(Math.floor(time / this.one_week));
- time = time % this.one_week;
- }
- if(time >= this.one_day){
- days = Math.abs(Math.floor(time / this.one_day));
- time = time % this.one_day;
- }
- if(time >= this.one_hour){
- hours = Math.abs(Math.floor(time / this.one_hour));
- time = time % this.one_hour;
- }
- minutes = Math.abs(Math.round(time / this.one_minute));
- if(weeks > 0){
- ret = weeks + " w " + days + " d ago";
- }
- else if(days > 0){
- ret = days + " d " + hours + " h ago";
- }
- else if(hours > 0){
- ret = hours + " h " + minutes + " m ago";
- }
- else{
- ret = minutes + " m ago";
- }
- return ret;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement