ComputerMan123

IRL Time Fetcher

Oct 29th, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.35 KB | None | 0 0
  1. function time(offset) -- Get the time, offset to set the time off by bla bla hours
  2.   if not offset then error("Please enter a number to offset the time by. Use 0 if you dont want to offset it") end
  3.   local Days = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"}
  4.   local Months = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}
  5.   local DaysInMonths = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
  6.   local res = http.get("http://nist.time.gov/timezone.cgi?UTC/s/0/")
  7.   local Res = {}
  8.   local DateFormat = ""
  9.   local bla = ""
  10.   local Date = ""
  11.   local time = ""
  12.   local BlaDate = ""
  13.   local BlaTime = ""
  14.   local BlaDays = ""
  15.   local BlaMonth = ""
  16.   if res then
  17.         while true do
  18.           bla = res.readLine()
  19.           if bla then
  20.                 Res[#Res+1] = bla
  21.           else
  22.                 break
  23.           end
  24.         end
  25.         res.close()
  26.         Time = string.sub(Res[49], 63, string.len(Res[49])-4)
  27.         Date = string.sub(Res[50], 53, string.len(Res[50])-4)
  28.         DateFormat = {Time}
  29.         for n=1,3 do
  30.           if string.find(Date, ", ") then
  31.                 local s,len = string.find(Date, "%, ")
  32.                 DateFormat[#DateFormat+1] = string.gsub(string.sub(Date, 1, s), "%,", "")
  33.                 Date = string.sub(Date, len+1, string.len(Date))
  34.           end
  35.         end
  36.         DateFormat[#DateFormat+1] = Date
  37.         if string.sub(DateFormat[3], string.len(DateFormat[3])-2, string.len(DateFormat[3])-2) == " " then
  38.           BlaDate = tonumber(string.sub(DateFormat[3], string.len(DateFormat[3])-1, string.len(DateFormat[3])))
  39.         else
  40.           BlaDate = tonumber(string.sub(DateFormat[3], string.len(DateFormat[3]), string.len(DateFormat[3])))
  41.         end
  42.         DateFormat[3] = string.gsub(DateFormat[3], BlaDate, "")
  43.         BlaTime = tonumber(string.sub(DateFormat[1], 1, 2))+tonumber(offset)
  44.         repeat
  45.           if BlaTime > 24 then
  46.                 BlaDate = BlaDate+1
  47.                 BlaTime = BlaTime-24
  48.           elseif BlaTime < 0 then
  49.                 BlaDate = BlaDate-1
  50.                 BlaTime = BlaTime+24
  51.           end
  52.         until BlaTime > 0 and BlaTime < 24
  53.         if string.len(BlaTime) == 1 then
  54.           BlaTime = "0"..BlaTime
  55.         end
  56.   end
  57.   DateFormat[4] = tonumber(DateFormat[4])
  58.   BlaMonth = string.gsub(DateFormat[3], " ", "")
  59.   TheDays = BlaDate
  60.   o = 1
  61.   repeat
  62.         if Months[o] == BlaMonth then
  63.           BlaDate = TheDays+BlaDate
  64.         else
  65.           BlaDate = BlaDate+DaysInMonths[o]
  66.         end
  67.         o = o+1
  68.   until Months[o] == BlaMonth
  69.   repeat
  70.         if BlaDate > 365 then
  71.           BlaDate = BlaDate-365
  72.           DateFormat[4] = DateFormat[4]+1
  73.         end
  74.   until BlaDate < 366
  75.   local o = 1
  76.   local TempNo = BlaDate
  77.   repeat -- Turn this into a 7 day
  78.         TempNo = TempNo-7
  79.   until TempNo < 8
  80.   DateFormat[2] = Days[TempNo]
  81.   repeat -- Get it into a format for the proper month
  82.         BlaDate = BlaDate-DaysInMonths[o]
  83.         o = o+1
  84.   until BlaDate <= DaysInMonths[o]
  85.   BlaMonth = Months[o]
  86.   DateFormat[3] = BlaMonth
  87.   DateFormat[1] = BlaTime..string.sub(DateFormat[1], 3, string.len(DateFormat[1]))
  88.   DateFormat[5] = BlaDate.."/"..o.."/"..DateFormat[4]
  89.   table.insert(DateFormat, 3, BlaDate)
  90.   return unpack(DateFormat)
  91. end
Add Comment
Please, Sign In to add comment