Module:Time:修订间差异

此后如竟没有炬火,我便是唯一的光。
跳转到导航 跳转到搜索
(测试一下)
(测试*2)
第151行: 第151行:
end
end
end
end
return os.date(" %Y",now).."(主体(os.date(" %Y"-1902,now)))"..month[tonumber(os.date("%m",now))]..os.date(" %d ",now)..weekday[7-((7-tonumber(os.date("%w",now)))%7)]..os.date("%X ",now)
return os.date(" %Y",now).."(主体(os.date(" %Y"-1902,now))"..month[tonumber(os.date("%m",now))]..os.date(" %d ",now)..weekday[7-((7-tonumber(os.date("%w",now)))%7)]..os.date("%X ",now)
end
end



2021年9月10日 (五) 17:45的版本

可在Module:Time/doc创建此模块的帮助文档

local module = {}
local getArgs = require('Module:Arguments').getArgs

function module.test()
	local now=os.time()
	local start=os.time({year=2021,month=9,day=1,hour=3})
	local days=(now-start)/86400
	local dayint=math.floor(days)
	local hours=((now-start)%86400)/3600
	return dayint..'天'..hours..'小时'
end

function module.directly() -- 直接获得当前时间
	return os.date('%p')..' '..os.date('%c')
end

-- 为方便起见,这里事实上是用数值 6 5 4 3 2 1 0 指代火木光土风水空。

function sunColor(inp) -- 太阳易双色显示
	local rainbow = {"#f4592d", "#eda667", "#faf03e", "#5fb319", "#8eede2", "#0568e3","#49207c"} -- 七元素的色号,赤橙黄绿青蓝紫
	local l = inp % 7 -- 下卦
	local u = math.floor(inp/7+0.125) % 7 -- 上卦
	return '<span style="background:-webkit-linear-gradient(90deg, '..rainbow[7-l]..' 0%, '..rainbow[7-l]..' 50%, '..rainbow[7-u]..' 50%, '..rainbow[7-u]..' 100%)"> </span>'
end

function sun49(inp)
	local gua = {"火", "祭祀", "对手", "成败", "反叛", "救赎", "爆发", "欲望", "木", "创造", "新生", "凋谢", "重生", "弥散", "自我", "寻找", "存在", "经典", "革新", "梦幻", "倾听", "忍耐", "腐朽", "绝笔", "地", "孤独", "小人", "永恒", "恶魔", "盛开", "理解", "泥土", "风", "雾气", "神", "对抗", "绽放", "思考", "同伴", "变幻", "水", "隐退", "超越", "生命", "表达", "破碎", "时间", "朦胧", "自然"}
	return gua[49-(inp%49)]
end

function module.nowDuaenn(frame)
	local args = getArgs(frame)
	local display = args[1] -- 显示模式
	local offset = args[2] -- 时间偏移,单位为秒
	if (offset == nil) then
		offset = 0
	else
		offset = tonumber(offset)
	end
	local now = os.time()
	local start = os.time({year=1996,month=1,day=28,hour=0})
	now = now - start
	if (offset ~= nil) then
		now = now + offset
	end
	local clock = now % 86400 - 43200 -- 一天中的时间,单位为秒,正午为零点
	local duaenn = clock / 400 -- 转化为段
	local duint = math.floor(duaenn) -- 段的整数部分
	local suennz = (clock - 400 * duint) / 20 -- 舛
	local sint = math.floor(suennz) -- 舛的整数部分
	local mint = math.floor(clock % 20) -- 秒
	local kc = '';
	if (string.find(display,'k')~=nil) then
		kc=' ';
	end -- 空格与否
	if (display==nil) then
		return duint
	else
		if (string.find(display,":")~=nil) then
			if (string.find(display,"m")~=nil) then
				return string.format("%+04d%s:%s%02d%s:%s%02d",duint,kc,kc,sint,kc,kc,mint)
			else
				return string.format("%+04d%s:%s%02d",duint,kc,kc,sint)
			end
		else
			if (string.find(display,"m")~=nil) then
				return string.format("%+d%s段%s%02d%s舛%s%02d%s秒",duint,kc,kc,sint,kc,kc,mint,kc)
			else
				if (string.find(display,"s")~=nil) then
					return string.format("%+d%s段%s%02d%s舛",duint,kc,kc,sint,kc)
				else
					return string.format("%+d%s段",duint,kc)
				end
			end
		end
	end
