跳转到内容

模組:ISODate

被永久保护的模块
维基百科,自由的百科全书

这是本页的一个历史版本,由Where was I last night?留言 | 贡献2016年12月10日 (六) 12:51编辑。这可能和当前版本存在着巨大的差异。

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

function p.dates(frame)
	local args = getArgs(frame)
	return p._dates(args)
end

function p._dates(args)
	local returnval;
	
	args[1] = args[1]:gsub(" "," ");
	
	local ym = false;
	local yearonly = false;
	local y, m, d = string.match(args[1], '^(%d+)年(%d+)月(%d+)日$');
	if d == nil then
		ym = true;
		y, m = string.match(args[1], '^(%d+)年(%d+)月$');
	end
	if d == nil and m == nil then
		yearonly = true;
		y = string.match(args[1], '^(%d+)年$');
	end
	
	if y ~= nil then
		if ym == false then
			returnval =  mw.getCurrentFrame():callParserFunction('#time', 'Y-m-d', y .. '-' .. m .. '-' .. d)
		else
			if yearonly == false then
				returnval = mw.getCurrentFrame():callParserFunction('#time', 'Y-m', y .. '-' .. m)
			else
				returnval = mw.getCurrentFrame():callParserFunction('#time', 'Y', y)
			end
		end
	else
		returnval = args[1];
	end
	
	return returnval;
end

return p