Module:ScheduleList:修订间差异
跳转到导航
跳转到搜索
无编辑摘要 |
无编辑摘要 |
||
第10行: | 第10行: | ||
local days = {31, leap_year and 29 or 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} | local days = {31, leap_year and 29 or 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} | ||
return days[month] | return days[month] | ||
end | |||
-- 工具函数:将输入的 `yydd` 转换为 `X月X日` | |||
local function format_date(yydd) | |||
local month = tonumber(string.sub(yydd, 1, 2)) -- 前两位是月份 | |||
local day = tonumber(string.sub(yydd, 3, 4)) -- 后两位是日期 | |||
return string.format("%d月%d日", month, day) | |||
end | end | ||
-- 工具函数:计算下一个日期 | -- 工具函数:计算下一个日期 | ||
local function get_next_date( | local function get_next_date(yydd, leap_year) | ||
local month | local month = tonumber(string.sub(yydd, 1, 2)) | ||
local day = tonumber(string.sub(yydd, 3, 4)) | |||
local days_in_current_month = days_in_month(month, nil, leap_year) | local days_in_current_month = days_in_month(month, nil, leap_year) | ||
第29行: | 第35行: | ||
end | end | ||
return string.format("% | return string.format("%02d%02d", month, day) -- 返回格式化的 yydd 格式 | ||
end | end | ||
第43行: | 第49行: | ||
-- 获取初始参数 | -- 获取初始参数 | ||
local date = args.date | local date = args.date -- 输入的日期为 `yydd` 格式 | ||
local week = tonumber(args.week) | local week = tonumber(args.week) -- 输入的周几 (1~7) | ||
local leap_year = args.leap_year == "yes" | local leap_year = args.leap_year == "yes" -- 闰年判断 | ||
-- 如果没有输入初始日期,则报错 | -- 如果没有输入初始日期,则报错 | ||
if not date then return "请提供初始日期 (date | if not date then return "请提供初始日期 (date 参数,格式为 yydd)!" end | ||
if not week or week < 1 or week > 7 then return "请提供正确的初始周几 (week 参数,1~7)!" end | if not week or week < 1 or week > 7 then return "请提供正确的初始周几 (week 参数,1~7)!" end | ||
第66行: | 第72行: | ||
local ruby_output = frame:expandTemplate{ | local ruby_output = frame:expandTemplate{ | ||
title = "ruby", | title = "ruby", | ||
args = {current_date, time} | args = {format_date(current_date), time} | ||
} | } | ||