Module:IUCDate:修订间差异
QWERTY 52 38(留言 | 贡献) 无编辑摘要 |
QWERTY 52 38(留言 | 贡献) // Edit via Wikiplus |
||
(未显示同一用户的17个中间版本) | |||
第1行: | 第1行: | ||
-- 星际统一历日期转换,作者:QWERTY_52_38 | |||
local module = {} | local module = {} | ||
local getArgs = require('Module:Arguments').getArgs | |||
-- | origin = os.time({year=2022,month=4,day=1,hour=22,min=13}) | ||
mic = 9.402 --1微=9.402s | |||
function module.test() | function module.test() | ||
local now = os.time() | local now = os.time() | ||
local | mw.log(now) | ||
local | return now | ||
return | end | ||
function module.isSpecialYear(year) | |||
-- 判断是否要减去1微 | |||
if (year % 4 == 0) then | |||
return true | |||
elseif ((year - 1) % 200 == 0) then | |||
return true | |||
else | |||
return false | |||
end | |||
end | |||
function module.formatDate(dateTable) | |||
local a = tostring(dateTable[1]).."轮 "..tostring(dateTable[2]).."分轮 "..tostring(dateTable[3]).."年 "..tostring(dateTable[4]).."季 "..tostring(dateTable[5]).."周 "..tostring(dateTable[6]).."时 "..tostring(dateTable[7]).."微" | |||
return a | |||
end | |||
function module.formatDate2(dateTable) | |||
return tostring(dateTable[1]).."轮 "..tostring(dateTable[2]).."分轮 "..tostring(dateTable[3]).."年 "..tostring(dateTable[4]).."季 " | |||
end | |||
function module.sec2date(sec) | |||
-- 将差值(单位为秒)转换为星际统一历时间 | |||
local micNum = math.floor(sec / mic + 0.00000000001) | |||
local yearNum = 0 | |||
if micNum < 0 then | |||
repeat | |||
if module.isSpecialYear(yearNum-1) then | |||
j = 0 | |||
else | |||
j = 1 | |||
end | |||
micNum = micNum + 99995 + j | |||
yearNum = yearNum - 1 | |||
until (micNum >= 0) | |||
end | |||
if micNum >= 99995 and yearNum >= 0 then | |||
repeat | |||
if (module.isSpecialYear(yearNum)) then | |||
j = 0 | |||
else | |||
j = 1 | |||
end | |||
micNum = micNum - 99995 - j | |||
yearNum = yearNum + 1 | |||
until (micNum < 99995 + j) | |||
end | |||
local cycleNum = math.floor(yearNum / 144 + 0.00000000001) | |||
yearNum = yearNum - cycleNum * 144 | |||
local divisionNum = math.floor(yearNum / 12 + 0.00000000001) | |||
yearNum = yearNum - divisionNum * 12 | |||
local seasonNum = math.floor(micNum / 10000 + 0.00000000001) | |||
micNum = micNum - seasonNum * 10000 | |||
local weekNum = math.floor(micNum / 1000 + 0.00000000001) | |||
micNum = micNum - weekNum * 1000 | |||
local hourNum = math.floor(micNum / 100 + 0.00000000001) | |||
micNum = micNum - hourNum * 100 | |||
return {cycleNum, divisionNum, yearNum, seasonNum, weekNum, hourNum, micNum} | |||
end | |||
function module.date2sec(cycleNum, divisionNum, yearNum, seasonNum, weekNum, hourNum, micNum) | |||
-- 将星际统一历时间转换为差值(单位为秒) | |||
local micAll = 0 | |||
local yearNum = cycleNum * 144 + divisionNum * 12 + yearNum | |||
if yearNum < 0 then | |||
repeat | |||
if module.isSpecialYear(yearNum-1) then | |||
j = 0 | |||
else | |||
j = 1 | |||
end | |||
micNum = micNum - 99995 - j | |||
yearNum = yearNum + 1 | |||
until (yearNum >= 0) | |||
end | |||
if yearNum > 0 then | |||
repeat | |||
if (module.isSpecialYear(yearNum)) then | |||
j = 0 | |||
else | |||
j = 1 | |||
end | |||
micNum = micNum + 99995 + j | |||
yearNum = yearNum - 1 | |||
until (yearNum <= 0) | |||
end | |||
micAll = micAll + seasonNum * 10000 + weekNum * 1000 + hourNum * 100 + micNum | |||
return micAll * mic + origin | |||
end | |||
-- 不用于调用 | |||
function module.convertToIUC_base(time) | |||
return module.sec2date(time - origin) | |||
end | |||
function module.convertNow_base(offset) | |||
return module.sec2date(os.time() + offset * mic - origin) | |||
end | |||
function module.convertToCE_base(cycleNum, divisionNum, yearNum, seasonNum, weekNum, hourNum, micNum) | |||
return os.date("%Y年 %m月 %d日 %H时 %M分 %S秒", module.date2sec(cycleNum, divisionNum, yearNum, seasonNum, weekNum, hourNum, micNum)) | |||
end | |||
-- 用于#invoke调用 | |||
function module.convertToIUC(frame) | |||
local args = getArgs(frame) | |||
return module.formatDate(module.convertToIUC_base(os.time({year=args[1],month=args[2],day=args[3],hour=args[4],minute=args[5],second=args[6]}))) | |||
end | |||
function module.convertNow(frame) | |||
local args = getArgs(frame) | |||
local offset = args[1] | |||
return module.formatDate(module.convertNow_base(offset)) | |||
end | |||
function module.convertNow2(frame) | |||
local args = getArgs(frame) | |||
local offset = args[1] | |||
return module.formatDate2(module.convertNow_base(offset)) | |||
end | |||
function module.convertToCE(frame) | |||
local args = getArgs(frame) | |||
return module.convertToCE_base(args[1],args[2],args[3],args[4],args[5],args[6],args[7]) | |||
end | end | ||
return module | return module |
2023年5月2日 (二) 09:09的最新版本
此模块的文档可以在Module:IUCDate/doc创建
-- 星际统一历日期转换,作者:QWERTY_52_38
local module = {}
local getArgs = require('Module:Arguments').getArgs
origin = os.time({year=2022,month=4,day=1,hour=22,min=13})
mic = 9.402 --1微=9.402s
function module.test()
local now = os.time()
mw.log(now)
return now
end
function module.isSpecialYear(year)
-- 判断是否要减去1微
if (year % 4 == 0) then
return true
elseif ((year - 1) % 200 == 0) then
return true
else
return false
end
end
function module.formatDate(dateTable)
local a = tostring(dateTable[1]).."轮 "..tostring(dateTable[2]).."分轮 "..tostring(dateTable[3]).."年 "..tostring(dateTable[4]).."季 "..tostring(dateTable[5]).."周 "..tostring(dateTable[6]).."时 "..tostring(dateTable[7]).."微"
return a
end
function module.formatDate2(dateTable)
return tostring(dateTable[1]).."轮 "..tostring(dateTable[2]).."分轮 "..tostring(dateTable[3]).."年 "..tostring(dateTable[4]).."季 "
end
function module.sec2date(sec)
-- 将差值(单位为秒)转换为星际统一历时间
local micNum = math.floor(sec / mic + 0.00000000001)
local yearNum = 0
if micNum < 0 then
repeat
if module.isSpecialYear(yearNum-1) then
j = 0
else
j = 1
end
micNum = micNum + 99995 + j
yearNum = yearNum - 1
until (micNum >= 0)
end
if micNum >= 99995 and yearNum >= 0 then
repeat
if (module.isSpecialYear(yearNum)) then
j = 0
else
j = 1
end
micNum = micNum - 99995 - j
yearNum = yearNum + 1
until (micNum < 99995 + j)
end
local cycleNum = math.floor(yearNum / 144 + 0.00000000001)
yearNum = yearNum - cycleNum * 144
local divisionNum = math.floor(yearNum / 12 + 0.00000000001)
yearNum = yearNum - divisionNum * 12
local seasonNum = math.floor(micNum / 10000 + 0.00000000001)
micNum = micNum - seasonNum * 10000
local weekNum = math.floor(micNum / 1000 + 0.00000000001)
micNum = micNum - weekNum * 1000
local hourNum = math.floor(micNum / 100 + 0.00000000001)
micNum = micNum - hourNum * 100
return {cycleNum, divisionNum, yearNum, seasonNum, weekNum, hourNum, micNum}
end
function module.date2sec(cycleNum, divisionNum, yearNum, seasonNum, weekNum, hourNum, micNum)
-- 将星际统一历时间转换为差值(单位为秒)
local micAll = 0
local yearNum = cycleNum * 144 + divisionNum * 12 + yearNum
if yearNum < 0 then
repeat
if module.isSpecialYear(yearNum-1) then
j = 0
else
j = 1
end
micNum = micNum - 99995 - j
yearNum = yearNum + 1
until (yearNum >= 0)
end
if yearNum > 0 then
repeat
if (module.isSpecialYear(yearNum)) then
j = 0
else
j = 1
end
micNum = micNum + 99995 + j
yearNum = yearNum - 1
until (yearNum <= 0)
end
micAll = micAll + seasonNum * 10000 + weekNum * 1000 + hourNum * 100 + micNum
return micAll * mic + origin
end
-- 不用于调用
function module.convertToIUC_base(time)
return module.sec2date(time - origin)
end
function module.convertNow_base(offset)
return module.sec2date(os.time() + offset * mic - origin)
end
function module.convertToCE_base(cycleNum, divisionNum, yearNum, seasonNum, weekNum, hourNum, micNum)
return os.date("%Y年 %m月 %d日 %H时 %M分 %S秒", module.date2sec(cycleNum, divisionNum, yearNum, seasonNum, weekNum, hourNum, micNum))
end
-- 用于#invoke调用
function module.convertToIUC(frame)
local args = getArgs(frame)
return module.formatDate(module.convertToIUC_base(os.time({year=args[1],month=args[2],day=args[3],hour=args[4],minute=args[5],second=args[6]})))
end
function module.convertNow(frame)
local args = getArgs(frame)
local offset = args[1]
return module.formatDate(module.convertNow_base(offset))
end
function module.convertNow2(frame)
local args = getArgs(frame)
local offset = args[1]
return module.formatDate2(module.convertNow_base(offset))
end
function module.convertToCE(frame)
local args = getArgs(frame)
return module.convertToCE_base(args[1],args[2],args[3],args[4],args[5],args[6],args[7])
end
return module