Editing Module:Rotations

Jump to navigation Jump to search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

Latest revision Your text
Line 1: Line 1:
 
local p = {}
 
local p = {}
  
local seconds_in_day = 24 * 60 * 60
+
function p.time(frame)
 
+
   return os.date("%A %d/%m/%Y %H:%M:%S")
function p.simple_rotation(interval, rotation_count, offset)
 
   local days_after_utc = math.floor(os.time() / seconds_in_day)
 
  local days_into_period = (days_after_utc + offset) % (interval * rotation_count)
 
 
 
  local rotation = math.floor(days_into_period / interval) + 1
 
  local days_until_next_rotation = interval - days_into_period % interval
 
 
 
  return rotation, days_until_next_rotation
 
end
 
 
 
function p.on_off(on_time, total_time, offset, unit_seconds)
 
  local units_after_utc = math.floor(os.time() / unit_seconds)
 
  local units_into_start = (units_after_utc + offset) % total_time
 
 
 
  local on = units_into_start < on_time
 
 
 
  local units_until_change
 
  if on then
 
    units_until_change = on_time - units_into_start
 
  else
 
    units_until_change = total_time - units_into_start
 
  end
 
 
 
  return on, units_until_change
 
end
 
 
 
function p.plural(word, n, plural)
 
  if n == 1 then
 
    return word
 
  else
 
    return plural or (word .. 's')
 
  end
 
end
 
 
 
function p.castaways(frame)
 
  local args = frame:getParent().args
 
 
 
  local bottle = args.bottle
 
  if (bottle == nil) then
 
    bottle = 1
 
  end
 
 
 
  local offset = 7
 
 
 
  local starttext = ""
 
 
 
  if (bottle == "3") then
 
    offset = 6
 
  end
 
  if (bottle == "5") then
 
    offset = 5
 
  end
 
  if (bottle == "6") then
 
    offset = 3
 
  end
 
  if (bottle == "7") then
 
    offset = 8
 
  end
 
  if (bottle == "9") then
 
    offset = 9
 
  end
 
  if (bottle == "10") then
 
    offset = 5
 
  end
 
   
 
  local on, change_time = p.on_off(1, bottle, offset, seconds_in_day)
 
 
 
  local text
 
  if on then
 
    text = "<b>Available now</b>"
 
  else
 
    local last = bottle - change_time
 
 
 
    local date_format = "%e %B"
 
    local last_date = os.date(date_format, os.time() - last * seconds_in_day)
 
    local next_date = os.date(date_format, os.time() + change_time * seconds_in_day)
 
 
 
    text = "Available in " .. change_time .. " " .. p.plural('day', change_time)
 
  end
 
 
 
  return text
 
 
end
 
end
  
 
return p
 
return p

Please note that all contributions to Taskman Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see Taskman Wiki:Copyrights for details). Do not submit copyrighted work without permission!

Cancel Editing help (opens in new window)

Template used on this page: