加帕里图书馆 - 兽娘动物园中文维基
动物朋友 けものフレンズ KemonoFriends百科

模块:历史事件:修订间差异

来自加帕里图书馆
跳转到导航 跳转到搜索
黯狐留言 | 贡献
无编辑摘要
黯狐留言 | 贡献
无编辑摘要
 
(未显示同一用户的1个中间版本)
第6行: 第6行:
     local years_since_start = current_year - project_start_year
     local years_since_start = current_year - project_start_year
     return string.format(
     return string.format(
         "**距离企划开始已经%d年**",
         "距离企划开始已经%d年",
         years_since_start
         years_since_start
     )
     )
第16行: 第16行:


     local current_year = tonumber(os.date("%Y"))
     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, "")
      
      
     local current_time = os.time()
     -- 现在 output 数组是: [ "距离企划开始...", "", ... ]
      
      
     for i = -10, 10 do
     for i = -10, 10 do
第49行: 第57行:
     end)
     end)
      
      
    local refresh_date = mw.getContentLanguage():formatDate("Ynj")
    table.insert(output, "")
     if #all_events > 0 then
     if #all_events > 0 then
        -- 循环插入事件列表
         for _, event in ipairs(all_events) do
         for _, event in ipairs(all_events) do
             local years_ago = current_year - event.year
             local years_ago = current_year - event.year
              
              
            -- 格式:2019年12月10日 (6 年前): xxxx
             local line = string.format(
             local line = string.format(
                 "* '''%d年%d月%d日''' (%d 年前): %s",
                 "* '''%d年%d月%d日''' (%d 年前): %s",

2025年12月12日 (五) 13:16的最新版本

此模块的文档可以在模块:历史事件/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