加帕里图书馆 - 兽娘动物园中文维基
动物朋友 けものフレンズ KemonoFriends百科
模块:历史事件
跳转到导航
跳转到搜索
此模块的文档可以在模块:历史事件/doc创建
local p = {}
local data = mw.loadData('Module:历史上的今天/数据')
local function calculate_project_age(current_year)
local project_start_year = 2014
local years_since_start = current_year - project_start_year
return string.format(
"距离企划开始已经%d年",
years_since_start
)
end
function p.show_range()
local all_events = {}
local output = {}
local current_year = tonumber(os.date("%Y"))
local current_time = os.time()
local refresh_date = mw.getContentLanguage():formatDate("Ynj")
local project_age_string = calculate_project_age(current_year)
table.insert(output, project_age_string)
table.insert(output, "")
-- 现在 output 数组是: [ "距离企划开始...", "", ... ]
for i = -10, 10 do
local offset_time = current_time + (i * 24 * 60 * 60)
local month = tonumber(os.date("%m", offset_time))
local day = tonumber(os.date("%d", offset_time))
local key = month .. "-" .. day
local events = data[key]
if events then
for _, item in ipairs(events) do
table.insert(all_events, {
sort_key = month * 100 + day,
year = item.year,
month = month,
day = day,
event_desc = item.event
})
end
end
end
table.sort(all_events, function(a, b)
if a.sort_key ~= b.sort_key then
return a.sort_key < b.sort_key
else
return a.year < b.year
end
end)
if #all_events > 0 then
-- 循环插入事件列表
for _, event in ipairs(all_events) do
local years_ago = current_year - event.year
local line = string.format(
"* '''%d年%d月%d日''' (%d 年前): %s",
event.year,
event.month,
event.day,
years_ago,
event.event_desc
)
table.insert(output, line)
end
else
table.insert(output, "近二十一天内没有历史事件记录")
end
-- 添加脚注/链接
table.insert(output, "\n<div style=\"text-align: right; margin-top: 5px; font-size: 85%;\">")
table.insert(output, "[[年表|查看完整年表]]")
table.insert(output, "</div>")
return table.concat(output, "\n")
end
return p