Advertisement
Guest User

Untitled

a guest
Jan 21st, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. getDifference(date_posted: number): string{
  2.     var ret = '';
  3.     var time = Math.abs(date_posted - Date.now());
  4.     var weeks = 0, days = 0, hours = 0, minutes = 0;
  5.     if(time >= this.one_week){
  6.       weeks = Math.abs(Math.floor(time / this.one_week));
  7.       time = time % this.one_week;
  8.     }
  9.     if(time >= this.one_day){
  10.       days = Math.abs(Math.floor(time / this.one_day));
  11.       time = time % this.one_day;
  12.     }
  13.     if(time >= this.one_hour){
  14.       hours = Math.abs(Math.floor(time / this.one_hour));
  15.       time = time % this.one_hour;
  16.     }
  17.     minutes = Math.abs(Math.round(time / this.one_minute));
  18.  
  19.     if(weeks > 0){
  20.       ret = weeks + " w " + days + " d ago";
  21.     }
  22.     else if(days > 0){
  23.       ret = days + " d " + hours + " h ago";
  24.     }
  25.     else if(hours > 0){
  26.       ret = hours + " h " + minutes + " m ago";
  27.     }
  28.     else{
  29.       ret = minutes + " m ago";
  30.     }
  31.     return ret;
  32.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement