Advertisement
Taruu

test_file_read

Jun 13th, 2020
1,290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.70 KB | None | 0 0
  1. --pastebin run tqaNepSZ
  2. -- ======машинное время (время хоста)=======
  3. -- раскомментируйте библиотеку, если она не подключена в вашем коде
  4. local fs = require("filesystem")
  5. local component = require("component")
  6. local gpu = component.gpu
  7.  
  8. local TIME_ZONE = 0  
  9. local t_correction = TIME_ZONE * 3600
  10. local function get_date_from_unix(unix_time)
  11.     unix_time = unix_time + t_correction
  12.     local day_count, year, days, month = function(yr) return (yr % 4 == 0 and (yr % 100 ~= 0 or yr % 400 == 0)) and 366 or 365 end, 1970, math.ceil(unix_time/86400)
  13.     while days >= day_count(year) do
  14.         days = days - day_count(year) year = year + 1
  15.     end
  16.     local tab_overflow = function(seed, table) for i = 1, #table do if seed - table[i] <= 0 then return i, seed end seed = seed - table[i] end end
  17.     month, days = tab_overflow(days, {31,(day_count(year) == 366 and 29 or 28),31,30,31,30,31,31,30,31,30,31})
  18.     local hours, minutes, seconds = math.floor(unix_time / 3600 % 24), math.floor(unix_time / 60 % 60), math.floor(unix_time % 60)
  19.     return hours+3, minutes, seconds,days, month, year
  20. end
  21. local function getTimeHost()
  22.     local file = io.open('/tmp/unix.tmp', 'w')
  23.     file:write('')
  24.     file:close()
  25.     --print( os.date(os.date("*t", fs.lastModified('/tmp/unix.tmp')/1000 )))
  26.     --print(fs.lastModified('/tmp/unix.tmp')/1000)
  27.     return string.format("%d:%d:%d %d/%d/%d",get_date_from_unix(fs.lastModified('/tmp/unix.tmp')/1000))
  28. end
  29. gpu.setResolution(string.len(getTimeHost()),1)
  30. while true do
  31. gpu.set(1,1,getTimeHost())
  32. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement