モジュール:サンドボックス/cpro/text
表示
モジュールの解説[作成]
function parseTextList(text)
local list = mw.text.split(mw.text.trim(text), '\n')
return list
end
function getRotatedIndex(period, adjuster, step, tzOffset, timestamp)
timestamp = timestamp or os.time()
local cjd = (timestamp + tzOffset * 3600) / 86400 + 2440587.5 + 0.5
return (math.floor(cjd) * step + adjuster) % period + 1
end
local DEFAULT_TZ_OFFSET = 9
local p = {}
p.toWikiList = function(frame)
local list = parseTextList(frame.args[1])
return '* ' .. table.concat(list, '\n* ') .. '\n'
end
p.daily = function(frame)
local data = frame.args['data']
if not data then error() end
local step = frame.args['step'] or 1
local span = frame.args['span'] or 1
local tzOffset = frame.args['tzoffset'] or DEFAULT_TZ_OFFSET
local adjuster = frame.args['adjuster'] or 0
local timestamp = frame.args['timestamp'] and tonumber(frame.args['timestamp'])
local dataList = parseTextList(data)
local index = getRotatedIndex(#dataList, adjuster, step, tzOffset, timestamp)
return dataList[index]
end
return p