跳转到内容

模板:生物联赛倒计时:修订间差异

来自osm&bio
Magezeya留言 | 贡献
无编辑摘要
Magezeya留言 | 贡献
无编辑摘要
第1行: 第1行:
<includeonly>
local p = {}
<!-- 主容器 -->
<div style="font-family: 'Segoe UI', system-ui, sans-serif; max-width: 500px; margin: 20px auto; text-align: center; background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%); color: white; padding: 25px; border-radius: 15px; box-shadow: 0 5px 15px rgba(0,0,0,0.1);">


<!-- 标题 -->
-- 预定义的联赛日期表(2025-2035年五月的第二个星期日)
<h1 style="margin: 0 0 15px; font-size: 1.8em; text-shadow: 1px 1px 3px rgba(0,0,0,0.2);">全国生物学竞赛倒计时</h1>
local olympiadDates = {
<p style="margin: 0 0 20px; opacity: 0.9;">每年的五月第二个星期日</p>
    "2025-05-11",
    "2026-05-10",
    "2027-05-09",
    "2028-05-14",
    "2029-05-13",
    "2030-05-12",
    "2031-05-11",
    "2032-05-09",
    "2033-05-08",
    "2034-05-14",
    "2035-05-13"
}


<!-- 倒计时显示 -->
function p.getNextDate()
<div style="background: rgba(255,255,255,0.15); padding: 15px; border-radius: 10px; backdrop-filter: blur(5px);">
    local currentTime = os.time()
  <div style="font-size: 0.9em; margin-bottom: 10px; opacity: 0.8;">距离{{#switch: {{CURRENTYEAR}}
   
    {{#ifexpr: {{#time: n}} > 5 or ({{#time: n}} = 5 and {{#time: j}} > {{#switch: {{CURRENTYEAR}}
     for i, dateStr in ipairs(olympiadDates) do
      |2024=12
        local datePattern = "(%d+)-(%d+)-(%d+)"
      |2025=11
        local year, month, day = dateStr:match(datePattern)
      |2026=10
         local olympiadTime = os.time({year = year, month = month, day = day})
      |2027=9
          
      |2028=14
        if olympiadTime > currentTime then
      |2029=13
            return dateStr
      |2030=12
         end
      |#default=12
    end
     }})}}
   
      |{{#expr: {{CURRENTYEAR}} + 1}}
    -- 如果所有日期都已过去,返回最后一个日期
    |{{CURRENTYEAR}}
    return olympiadDates[#olympiadDates]
  {{/ifexpr}}}}年联赛还有</div>
end
 
  <div style="font-size: 2.5em; font-weight: bold; margin: 10px 0; text-shadow: 2px 2px 4px rgba(0,0,0,0.3);">
    {{#switch: {{CURRENTYEAR}}
      {{#ifexpr: {{#time: n}} > 5 or ({{#time: n}} = 5 and {{#time: j}} > {{#switch: {{CURRENTYEAR}}
        |2024=12
        |2025=11
        |2026=10
        |2027=9
        |2028=14
        |2029=13
        |2030=12
        |#default=12
      }})}}
         |{{Countdown|{{#switch: {{#expr: {{CURRENTYEAR}} + 1}}
          |2024=2024-05-12
          |2025=2025-05-11
          |2026=2026-05-10
          |2027=2027-05-09
          |2028=2028-05-14
          |2029=2029-05-13
          |2030=2030-05-12
          |#default=2030-05-12
        }}|text=天}}
      |{{Countdown|{{#switch: {{CURRENTYEAR}}
          |2024=2024-05-12
          |2025=2025-05-11
          |2026=2026-05-10
          |2027=2027-05-09
          |2028=2028-05-14
          |2029=2029-05-13
          |2030=2030-05-12
          |#default=2030-05-12
        }}|text=天}}
    {{/ifexpr}}
  </div>
 
  <div style="font-size: 0.9em; opacity: 0.8;">
    {{#switch: {{CURRENTYEAR}}
      {{#ifexpr: {{#time: n}} > 5 or ({{#time: n}} = 5 and {{#time: j}} > {{#switch: {{CURRENTYEAR}}
        |2024=12
        |2025=11
        |2026=10
        |2027=9
        |2028=14
        |2029=13
        |2030=12
        |#default=12
      }})}}
         |比赛日期: {{#switch: {{#expr: {{CURRENTYEAR}} + 1}}
          |2024=2024年5月12日
          |2025=2025年5月11日
          |2026=2026年5月10日
          |2027=2027年5月9日
          |2028=2028年5月14日
          |2029=2029年5月13日
          |2030=2030年5月12日
          |#default=2030年5月12日
         }}
      |比赛日期: {{#switch: {{CURRENTYEAR}}
          |2024=2024年5月12日
          |2025=2025年5月11日
          |2026=2026年5月10日
          |2027=2027年5月9日
          |2028=2028年5月14日
          |2029=2029年5月13日
          |2030=2030年5月12日
          |#default=2030年5月12日
        }}
    {{/ifexpr}}
  </div>
</div>


<!-- 装饰元素 -->
return p
<div style="margin-top: 20px; display: flex; justify-content: center; gap: 8px;">
  <span style="display: inline-block; width: 12px; height: 12px; background: rgba(255,255,255,0.5); border-radius: 50%;"></span>
  <span style="display: inline-block; width: 12px; height: 12px; background: rgba(255,255,255,0.5); border-radius: 50%;"></span>
  <span style="display: inline-block; width: 12px; height: 12px; background: rgba(255,255,255,0.5); border-radius: 50%;"></span>
</div>
</div>
</includeonly>
 
<noinclude>
== 全国生物学竞赛倒计时模板 ==
这是一个显示全国生物学竞赛倒计时的模板,比赛日期为每年的五月第二个星期日。
 
=== 使用方法 ===
只需在任意页面插入以下代码:
<pre>
{{全国生物学竞赛倒计时}}
</pre>
 
=== 功能特点 ===
* 使用查表法预计算2024-2030年的比赛日期
* 自动判断今年是否已过比赛日期,显示下一年的比赛
* 使用现有的Countdown模板显示天数
* 美观的UI设计
 
=== 维护说明 ===
本模板内置了2024年至2030年的比赛日期,2030年之后需要更新模板。
 
[[Category:倒计时模板]]
[[Category:教育模板]]
</noinclude>

2025年8月22日 (五) 12:00的版本

local p = {}

-- 预定义的联赛日期表(2025-2035年五月的第二个星期日) local olympiadDates = {

   "2025-05-11",
   "2026-05-10",
   "2027-05-09",
   "2028-05-14",
   "2029-05-13",
   "2030-05-12",
   "2031-05-11",
   "2032-05-09",
   "2033-05-08",
   "2034-05-14",
   "2035-05-13"

}

function p.getNextDate()

   local currentTime = os.time()
   
   for i, dateStr in ipairs(olympiadDates) do
       local datePattern = "(%d+)-(%d+)-(%d+)"
       local year, month, day = dateStr:match(datePattern)
       local olympiadTime = os.time({year = year, month = month, day = day})
       
       if olympiadTime > currentTime then
           return dateStr
       end
   end
   
   -- 如果所有日期都已过去,返回最后一个日期
   return olympiadDates[#olympiadDates]

end

return p