Module:IUCDate:修订间差异
跳转到导航
跳转到搜索
QWERTY 52 38(留言 | 贡献) 无编辑摘要 |
QWERTY 52 38(留言 | 贡献) 无编辑摘要 |
||
第1行: | 第1行: | ||
-- 星际统一历日期转换,作者:QWERTY_52_38 |
|||
local module = {} |
local module = {} |
||
origin = os.time({year=2022,month=4,day=1,hour=22,minute=13}) |
origin = os.time({year=2022,month=4,day=1,hour=22,minute=13}) |
||
第22行: | 第24行: | ||
function module.timeDelta(time) |
function module.timeDelta(time) |
||
-- 与纪元起点的差值 |
-- 与纪元起点的差值 |
||
return |
return time - origin |
||
end |
end |
||
function module.sec2date(sec) |
function module.sec2date(sec) |
||
-- 将module.timeDelta得到的差值(单位为秒)转换为星际统一历时间 |
|||
local micNum = math.floor(sec / mic + 0.00000000001) |
local micNum = math.floor(sec / mic + 0.00000000001) |
||
local yearNum = 0 |
local yearNum = 0 |
||
第37行: | 第40行: | ||
micNum = micNum - 99995 - j |
micNum = micNum - 99995 - j |
||
yearNum = yearNum + 1 |
yearNum = yearNum + 1 |
||
until (micNum |
until (micNum < 99995 + j) |
||
end |
end |
||
local cycleNum = math.floor(yearNum / 144 + 0.00000000001) |
local cycleNum = math.floor(yearNum / 144 + 0.00000000001) |
||
第46行: | 第49行: | ||
micNum = micNum - seasonNum * 10000 |
micNum = micNum - seasonNum * 10000 |
||
local weekNum = math.floor(micNum / 1000 + 0.00000000001) |
local weekNum = math.floor(micNum / 1000 + 0.00000000001) |
||
micNum = micNum - weekNum * |
micNum = micNum - weekNum * 1000 |
||
local hourNum = math.floor(micNum / 100 + 0.00000000001) |
local hourNum = math.floor(micNum / 100 + 0.00000000001) |
||
micNum = micNum - hourNum * |
micNum = micNum - hourNum * 100 |
||
return {cycleNum, divisionNum, yearNum, seasonNum, weekNum, hourNum, micNum} |
return {cycleNum, divisionNum, yearNum, seasonNum, weekNum, hourNum, micNum} |
||
end |
|||
function module.convert(time) |
|||
return module.sec2date(module.timeDelta(os.time(time))) |
|||
end |
|||
function module.convertNow(time) |
|||
return module.sec2date(module.timeDelta(os.time())) |
|||
end |
end |
||
2022年4月28日 (四) 21:24的版本
可在Module:IUCDate/doc创建此模块的帮助文档
-- 星际统一历日期转换,作者:QWERTY_52_38
local module = {}
origin = os.time({year=2022,month=4,day=1,hour=22,minute=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.timeDelta(time)
-- 与纪元起点的差值
return time - origin
end
function module.sec2date(sec)
-- 将module.timeDelta得到的差值(单位为秒)转换为星际统一历时间
local micNum = math.floor(sec / mic + 0.00000000001)
local yearNum = 0
if micNum >= 99995 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.convert(time)
return module.sec2date(module.timeDelta(os.time(time)))
end
function module.convertNow(time)
return module.sec2date(module.timeDelta(os.time()))
end
return module