Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function split(str, pat)
- local t = {} -- NOTE: use {n = 0} in Lua-5.0
- if str ~= nil then
- local fpat = "(.-)" .. pat
- local last_end = 1
- local s, e, cap = str:find(fpat, 1)
- while s do
- if s ~= 1 or cap ~= "" then
- table.insert(t,cap)
- end
- last_end = e+1
- s, e, cap = str:find(fpat, last_end)
- end
- if last_end <= #str then
- cap = str:sub(last_end)
- table.insert(t, cap)
- end
- else
- print("##CC CHANNELS ERROR: FAILED TO SPLIT by:"..pat)
- end
- return t
- end
- function time(offset) -- Get the time, offset to set the time off by bla bla hours
- if not offset then error("Please enter a number to offset the time by. Use 0 if you dont want to offset it") end
- local Days = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"}
- local Months = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}
- local DaysInMonths = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
- local res = http.get("http://nist.time.gov/timezone.cgi?UTC/s/0/")
- local Res = {}
- local DateFormat = ""
- local bla = ""
- local Date = ""
- local time = ""
- local BlaDate = ""
- local BlaTime = ""
- local BlaDays = ""
- local BlaMonth = ""
- if res then
- while true do
- bla = res.readLine()
- if bla then
- Res[#Res+1] = bla
- else
- break
- end
- end
- res.close()
- Time = string.sub(Res[49], 63, string.len(Res[49])-4)
- Date = string.sub(Res[50], 53, string.len(Res[50])-4)
- DateFormat = {Time}
- for n=1,3 do
- if string.find(Date, ", ") then
- local s,len = string.find(Date, "%, ")
- DateFormat[#DateFormat+1] = string.gsub(string.sub(Date, 1, s), "%,", "")
- Date = string.sub(Date, len+1, string.len(Date))
- end
- end
- DateFormat[#DateFormat+1] = Date
- if string.sub(DateFormat[3], string.len(DateFormat[3])-2, string.len(DateFormat[3])-2) == " " then
- BlaDate = tonumber(string.sub(DateFormat[3], string.len(DateFormat[3])-1, string.len(DateFormat[3])))
- else
- BlaDate = tonumber(string.sub(DateFormat[3], string.len(DateFormat[3]), string.len(DateFormat[3])))
- end
- DateFormat[3] = string.gsub(DateFormat[3], BlaDate, "")
- BlaTime = tonumber(string.sub(DateFormat[1], 1, 2))+tonumber(offset)
- repeat
- if BlaTime > 24 then
- BlaDate = BlaDate+1
- BlaTime = BlaTime-24
- elseif BlaTime < 0 then
- BlaDate = BlaDate-1
- BlaTime = BlaTime+24
- end
- until BlaTime > 0 and BlaTime < 24
- if string.len(BlaTime) == 1 then
- BlaTime = "0"..BlaTime
- end
- end
- DateFormat[4] = tonumber(DateFormat[4])
- BlaMonth = string.gsub(DateFormat[3], " ", "")
- TheDays = BlaDate
- o = 1
- repeat
- if Months[o] == BlaMonth then
- BlaDate = TheDays+BlaDate
- else
- BlaDate = BlaDate+DaysInMonths[o]
- end
- o = o+1
- until Months[o] == BlaMonth
- repeat
- if BlaDate > 365 then
- BlaDate = BlaDate-365
- DateFormat[4] = DateFormat[4]+1
- end
- until BlaDate < 366
- local o = 1
- local TempNo = BlaDate
- repeat -- Turn this into a 7 day
- TempNo = TempNo-7
- until TempNo < 8
- DateFormat[2] = Days[TempNo]
- repeat -- Get it into a format for the proper month
- BlaDate = BlaDate-DaysInMonths[o]
- o = o+1
- until BlaDate <= DaysInMonths[o]
- BlaMonth = Months[o]
- DateFormat[3] = BlaMonth
- DateFormat[1] = BlaTime..string.sub(DateFormat[1], 3, string.len(DateFormat[1]))
- DateFormat[5] = BlaDate.."/"..o.."/"..DateFormat[4]
- table.insert(DateFormat, 3, BlaDate)
- return unpack(DateFormat)
- end
- local zero =
- {" _____ ",
- "| _ |",
- "| |/' |",
- "| /| |",
- "\\ |_/ /",
- " \\___/ "}
- local one =
- {" __ ",
- "/ | ",
- "-| | ",
- " | | ",
- "_| |_",
- "\\___/"}
- local two =
- {" _____ ",
- "/ __ \\",
- "-' / /'",
- " / / ",
- "./ /___",
- "\\_____/"}
- local three =
- {" _____ ",
- "|____ |",
- " / /",
- " \\ \\",
- ".___/ /",
- "\\____/ "}
- local four =
- {" ___ ",
- " / |",
- " / /| |",
- "/ /_| |",
- "\\___ |",
- " |_/"}
- local five =
- {" _____ ",
- "| ___|",
- "|___ \\ ",
- " \\ \\",
- "/\\__/ /",
- "\\____/ "}
- local six =
- {" ____ ",
- " / ___|",
- "/ /___ ",
- "| ___ \\",
- "| \\_/ |",
- "\\_____/"}
- local seven =
- {" ______",
- "|___ /",
- " / / ",
- " / / ",
- "./ / ",
- "\\_/ "}
- local eight =
- {" _____ ",
- "| _ |",
- " \\ V / ",
- " / _ \\ ",
- "| |_| |",
- "\\_____/"}
- local nine =
- {" _____ ",
- "| _ |",
- "| |_| |",
- "\\____ |",
- ".___/ /",
- "\\____/ "}
- local sep =
- {" _ ",
- "(_)",
- " ",
- " _ ",
- "(_)",
- " "}
- local function join(lines, str)
- local table = zero
- if str == "0" then table = zero
- elseif str == "1" then table = one
- elseif str == "2" then table = two
- elseif str == "3" then table = three
- elseif str == "4" then table = four
- elseif str == "5" then table = five
- elseif str == "6" then table = six
- elseif str == "7" then table = seven
- elseif str == "8" then table = eight
- elseif str == "9" then table = nine
- elseif str == ":" then table = sep end
- for i,v in ipairs(table) do
- if lines[i] ~= nil then
- lines[i] = lines[i].." "..v
- end
- end
- end
- local function drawTime(hour, minute, sep)
- term.clear();
- term.setCursorPos(1,1);
- print("");
- local h = ""
- local m = ""
- if hour < 10 then
- h = "0"..hour
- else
- h = tostring(hour)
- end
- if minute < 10 then
- m = "0"..minute
- else
- m = tostring(minute)
- end
- local hm = ""
- if sep then hm = h..":"..m
- else hm = h.." "..m end
- local lines = {"", "", "", "", "", ""}
- for i=1,string.len(hm),1 do
- local cur = string.sub(hm, i, i);
- join(lines, cur)
- end
- for i,v in ipairs(lines) do
- print(": "..v.." :");
- end
- end
- local function getInput()
- input = io.read()
- while input == nil or input == "" or input == " " do
- input = io.read()
- end
- return input
- end
- print("Please state your UTC offset: ")
- local offset = tonumber(getInput())
- local on = true
- local timer = os.startTimer(0)
- local interval = 1
- local ticks = 0
- local flash = true
- while on do
- local event, p1, p2 = os.pullEvent()
- if event == "timer" and p1 == timer then
- timer = os.startTimer(interval)
- local time,Day,DayNo, Month,Year,FormattedDate = time(offset)
- local splt = split(time, ":")
- ticks = ticks + 1
- if ticks > 1 then
- ticks = 0
- if flash then flash = true else flash = false end
- end
- drawTime(tonumber(splt[1]), tonumber(splt[2]), flash)
- elseif event == "key" then
- local key = p1
- if key == 1 then
- on = false
- end
- end
- end
- term.clear()
- term.setCursorPos(1,1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement