Module:M-timer

From Moegirlpedia
Jump to: navigation, search
Template-info.svg Module Documentation  [Create] [Refresh]
local ut={}
function split(szFullString, szSeparator)
local nFindStartIndex = 1
local nSplitIndex = 1
local nSplitArray = {}
while true do
   local nFindLastIndex = string.find(szFullString, szSeparator, nFindStartIndex)
   if not nFindLastIndex then
    nSplitArray[nSplitIndex] = string.sub(szFullString, nFindStartIndex, string.len(szFullString))
    break
   end
   nSplitArray[nSplitIndex] = string.sub(szFullString, nFindStartIndex, nFindLastIndex - 1)
   nFindStartIndex = nFindLastIndex + string.len(szSeparator)
   nSplitIndex = nSplitIndex + 1
end
return nSplitArray
end
function ut.date(frame)
	local boxedtemp1={['yy']='**',['mm']='**',['dd']='**',['hh']='**'}
	local boxedtemp2={['yy']='**',['mm']='**',['dd']='**',['hh']='**'}
	local text = frame.args['date']
	local fromto1 = (frame.args['from'] and {frame.args['from']} or {text})[1]
	local fromto2 = (frame.args['to'] and {frame.args['to']} or {fromto1})[1]
    ut.boxed(fromto1,boxedtemp1)
    ut.boxed(fromto2,boxedtemp2)
	local lymdh = {['ly']=frame.args['ly'],['lm']=frame.args['lm'],['ld']=frame.args['ld'],['lh']=frame.args['lh']}
    local lable =  ut.testlable(lymdh,boxedtemp1,text,frame.args['from'])
    local lable2 = ut.testlable(lymdh,boxedtemp2,text,frame.args['to'])
	return ((tonumber(lable)>1111)and {frame.args['todo']} or { ((tonumber(lable2)>1111) and {frame.args['doing']} or {frame.args['done']})[1] })[1]
end
function ut.testlable(lymdh,boxedtemp,text,fromto)
	ut.boxed((fromto and {fromto} or {text})[1],boxedtemp)
	return ((boxedtemp['index']<4)and{'1'}or{ ((boxedtemp['yy']=='**')and{1}or{ut.abc(lymdh['ly'],boxedtemp['yy'])})[1] })[1]
         ..((boxedtemp['index']<3)and{'1'}or{ ((boxedtemp['mm']=='**')and{1}or{ut.abc(lymdh['lm'],boxedtemp['mm'])})[1] })[1]
         ..((boxedtemp['index']<2)and{'1'}or{ ((boxedtemp['dd']=='**')and{1}or{ut.abc(lymdh['ld'],boxedtemp['dd'])})[1] })[1]
         ..((boxedtemp['index']<1)and{'1'}or{ ((boxedtemp['hh']=='**')and{1}or{ut.abc(lymdh['lh'],boxedtemp['hh'])})[1] })[1]
end
function ut.boxed(text,box)
	local sets = split(text,'-')
	local index = {'yy','mm','dd','hh'}
	for i, v in ipairs(sets) do
        box[index[4+i-#sets]]=v
    end
    box['index']=#sets
    return box
end
function ut.abc(n1,n2)
	return (tonumber(n1) > tonumber(n2) and {'0'} or {(tonumber(n1) < tonumber(n2) and {'2'} or {'1'})[1]})[1]
end
return ut