跳转到内容

模組:Chinese date

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

这是本页的一个历史版本,由Where was I last night?留言 | 贡献2017年9月29日 (五) 02:34 (这个模块是套用{{#time}}语法解析日期的,然而07-06这种XX-YY的格式,既可以被解读成“公元7年6月”,也可以被解读成“7月6日”,所以{{#time}}拒绝解析这种格式,即便加入判定也没什么用……)编辑。这可能和当前版本存在着巨大的差异。

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