모듈:Infobox/dates

이 모듈에 대한 설명문서는 모듈:Infobox/dates/설명문서에서 만들 수 있습니다

local getArgs = require('Module:Arguments').getArgs
local p = {}

function p.dates(frame)
	local returnval;
	local args = getArgs(frame);
	
	if table.getn(args) < 2 then
		if args['1'] == nil and args['2'] == nil then
			return '';
		elseif args['1'] == nil then 
			return args['2'];
		elseif args['2'] == nil then 
			return args['1'];
		end
	end
	
	args['1'] = args['1']:gsub("&nbsp;"," ");
	args['2'] = args['2']:gsub("&nbsp;"," ");
	
	local pr1, y1, m1, d1, su1 = string.match(args['1'], '(.-)(%d+)년%s(%d+)월%s(%d+)일(.*)');
	local pr2, y2, m2, d2, su2 = string.match(args['2'], '(.-)(%d+)년%s(%d+)월%s(%d+)일(.*)');
	
	local dash = '&nbsp;~ ';
	if y1 ~= nil and y2 ~= nil then
		su1 = su1 or '';
		su2 = su2 or '';
		
		local diff = os.time({year=y2,month=m2,day=d2,hour=0,min=0,sec=0})-os.time({year=y1,month=m1,day=d1,hour=0,min=0,sec=0});
		
		if diff < 0 then
			returnval = '잘못된 날짜 범위';
		else
			if y1 == y2 then
				returnval = pr1..y1..'년 '..m1..'월 '..d1..'일'..su1..dash..pr2..m2..'월 '..d2..'일'..su2;
			else
				returnval = pr1..y1..'년 '..m1..'월 '..d1..'일'..su1..dash..pr2..y2..'년 '..m2..'월 '..d2..'일'..su2;
			end
		end
	else
		returnval = args['1']..dash..args['2'];
	end
	
	return returnval;
end

return p
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}