JoackoBengochea

Time Ago Function

May 20th, 2016
490
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.     }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×