跳转到内容

Template:Date table sorting/doc

维基百科,自由的百科全书

这是本页的一个历史版本,由Ultrakwan留言 | 贡献2019年12月30日 (一) 06:02 處理錯誤编辑。这可能和当前版本存在着巨大的差异。

DTS代表Date Table Sorting(以日期排序),用於在能排序表格裡整理和顯示日期(幫助:排序(英文))。

它解決的問題

通常如果要排序的話,日期必須要使用YYYY-MM-DD的格式輸入。但是,這格式與格式手冊中指定的格式不同。這模板會自動製作用作排序的<span style="display:none">1776-07-04</span>,但會以July 4, 1776的形式顯示。如果想要使輸出隱藏,請使用{{dtsh}} 模板。

參數

年月日不一定要分開輸入。
{{dts||||公元前}} {{dts|}}
  • 第一個參數 – 年份(如月份不為空可選)
    • 年份:范围-9999到9999。在未使用bc的情况下,-9999到0被认为是-9999到0年。1-9999的数字默认代表公元后年份,若第4个参数被设置为 bc 或 BC 的话,表示它代表公元前年份。
  • 第二个参数 – 月份(如日为空可选)
    • 月份的全称 – February 或 february
    • 月份的缩写– Feb 或 feb
    • 月份的数字 – 2 或者 02
  • 第三个参数 – 日(可选)
    • 日期数字 – 7 或 07
  • 第四个参数 – 可选,或者填写BC 或 bc
    • 当年份值为正时使用

所以,例如公元前5年,可以使用 "5|bc" or "-4"。

A time period (year or month and year) is sorted according to its start, and time periods with the same starting moment are in order of descending length: a year comes before its first month; a month comes before its first day.

  • 第一个参数 – 完整日期。国际格式、美国格式或 YYYY-MM-DD 格式
    • 模板使用{{#time:}},所以它也受解析器函数的限制(例如不支持公元100年以下)
    • 国际格式的日期不会被改变。YYYY-MM-DD 式日期默认会转换到US格式。
    • 可以接受月份缩写
    • 大小写和符号错误将被改正

输入

{{dts|year|month|day|BC}}

  • {{dts|1776|July|4}}

{{dts|date}}

  • {{dts|1776-07-04}}
  • {{dts|July 4, 1776}}
  • {{dts|4 July 1776}}

当处理单一的日期参数时,除非只有一个数字(那么它将被解释为年份),模板将根据php date/time format来解释参数。默认就是按照输入的参数来显示的。若果第一個参数不是只是年份,但又沒有提供格式参数,由於有一個函數#time的召喚,一個頁面中使用本模板的最多召喚次數是1200。

Using format=mdy, format=dmy, or format=auto produces a format that depends on, but is not necessarily equal to the format of the supplied date. This requires multiple calls of function #time, reducing the maximum number of calls of this template on a page in the worst case to 88, see below.

另外請參見下方的例子

输出

發送到表格的輸出

  • <span style="display:none">01776-07-04</span> July 4, 1776
  • <span style="display:none">01776-07-04</span> 4 July 1776

顯示給用戶的輸出

  • July 4, 1776 或
  • 4 July 1776

链接

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

例子

Normal function of the template. The template with debug=yes, which causes hidden parts to appear:

Template:Dts/examples

Template:Dts/examples

註解

處理錯誤

輸入無效的日期格式(通常)會產生一條錯誤消息,例如以下內容。

Module:Date table sorting錯誤:6月只有30天,沒有「第35天」!

參見

  • {{sort}},以一個特定的鑰匙排序
  • {{sortname}},排序人名(用姓氏和名稱作為預設排序鑰匙)。
  • {{tts}},用於在體育賽事結果表中排序時間(只需要用於一定情況——參見該模板的文档页面)
  • {{number table sorting}},為數字而設