Module:ScheduleList:修订间差异

跳转到导航 跳转到搜索
无编辑摘要
无编辑摘要
 
(未显示同一用户的12个中间版本)
第12行: 第12行:
end
end


-- 工具函数:将输入的 `yydd` 转换为 `X月X日`
-- 工具函数:将输入的 `mmdd` 转换为 `X月X日`
local function format_date(yydd)
local function format_date(mmdd)
     local month = tonumber(string.sub(yydd, 1, 2)) -- 前两位是月份
    local months = {"1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"}
     local day = tonumber(string.sub(yydd, 3, 4))  -- 后两位是日期
     local month = tonumber(string.sub(mmdd, 1, 2)) -- 前两位是月份
     return string.format("%d月%d日", month, day)
     local day = tonumber(string.sub(mmdd, 3, 4))  -- 后两位是日期
     return string.format("%s%d日", months[month], day)
end
end


-- 工具函数:计算下一个日期
-- 工具函数:计算下一个日期
local function get_next_date(yydd, leap_year)
local function get_next_date(mmdd, leap_year)
     local month = tonumber(string.sub(yydd, 1, 2))
     local month = tonumber(string.sub(mmdd, 1, 2))
     local day = tonumber(string.sub(yydd, 3, 4))
     local day = tonumber(string.sub(mmdd, 3, 4))
      
      
     local days_in_current_month = days_in_month(month, leap_year)
     local days_in_current_month = days_in_month(month, leap_year)
第47行: 第48行:
local function format_date_line(frame, date, time, week, title, css_class)
local function format_date_line(frame, date, time, week, title, css_class)
     local formatted_date = format_date(date)
     local formatted_date = format_date(date)
     local ruby_output = frame:expandTemplate{
 
         title = "ruby",
     -- 如果标题为空,设置默认值为“无”
        args = {formatted_date, time}
    if not title or title == "" then
     }
         title = ""
     if css_class and css_class ~= "" then
    end
         return string.format(
 
            '<li class="%s" style="display: flex;">' ..
     local schedule_output
            '<div class="datetime"><span>%s<small>%s</small></span></div>' ..
     if title == "" then
             '<div class="title">%s</div>' ..
         css_class = (css_class and css_class .. " " or "") .. "offline" -- 标题为空时,添加“offline”类
            '</li>',
        schedule_output = frame:expandTemplate{
             css_class, ruby_output, week, title
             title = "ScheduleList/date",
         )
             args = {formatted_date, "", week, title} -- 时间为空,标题为“无”
         }
     else
     else
         return string.format(
         css_class = (css_class and css_class .. " " or "") .. "online" -- 标题存在时,添加“online”类
            '<li style="display: flex;">' ..
        time = time or "2:00" -- 如果未提供时间,使用默认值 "2:00"
            '<div class="datetime"><span>%s<small>%s</small></span></div>' ..
        schedule_output = frame:expandTemplate{
             '<div class="title">%s</div>' ..
             title = "ScheduleList/date",
             '</li>',
             args = {formatted_date, time .. " (UTC+8)", week, title} -- 时间和标题正常显示
            ruby_output, week, title
         }
         )
     end
     end
    -- 构建 HTML 输出
    return string.format(
        '<li class="%s" style="display: flex;">' ..
        '<div class="datetime">%s</div>' ..
        '</li>',
        css_class, schedule_output
    )
end
end


第75行: 第84行:


     -- 获取初始参数
     -- 获取初始参数
     local date = args.date -- 输入的日期为 `yydd` 格式
     local date = args.date -- 输入的日期为 `mmdd` 格式
     local week = tonumber(args.week) -- 输入的周几 (1~7)
     local week = tonumber(args.week) -- 输入的周几 (1~7)
     local leap_year = args.leap_year == "yes" -- 闰年判断
     local leap_year = args.leap_year == "yes" -- 闰年判断
    local time_default = "2:00"


     -- 如果没有输入初始日期,则报错
     -- 如果没有输入初始日期,则报错
第91行: 第99行:
     -- 循环生成7行
     -- 循环生成7行
     for i = 1, 7 do
     for i = 1, 7 do
         local title = args["title" .. i] or "无" -- 未提供标题时默认 "无"
         local title = args["title" .. i] -- 每行的标题
         local time = args["time" .. i] or time_default -- 未提供时间时默认 "2:00"
         local time = args["time" .. i] -- 每行的时间(可以为空)
         local css_class = args["class" .. i] -- 每行的 CSS 类
         local css_class = args["class" .. i] -- 每行的 CSS 类
         local week_day = get_weekday(current_weekday) -- 计算周几
         local week_day = get_weekday(current_weekday) -- 计算周几


         -- 格式化每一行
         -- 格式化每一行
         table.insert(result, format_date_line(frame, current_date, time"(UTF+8)", week_day, title, css_class))
         table.insert(result, format_date_line(frame, current_date, time, week_day, title, css_class))


         -- 更新日期和周几
         -- 更新日期和周几