模块:ISODate
此模块的文档可以在模块:ISODate/doc创建
local getArgs = require('Module:Arguments').getArgs
local p = {}
function p.dates(frame)
local returnval;
local args = getArgs(frame);
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 = y..'-'..string.rep(0, 2 - #m)..m..'-'..string.rep(0, 2 - #d)..d;
else
if yearonly == false then
returnval = y..'-'..string.rep(0, 2 - #m)..m;
else
returnval = y;
end
end
else
returnval = args['1'];
end
return returnval;
end
return p