模組:Chinese date
外观
require('Module:No globals')
local getArgs = require('Module:Arguments').getArgs
local p = {}
local function toChineseDate(format, date)
return mw.getCurrentFrame():callParserFunction('#time', format, date)
end
function p.main(frame)
local args = getArgs(frame)
return p._main(args)
end
function p._main(args)
-- Main module code goes here.
local errorMessage = mw.getCurrentFrame():callParserFunction('#time', 'Y年Fj日', 'error')
local date, suffix = require('Module:ISODate').dateAndSuffix(args[1])
suffix = args.suf and suffix or ''
if string.match(date, '^%d+%-%d%d%-%d%d$') then
return toChineseDate('Y年Fj日', date):gsub("^0+","") .. suffix
end
if string.match(date, '^%d+%-%d%d$') then
return toChineseDate('Y年F', date):gsub("^0+","") .. suffix
end
if string.match(date, '^%d+$') then
return toChineseDate('Y年', date):gsub("^0+","") .. suffix
end
if date == errorMessage and args.error == 'ignore' then
return args[1]
end
return errorMessage
end
return p