跳去內容

模組:Chinese date

出自維基百科,自由嘅百科全書
模組解[]
require('strict')

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