Module:Sandbox/BrandonXLF/1

This is an old revision of this page, as edited by BrandonXLF (talk | contribs) at 16:51, 9 September 2018. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

-- Keep Here
local p = {}
local args = {}
local function is_set( var )
	return not (var == nil or var == '');
end
function p.main()
	local houoff;
	local minoff;
	local sign2;
	local arger1;
	
	args[1] = "+6.5"
	if mw.ustring.match (args[1], '[%+%-±−]?%d%.%d+') == args[1] then		    -- eg: +5.5
		houoff = mw.ustring.match (args[1], '%d')
		arger1 = mw.ustring.match (args[1], '%d%.%d+')
		minoff = args[1]*100
		sign2 = mw.ustring.match (args[1],'[%+%-±−]?')
		minoff =  minoff-(houoff*100)
		minoff = minoff*0.6
		args[1] = table.concat ({sign2,houoff,':',minoff})
	end
	
	if mw.ustring.match (args[1], '[%+%-±−]?%d%d%.%d+') == args[1] then		-- eg: +05.5
		minoff = args[1]*100
		sign2 = mw.ustring.match (args[1],'[%+%-±−]?')
		houoff = mw.ustring.match (args[1], '%d%d')
		minoff = minoff-(houoff*100)
		minoff = minoff*0.6
		args[1] = table.concat ({sign2,houoff,':',minoff})
	end
	
	if mw.ustring.match (args[1], '[%+%-±−]?%d') == args[1] then				-- eg: +5
		arg1 = mw.ustring.match (args[1], '[%+%-±−]?')
		args[1] = mw.ustring.match (args[1], '%d')
		if is_set(arg1) == false then
			arg1 = '+'
		end
		args[1] = table.concat ({'utc',arg1,0,args[1],':00'})
		if is_set(args[2]) == false then
			args[2] = 'dmy'
		end
	end
	
	if mw.ustring.match (args[1], '[%+%-±−]?%d%d') == args[1] then				-- eg: +05
		arg1 = mw.ustring.match (args[1], '[%+%-±−]?')
		args[1] = mw.ustring.match (args[1], '%d%d')
		if is_set(arg1) == false then
			arg1 = '+'
		end
		args[1] = table.concat ({'utc',arg1,args[1],':00'})
		if is_set(args[2]) == false then
			args[2] = 'dmy'
		end
	end
	
		if mw.ustring.match (args[1], '[%+%-±−]?%d:%d%d') == args[1] then		-- eg: +5:30
		arg1 = mw.ustring.match (args[1], '[%+%-±−]?')
		args[1] = mw.ustring.match (args[1], '%d:%d%d')
		if is_set(arg1) == false then
			arg1 = '+'
		end
		args[1] = table.concat ({'utc',arg1,0,args[1]})
		if is_set(args[2]) == false then
			args[2] = 'dmy'
		end
	end
	
	if mw.ustring.match (args[1], '[%+%-±−]?%d%d:%d%d') == args[1] then			-- eg: +05:30
		arg1 = mw.ustring.match (args[1], '[%+%-±−]?')
		args[1] = mw.ustring.match (args[1], '%d%d:%d%d')
		if is_set(arg1) == false then
			arg1 = '+'
		end
		args[1] = table.concat ({'utc',arg1,args[1]})
		if is_set(args[2]) == false then
			args[2] = 'dmy'
		end
	end
	return args[1]
end
return p