跳转到内容

模板:Date table sorting/sandbox

本页使用了标题或全文手工转换
维基百科,自由的百科全书
文档图示 模板文档[查看] [编辑] [历史] [清除缓存]

DTS代表Date Table Sorting(以日期排序),用于在能排序表格里整理和显示日期(帮助:排序(英文))。

它解决的问题[编辑]

通常如果要排序的话,日期必须要使用YYYY-MM-DD的格式输入。但是,这格式与格式手册中指定的格式不同。这模板会自动制作用作排序的排序键,但会以另外的形式显示输出(例如年-月-日)。

参数[编辑]

日期[编辑]

年月日不一定要分开输入。
{{dts||||时代}} {{dts|日期}}
  • 第一个参数 – 年份(如月份不空缺就非必要)
    • 正数(1 到 9999)代表公元前或公元后年份(视乎第四个参数),第四个参数空缺的话,默认代表公元后年份。
    • 负数(−1 到 −9999)代表公元前年份(第四个参数必须空缺)。
  • 第二个参数 – 月份(如日子空缺就非必要)
    • 月份的全称 – February 或 february
    • 月份的缩写– Feb 或 feb
    • 月份的数字 – 2 或者 02
  • 第三个参数 – 日子(非必要)
    • 日期数字 – 7 或 07
  • 第四个参数 – (非必要)
    • 可以是 BC、AD、BCE 或 CE
    • 当年份值为正时使用
  • 第一个参数 – 完整日期。国际格式、美国格式[需要解释]或 YYYY-MM-DD 格式
    • 国际格式的日期不会被改变。YYYY-MM-DD 式日期默认会转换到US格式。
    • 可以接受月份缩写
    • 大小写和逗号错误将被改正
    • 模板使用{{#time:}},所以它也受解析器函数的限制(例如不支持公元100年以下)
例子
输入风格 输入码 隐藏排序键 显示的输出

Template:Date table sorting/sandbox/row Template:Date table sorting/sandbox/row Template:Date table sorting/sandbox/row Template:Date table sorting/sandbox/row Template:Date table sorting/sandbox/row Template:Date table sorting/sandbox/row Template:Date table sorting/sandbox/row Template:Date table sorting/sandbox/row Template:Date table sorting/sandbox/row Template:Date table sorting/sandbox/row Template:Date table sorting/sandbox/row Template:Date table sorting/sandbox/row Template:Date table sorting/sandbox/row Template:Date table sorting/sandbox/row Template:Date table sorting/sandbox/row Template:Date table sorting/sandbox/row Template:Date table sorting/sandbox/row Template:Date table sorting/sandbox/row

格式化[编辑]

使用format可以做出一个依赖但不需要相同于提供日期的格式。这需要多次调用函数 {{#time:}},减少一个页面中使用本模板的最多召唤次数到最差88次,参见下方。format 参数可以用九个数值。

例子
Template:Date table sorting/sandbox/rowTemplate:Date table sorting/sandbox/rowTemplate:Date table sorting/sandbox/rowTemplate:Date table sorting/sandbox/row
输出格式 输入码 隐藏排序键 显示的输出

Template:Date table sorting/sandbox/row Template:Date table sorting/sandbox/row Template:Date table sorting/sandbox/row

Template:Date table sorting/sandbox/row Template:Date table sorting/sandbox/row Template:Date table sorting/sandbox/row Template:Date table sorting/sandbox/row

Template:Date table sorting/sandbox/row Template:Date table sorting/sandbox/row Template:Date table sorting/sandbox/row Template:Date table sorting/sandbox/row

Template:Date table sorting/sandbox/row

Template:Date table sorting/sandbox/row

Template:Date table sorting/sandbox/row

Template:Date table sorting/sandbox/row

Template:Date table sorting/sandbox/row

注意:以下格式的值皆视为无效

当处理单一的日期参数时,除非只有一个数字(那么它将被解释为年份),模板将根据php date/time format来解释参数。但由于中文习惯的格式的影响,默认皆是使用年-月-日由于本模板调用函数{{#time:}},因此单一页面中最多仅能使用本模板1200次。[需要解释]

缩写[编辑]

在中文版本,只有一个方法缩写日期:使用 abbr=on 参数。

例子
缩写方法 输入码 隐藏排序键 显示的输出

Template:Date table sorting/sandbox/row Template:Date table sorting/sandbox/row Template:Date table sorting/sandbox/row Template:Date table sorting/sandbox/row Template:Date table sorting/sandbox/row Template:Date table sorting/sandbox/row Template:Date table sorting/sandbox/row Template:Date table sorting/sandbox/row Template:Date table sorting/sandbox/row Template:Date table sorting/sandbox/row

额外排序键[编辑]

如果表格内的两个日期一样,它们可以利用参数 addkey 排序。

例子
输入码 隐藏排序键 显示的输出

Template:Date table sorting/sandbox/row Template:Date table sorting/sandbox/row Template:Date table sorting/sandbox/row Template:Date table sorting/sandbox/row Template:Date table sorting/sandbox/row Template:Date table sorting/sandbox/row Template:Date table sorting/sandbox/row

文字换行[编辑]

要关闭自动换行的话,请使用nowrap=off参数。

注解[编辑]

排序非完整日期[编辑]

完整年份或月份[编辑]

完整年份或月份(或完整年月),例如{{dts|2020}}{{dts|Jan}}{{dts|2020|1}},系统会按其第一个日子排序。

没有年份[编辑]

如果未指定年份,系统将会视年份为现时年份来进行排序。

处理错误[编辑]

输入无效的日期格式(通常)会产生一条错误消息,例如{{dts||維基百科}}会产生以下内容:

Module:Date table sorting错误:给出的月份“维基百科”月不合理。

历法选择[编辑]

本模板无法区分儒略历和公历日期。另外,它不能从一个历法输入日期并按另一历法输出日期。所以,要确保排序良好,用户必须把日期统一于一个历法,或者确定一个转折日(例如,确定1582年10月4日为儒略历,以后的所有日期为公历),这可以用一条条的方法实现。如果可能造成混淆,用家有责任解释给读者究竟显示的日期是儒略历还是公历。

链接[编辑]

本模板默认自动链接到日期。若要关闭链接,则可使用参数link=off。根据目前的指引,此模板不再支持日期的内部链接。请不要使用此参数,并请将此参数从目前的模板调用中移除。

参见[编辑]

  • {{sort}},以一个特定的钥匙排序
  • {{sortname}},排序人名(用姓氏和名称作为默认排序钥匙)。
  • {{tts}},用于在体育赛事结果表中排序时间(只需要用于一定情况——参见该模板的文档页面)
  • {{number table sorting}},为数字而设