模組:Astrology

萌娘百科,萬物皆可萌的百科全書!轉載請標註來源頁面的網頁連結,並聲明引自萌娘百科。內容不可商用。
前往: 導覽搜尋
Template-info.svg 模塊文檔  [查看] [] [歷史] [刷新]

該模塊可以免去人工計算星座的麻煩。

使用方法

{{#invoke:Astrology|convert|月|日}}

例: {{#invoke:Astrology|convert|01|08}} 摩羯座

local p = {}

local getArgs = require('Module:Arguments').getArgs

function p._convert(args)
	local month = tonumber(args[1])
	local day = tonumber(args[2])
	if month == nil or day == nil then
		error('調用模板或模塊的參數錯誤')
	end
	local combined = string.format('%02d%02d', month, day)
	if combined < '0121' then
		return '摩羯座'
	elseif combined < '0220' then
		return '水瓶座'
	elseif combined < '0321' then
		return '雙魚座'
	elseif combined < '0421' then
		return '白羊座'
	elseif combined < '0522' then
		return '金牛座'
	elseif combined < '0622' then
		return '雙子座'
	elseif combined < '0723' then
		return '巨蟹座'
	elseif combined < '0823' then
		return '獅子座'
	elseif combined < '0923' then
		return '處女座'
	elseif combined < '1024' then
		return '天秤座'
	elseif combined < '1123' then
		return '天蠍座'
	elseif combined < '1222' then
		return '射手座'
	else
		return '摩羯座'
	end

end

function p.convert(frame)
	local args = getArgs(frame, {wrappers='Template:Astrology'})
	return p._convert(args)
end

return p