Advertisement
Imgoodisher

CC Clock

Jan 9th, 2013
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.24 KB | None | 0 0
  1. local function _getTime(format)
  2.     local response = http.post(
  3.         "http://www.imgood.webege.com/time.php",
  4.         "format="..textutils.urlEncode(format)
  5.     )
  6.     return response:readLine()
  7. end
  8.  
  9. local function getTime()
  10.     local start = _getTime("h:i:s")
  11.     sleep(1)
  12.     local stop = _getTime("h:i:s - D, M d, Y - T")
  13.    
  14.     print(start..", "..stop)
  15.     local hs, ms, ss = string.match(start, "(%d+):(%d+):(%d+)")
  16.     local he, me, se, date, timezone = string.match(stop, "^(%d-):(%d-):(%d-)%s?-%s?([%w,%s]-)%s?-%s?(%w+)$")
  17.     print(tostring(he)..", "..tostring(me))
  18.     hs, ms, ss, he, me, se = tonumber(hs), tonumber(ms), tonumber(ss), tonumber(he), tonumber(me), tonumber(se)
  19.    
  20.     local startSec = ss + ((ms + (hs * 60)) * 60)
  21.     local endSec = se + ((me + (he * 60)) * 60)
  22.    
  23.     return endSec - startSec, he, me, se, date, timezone
  24. end
  25.  
  26. local function addZero(n)
  27.     if tostring(n):len() == 1 then
  28.         return "0"..tostring(n)
  29.     else
  30.         return tostring(n)
  31.     end
  32. end
  33.  
  34. while true do
  35.     local sec, h, m, s, date, timezone = getTime()
  36.     for i = 1, 10 do
  37.         for i=1, 60 do
  38.             term.clear()
  39.             term.setCursorPos(2, 2)
  40.             print(h..":"..addZero(m)..":"..addZero(s).." "..timezone.." - "..date)
  41.             sleep(sec)
  42.             s = s + 1
  43.             if s >= 60 then
  44.                 s = 0
  45.                 m = m + 1
  46.             end
  47.         end
  48.     end
  49. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement