Advertisement
JoackoBengochea

Time Ago Function

May 20th, 2016
1,232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haxe 0.86 KB | None | 0 0
  1. public static function timeAgo(time:Float):String {
  2.         var arr:Array<Array<Dynamic>> = [
  3.                 ["month_ago", "months_ago", 4*7*24*60*60000.0, 4*7*24*60*60000.0],
  4.                 ["week_ago", "weeks_ago",     7*24*60*60000.0, 2*7*24*60*60000.0],
  5.                 ["day_ago", "days_ago",         24*60*60000.0, 24*60*60000.0],
  6.                 ["hour_ago", "hours_ago",          60*60000.0, 60*60000.0],
  7.                 ["minute_ago", "minutes_ago",         60000.0, 60000.0],
  8.                 ["second_ago", "seconds_ago",          1000.0, 2000.0]
  9.         ];
  10.         for (t in arr){
  11.                 if(time>t[3]){
  12.                     if(Std.int(time/t[2]) > 1 ) return Localization.get(t[1], [ Std.string(Std.int(time/t[2])) ]);
  13.                     return Localization.get(t[0]);
  14.                 }
  15.         }
  16.         return Localization.get("second_ago");
  17.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement