用户:CrablePotion/模板/TimeFilter:修订间差异

+ doc
无编辑摘要
(+ doc)
<onlyinclude>{{
#vardefine:currentY|{{#time:Y|now|+{{{UTC|08}}} hours}}}}{{
#vardefine:currentM|{{#time:n|now|+{{{UTC|08}}} hours}}}}{{
#vardefine:currentD|{{#time:j|now|+{{{UTC|08}}} hours}}}}{{
#vardefine:matchdate|0}}{{
#vardefine:matchrange|0}}{{
| 1 = {{#ifexpr:{{#var:matchrange}}|{{{返回|}}}}}
| 2 = {{#ifexpr:{{#var:matchdate}} - {{#var:matchrange}} = 0||{{{返回|}}}}}
}}</onlyinclude>{{
doc|content=
这个模板用于判断现在的时间是否与规则匹配,如果匹配则返回指定内容。
== 用法 ==
该模板有三种匹配方式:
# 匹配确切时间,即参数<code>范围=0</code>(默认),且<code>年</code>、<code>月</code>、<code>日</code>任意一个不为空。如果<code>月=3</code>,则会匹配3月的每一天;如果<code><nowiki>月=3|日=1</nowiki></code>,则会匹配每年的3月1日。
# 匹配特定范围内的时间,即参数<code>范围=1</code>,且<code>始</code>、<code>末</code>任意一个不为空。需要注意的是,无论是<code>始</code>还是<code>末</code>,输入的都需要是unix时间戳。如果<code>始=946656000</code>(对应时间2000-01-01 00:00:00),则会匹配自2000-01-01 00:00:00之后的时间;如果<code>始=946656000</code>且<code>末=1704038400</code>(2024-01-01 00:00:00),则会匹配从2000-01-01 00:00:00开始,到2024-01-01 00:00:00结束的时间。参数<code>始</code>和<code>末</code>必须使得<code>始</code><=<code>末</code>。
# 混合模式,即参数<code>范围=2</code>,且同时满足1与2的条件:<code>年</code>、<code>月</code>、<code>日</code>任意一个不为空,<code>始</code>、<code>末</code>任意一个不为空。如果<code>始=946656000</code>,<code>末=1704038400</code>,<code>月=3</code>,则会匹配从2000年至2024年3月的每一天。
举例:
<code><nowiki>{{用户:CrablePotion/模板/WhatDayIsToday|UTC=0|范围=0|年=2024|返回=true}}</nowiki></code> 在2024年(世界协调时)时会返回true,反之不返回。<br>效果如下:{{用户:CrablePotion/模板/WhatDayIsToday|UTC=0|范围=0|年=2024|返回=true}}(没有返回就说明现在不是2024年)
}}<templatedata>
{
"params": {
"UTC": {
"label": "时区",
"type": "string",
"description": "当前时区的UTC值",
"default": "8 (北京时间)"
},
"年": {
"label": "年",
"type": "string",
"description": "匹配的年份"
},
"月": {
"label": "月",
"type": "string",
"description": "匹配的月份"
},
"日": {
"label": "日",
"type": "string",
"description": "匹配的日期"
},
"始": {
"label": "开始的时间点",
"type": "string",
"description": "开始的unix时间戳"
},
"末": {
"label": "末尾的时间点",
"type": "string",
"description": "末尾的unix时间戳"
},
"范围": {
"label": "是否启用范围",
"type": "string",
"description" : "0-不启用;1-仅范围;2-混合",
"default": "0 (不启用)"
},
"返回": {
"label": "返回内容",
"type": "string",
"description":"判断为真时返回的内容,作为wikitext解析",
"required": true
}
},
"description": "判断当前时间是否与规则匹配"
}</templatedata>
934

个编辑