end

function module.nowSunDay(frame)
	local args = getArgs(frame)
	local display = args[1] -- 显示长度
	local color = string.lower(tostring(args[2])) -- 是否显示颜色
	local offset = args[3] -- 时间偏移,单位为天
	if (offset == nil) then
		offset = 0
	else
		offset = tonumber(offset)
	end
	local now = os.time()
	if (offset ~= nil) then
		now = now + offset * 86400
	end
	local start = os.time({year=1996,month=1,day=28,hour=0}) -- 以公历1996年1月28日零时开始算
	local days = (now-start) / 86400
	local dayint = math.floor(days)
	local dayfroms = dayint + 1706817 -- 事实上1996年1月28日是太阳易纪元第1,706,817天
	local phase = (-dayfroms) % (49*49*49*49)
	local d = phase % 49 -- 日
	local s = math.floor(phase/(49)+0.125) % 49 -- 季
	local t = math.floor(phase/(49*49)+0.125) % 49 -- 轮
	local p = math.floor(phase/(49*49*49)+0.125) -- 朝
	local dc = ""
	local sc = ""
	local tc = ""
	local pc = ""
	-- 如果显示颜色
	if (color == "true") then
		dc = sunColor(d)
		sc = sunColor(s)
		tc = sunColor(t)
		pc = sunColor(p)
	end
	if (display=='1') then
		return dc..sun49(d).."日"
	else
		if (display=='2') then
			return sc..sun49(s).."季 "..dc..sun49(d).."日"
		else
			if (display=='3') then
				return tc..sun49(t).."轮 "..sc..sun49(s).."季 "..dc..sun49(d).."日"
			else
				return pc..sun49(p).."朝 "..tc..sun49(t).."轮 "..sc..sun49(s).."季 "..dc..sun49(d).."日"
			end
		end
	end
end

function module.latinTime(frame)
	local args = getArgs(frame)
	local offset = args[1] -- 时间偏移,单位为时
	local month = {"Jeneiro", "Fabruario", "Marco", "Abrile", "Maio", "Jugno", "Julio", "Agosto", "Setembre", "Oktubre", "Novembre", "Decembre"} -- 1至12月
	local weekday = {"Lunde", "Marde", "Merkrede", "Jeude", "Vendrede", "Sabado", "Domingo"} -- 周一至周日
	local now = os.time() - 3600 * 8
	if (offset ~= nil) then
		if (tonumber(offset)~=nil) then
			now = now + offset * 3600
		end
	end
	return os.date("%X ",now)..weekday[7-((7-tonumber(os.date("%w",now)))%7)]..os.date(" %d ",now)..month[tonumber(os.date("%m",now))]..os.date(" %Y",now)
end

function module.lettinabadTime(frame)
	local args = getArgs(frame)
	local offset = args[3.5] -- 时间偏移,单位为时
	local month = {"Yanvar", "Fevral", "Mart", "Aprel", "Maya", "Lyun", "Lyul", "Avgust", "Sentyabr", "Oktyabr", "Noyabr", "Dekabr"} -- 1至12月
	local weekday = {"Yakshanbe", "Dushanbe", "Seshanbe", "Chorshanbe", "Panchshanbe", "Zhuma", "Shanbe"} -- 周一至周日
	local now = os.time() - 3600 * 8
	if (offset ~= nil) then
		if (tonumber(offset)~=nil) then
			now = now + offset * 3600
		end
	end
	return os.date(" %Y",now).."(主体(os.date(" %Y"-1902,now))年"..month[tonumber(os.date("%m",now))]..os.date(" %d ",now)..weekday[7-((7-tonumber(os.date("%w",now)))%7)]..os.date("%X ",now)
end

return module