Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function getDiff(t)
- return t - os.epoch("utc") / 1000
- end
- local function dispTime(t)
- t = math.abs(t)
- local y = math.floor(t / 31536000)
- local mo = math.floor((t % 946080000) / 31536000)
- local d = math.floor((t % 31536000) / 86400)
- local h = math.floor((t % 86400) / 3600)
- local m = math.floor((t % 3600) / 60)
- local s = math.floor((t % 60))
- return y, mo, d, h, m, s
- end
- local function getDistanceFrom(nTime)
- local diff = getDiff(nTime)
- local y, mo, d, h, m, s = dispTime(diff)
- if diff > 0 then
- if y > 1 then
- return ("in %d years"):format(y), 0
- elseif y == 1 then
- return ("in 1 year"), 0
- elseif d > 1 then
- return ("in %d days"):format(d), 0
- elseif d == 1 then
- return "tommorow", 0
- elseif h == 1 then
- return "in 1 hour", 0
- elseif h > 0 then
- return ("in %d hours"):format(h), 0
- elseif m == 1 then
- return "in 1 minute", 0
- elseif m > 0 then
- return ("in %d minutes"):format(m), 0
- elseif s == 1 then
- return "in 1 second", 0
- elseif s > 0 then
- return ("in %d seconds"):format(s), 0
- else
- return "in 0 seconds", 0
- end
- elseif diff < 0 then
- if y > 1 then
- return ("%d years ago"):format(y), 1
- elseif y == 1 then
- return ("1 year ago"), 1
- elseif d > 1 then
- return ("%d days ago"):format(d), 1
- elseif d == 1 then
- return "yesterday", 1
- elseif h == 1 then
- return ("1 hour ago"), 1
- elseif h > 0 then
- return ("%d hours ago"):format(h), 1
- elseif m == 1 then
- return ("1 minute ago"), 1
- elseif m > 0 then
- return ("%d minutes ago"):format(m), 1
- elseif s >= 30 then
- return ("%d seconds ago"):format(s), 1
- else
- return "just now", 1
- end
- else
- return "just now"
- end
- end
- return getDistanceFrom
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement