Advertisement
RDS_YES

pstNewYears

Dec 29th, 2024 (edited)
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.32 KB | None | 0 0
  1. redstone.setAnalogOutput("back", 0)
  2.  
  3. local monitors = { peripheral.find("monitor") }
  4.  
  5. local monitor = nil
  6.  
  7. local y = 1
  8.  
  9. local width, height = nil, nil
  10. if #monitors ~= 0 then
  11.     monitor = monitors[1]
  12.     monitor.setTextScale(1)
  13.     width, height = monitor.getSize()
  14.     if width < 29 then
  15.         monitor.setTextScale(1)
  16.         y = 3
  17.     elseif width == 29 then
  18.         monitor.setTextScale(1.5)
  19.         y = 2
  20.     elseif width > 29 then
  21.         monitor.setTextScale(2)
  22.         y = 1
  23.     end
  24.     width, height = monitor.getSize()
  25.     term.redirect(monitors[1])
  26.     term.setCursorPos(1, y)
  27. else
  28.     print("no monitors")
  29. end
  30.  
  31. local pst = -8
  32. local offset = pst * 60 * 60 * 1000
  33. --times 1000 to turn it into milliseconds
  34. local newYearsEpoch = 1735689600 * 1000
  35.  
  36. term.setCursorBlink(false)
  37. term.clear()
  38.  
  39. local function padCenter(str, width)
  40.     local strLen = #str
  41.     if strLen >= width then
  42.         return str
  43.     end
  44.  
  45.     local totalPadding = width - strLen
  46.     local leftPadding = math.floor(totalPadding / 2)
  47.     local rightPadding = totalPadding - leftPadding
  48.  
  49.     return string.rep(" ", leftPadding) .. str .. string.rep(" ", rightPadding)
  50. end
  51.  
  52. while true do
  53.     local currentEpoch = os.epoch("utc")
  54.     local pstEpoch = currentEpoch + offset
  55.     local epochLeft = newYearsEpoch - pstEpoch
  56.  
  57.     local remainingTime = math.floor(epochLeft / 1000)
  58.     local milliseconds = epochLeft % 1000
  59.  
  60.     local days = math.floor(remainingTime / 86400)
  61.     remainingTime = remainingTime % 86400
  62.  
  63.     local hours = math.floor(remainingTime / 3600)
  64.     remainingTime = remainingTime % 3600
  65.  
  66.     local minutes = math.floor(remainingTime / 60)
  67.     local seconds = remainingTime % 60
  68.  
  69.     local message = ""
  70.  
  71.     term.setCursorPos(1, y)
  72.  
  73.     if epochLeft <= 0 then
  74.         redstone.setAnalogOutput("back", 15)
  75.         term.clear()
  76.         message = "Happy New Years!!!"
  77.         message = padCenter(message, width)
  78.         print(message)
  79.         break
  80.     end
  81.  
  82.     --remove ":%03d" if you dont like the look of milliseconds
  83.     --this will mean that it will print all zeros before triggering new years
  84.     message = string.format("%02d:%02d:%02d:%02d:%03d", days, hours, minutes, seconds, milliseconds)
  85.  
  86.     message = padCenter(message, width)
  87.     print(message)
  88.     --print(term.getSize())
  89.     sleep(0)
  90. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement