Advertisement
znepb

Untitled

Dec 31st, 2020
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. local function getDiff(t)
  2. return t - os.epoch("utc") / 1000
  3. end
  4.  
  5. local function dispTime(t)
  6. t = math.abs(t)
  7. local y = math.floor(t / 31536000)
  8. local mo = math.floor((t % 946080000) / 31536000)
  9. local d = math.floor((t % 31536000) / 86400)
  10. local h = math.floor((t % 86400) / 3600)
  11. local m = math.floor((t % 3600) / 60)
  12. local s = math.floor((t % 60))
  13. return y, mo, d, h, m, s
  14. end
  15.  
  16. local function getDistanceFrom(nTime)
  17. local diff = getDiff(nTime)
  18. local y, mo, d, h, m, s = dispTime(diff)
  19.  
  20. if diff > 0 then
  21. if y > 1 then
  22. return ("in %d years"):format(y), 0
  23. elseif y == 1 then
  24. return ("in 1 year"), 0
  25. elseif d > 1 then
  26. return ("in %d days"):format(d), 0
  27. elseif d == 1 then
  28. return "tommorow", 0
  29. elseif h == 1 then
  30. return "in 1 hour", 0
  31. elseif h > 0 then
  32. return ("in %d hours"):format(h), 0
  33. elseif m == 1 then
  34. return "in 1 minute", 0
  35. elseif m > 0 then
  36. return ("in %d minutes"):format(m), 0
  37. elseif s == 1 then
  38. return "in 1 second", 0
  39. elseif s > 0 then
  40. return ("in %d seconds"):format(s), 0
  41. else
  42. return "in 0 seconds", 0
  43. end
  44. elseif diff < 0 then
  45. if y > 1 then
  46. return ("%d years ago"):format(y), 1
  47. elseif y == 1 then
  48. return ("1 year ago"), 1
  49. elseif d > 1 then
  50. return ("%d days ago"):format(d), 1
  51. elseif d == 1 then
  52. return "yesterday", 1
  53. elseif h == 1 then
  54. return ("1 hour ago"), 1
  55. elseif h > 0 then
  56. return ("%d hours ago"):format(h), 1
  57. elseif m == 1 then
  58. return ("1 minute ago"), 1
  59. elseif m > 0 then
  60. return ("%d minutes ago"):format(m), 1
  61. elseif s >= 30 then
  62. return ("%d seconds ago"):format(s), 1
  63. else
  64. return "just now", 1
  65. end
  66. else
  67. return "just now"
  68. end
  69. end
  70.  
  71. return getDistanceFrom
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement