查看“Module:ScheduleList”的源代码
←
Module:ScheduleList
跳转到导航
跳转到搜索
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
您必须确认您的电子邮件地址才能编辑页面。请通过
参数设置
设置并确认您的电子邮件地址。
您可以查看和复制此页面的源代码。
local p = {} -- 工具函数:判断是否为闰年 local function is_leap_year(year) return (year % 4 == 0 and year % 100 ~= 0) or (year % 400 == 0) end -- 工具函数:计算每月天数 local function days_in_month(month, leap_year) local days = {31, leap_year and 29 or 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} return days[month] end -- 工具函数:将输入的 `mmdd` 转换为 `X月X日` local function format_date(mmdd) local months = {"1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"} local month = tonumber(string.sub(mmdd, 1, 2)) -- 前两位是月份 local day = tonumber(string.sub(mmdd, 3, 4)) -- 后两位是日期 return string.format("%s%d日", months[month], day) end -- 工具函数:计算下一个日期 local function get_next_date(mmdd, leap_year) local month = tonumber(string.sub(mmdd, 1, 2)) local day = tonumber(string.sub(mmdd, 3, 4)) local days_in_current_month = days_in_month(month, leap_year) if day == days_in_current_month then day = 1 month = month + 1 if month > 12 then month = 1 end else day = day + 1 end return string.format("%02d%02d", month, day) -- 返回格式化的 mmdd 格式 end -- 工具函数:计算周几 local function get_weekday(weekday) local weekdays = {"周一", "周二", "周三", "周四", "周五", "周六", "周日"} return weekdays[(weekday - 1) % 7 + 1] end -- 格式化日期行 local function format_date_line(frame, date, time, week, title, css_class) local formatted_date = format_date(date) -- 如果标题为空,设置默认值为“无” if not title or title == "" then title = "无" end local schedule_output if title == "无" then css_class = (css_class and css_class .. " " or "") .. "offline" -- 标题为空时,添加“offline”类 schedule_output = frame:expandTemplate{ title = "ScheduleList/date", args = {formatted_date, "", week, title} -- 时间为空,标题为“无” } else css_class = (css_class and css_class .. " " or "") .. "online" -- 标题存在时,添加“online”类 time = time or "2:00" -- 如果未提供时间,使用默认值 "2:00" schedule_output = frame:expandTemplate{ title = "ScheduleList/date", args = {formatted_date, time .. " (UTC+8)", week, title} -- 时间和标题正常显示 } end -- 构建 HTML 输出 return string.format( '<li class="%s" style="display: flex;">' .. '<div class="datetime">%s</div>' .. '</li>', css_class, schedule_output ) end -- 主函数 function p.main(frame) local args = frame:getParent().args -- 获取初始参数 local date = args.date -- 输入的日期为 `mmdd` 格式 local week = tonumber(args.week) -- 输入的周几 (1~7) local leap_year = args.leap_year == "yes" -- 闰年判断 -- 如果没有输入初始日期,则报错 if not date then return "请提供初始日期 (date 参数,格式为 mmdd)!" end if not week or week < 1 or week > 7 then return "请提供正确的初始周几 (week 参数,1~7)!" end -- 初始化结果表 local result = {} local current_date = date local current_weekday = week -- 循环生成7行 for i = 1, 7 do local title = args["title" .. i] -- 每行的标题 local time = args["time" .. i] -- 每行的时间(可以为空) local css_class = args["class" .. i] -- 每行的 CSS 类 local week_day = get_weekday(current_weekday) -- 计算周几 -- 格式化每一行 table.insert(result, format_date_line(frame, current_date, time, week_day, title, css_class)) -- 更新日期和周几 current_date = get_next_date(current_date, leap_year) current_weekday = current_weekday + 1 end -- 包装在 <ul> 中,作为返回结果 return '<ul class="schedule-list">' .. table.concat(result, "\n") .. '</ul>' end return p
该页面使用的模板:
Module:ScheduleList/doc
(
查看源代码
)
返回
Module:ScheduleList
。
导航菜单
个人工具
中文
创建账号
登录
命名空间
模块
讨论
English
查看
阅读
查看源代码
查看历史
更多
搜索
导航
首页
最近更改
最新文件
随机页面
官方Discord
浏览NeuroWiki
人物列表
直播记录
梗列表
事件列表
物品列表
场景列表
辟谣专区
帮助
帮助
沙盒
NeuroWiki政策文件
编辑规范
怎么正确编辑&更新?
工具
链入页面
相关更改
上传文件
特殊页面
页面信息