模板:Date table sorting/doc

出自Local Chinese Wikipedia
跳至導覽 跳至搜尋

Template:NoteTA/MediaWiki 腳本錯誤:沒有「Message box」這個模塊。 Template:Lua 頁面Template:楷體/styles.css沒有內容。 DTS代表Date Table Sorting(以日期排序),用於在能排序表格裏整理和顯示日期(幫助:排序(英文))。

簡介[編輯]

通常如果要排序的話,日期必須要使用YYYY-MM-DD的格式輸入。但是,這格式與格式手冊中指定的格式不同。這模板會自動製作用作排序的排序鍵,但會以另外的形式顯示輸出(例如年-月-日)。

參數[編輯]

日期[編輯]

年月日不一定要分開輸入。
腳本錯誤:沒有「Tlg」這個模塊。 腳本錯誤:沒有「Tlg」這個模塊。
  • 第一個參數 – 年份(如月份不空缺就非必要)
    • 正數(1 到 9999)代表公元前或公元後年份(視乎第四個參數),第四個參數空缺的話,默認代表公元後年份。
    • 負數(−1 到 −9999)代表公元前年份(第四個參數必須空缺)。
  • 第二個參數 – 月份(如日子空缺就非必要)
    • 月份的全稱 – February 或 february
    • 月份的縮寫– Feb 或 feb
    • 月份的數字 – 2 或者 02
  • 第三個參數 – 日子(非必要)
    • 日期數字 – 7 或 07
  • 第四個參數 – (非必要)
    • 可以是 BC、AD、BCE 或 CE
    • 當年份值為正時使用
  • 第一個參數 – 完整日期。國際格式、Template:What或 YYYY-MM-DD 格式
    • 國際格式的日期不會被改變。YYYY-MM-DD 式日期默認會轉換到US格式。
    • 可以接受月份縮寫
    • 大小寫和逗號錯誤將被改正
    • 模板使用Template:Tlxm,所以它也受解析器函數的限制(例如不支持公元100年以下)
例子
輸入風格 輸入碼 隱藏排序鍵 顯示的輸出

Template:Date table sorting/doc/row Template:Date table sorting/doc/row Template:Date table sorting/doc/row Template:Date table sorting/doc/row Template:Date table sorting/doc/row Template:Date table sorting/doc/row Template:Date table sorting/doc/row Template:Date table sorting/doc/row Template:Date table sorting/doc/row Template:Date table sorting/doc/row Template:Date table sorting/doc/row Template:Date table sorting/doc/row Template:Date table sorting/doc/row Template:Date table sorting/doc/row Template:Date table sorting/doc/row Template:Date table sorting/doc/row Template:Date table sorting/doc/row Template:Date table sorting/doc/row

格式化[編輯]

使用format可以做出一個依賴但不需要相同於提供日期的格式。這需要多次調用函數 Template:Tlxm,減少一個頁面中使用本模板的最多召喚次數到最差88次,參見下方。format 參數可以用九個數值。

例子
Template:Date table sorting/doc/rowTemplate:Date table sorting/doc/rowTemplate:Date table sorting/doc/rowTemplate:Date table sorting/doc/rowTemplate:Date table sorting/doc/rowTemplate:Date table sorting/doc/rowTemplate:Date table sorting/doc/row
輸出格式 輸入碼 隱藏排序鍵 顯示的輸出

Template:Date table sorting/doc/row Template:Date table sorting/doc/row Template:Date table sorting/doc/row

Template:Date table sorting/doc/row Template:Date table sorting/doc/row Template:Date table sorting/doc/row Template:Date table sorting/doc/row

Template:Date table sorting/doc/row Template:Date table sorting/doc/row

Template:Date table sorting/doc/row

Template:Date table sorting/doc/row

Template:Date table sorting/doc/row

Template:Date table sorting/doc/row

  1. 重定向 Template:Font color以下格式雖然有效,但不符合中文習慣,請勿使用

當處理單一的日期參數時,除非只有一個數字(那麼它將被解釋為年份),模板將根據php date/time format來解釋參數。但由於中文習慣的格式的影響,預設皆是使用年-月-日Template:What

縮寫[編輯]

在中文版本,只有一個方法縮寫日期:使用 abbr=on 參數。

例子
縮寫方法 輸入碼 隱藏排序鍵 顯示的輸出

Template:Date table sorting/doc/row Template:Date table sorting/doc/row Template:Date table sorting/doc/row Template:Date table sorting/doc/row Template:Date table sorting/doc/row Template:Date table sorting/doc/row Template:Date table sorting/doc/row Template:Date table sorting/doc/row Template:Date table sorting/doc/row Template:Date table sorting/doc/row

額外排序鍵[編輯]

如果表格內的兩個日期一樣,它們可以利用參數 addkey 排序。

例子
輸入碼 隱藏排序鍵 顯示的輸出

Template:Date table sorting/doc/row Template:Date table sorting/doc/row Template:Date table sorting/doc/row Template:Date table sorting/doc/row Template:Date table sorting/doc/row Template:Date table sorting/doc/row Template:Date table sorting/doc/row

文字換行[編輯]

要關閉自動換行的話,請使用nowrap=off參數。

高級用法[編輯]

除了內建格式,模板也支援使用以下變數自定義格式。

  1. 重定向 Template:Font color
格式代碼 說明
%X 模板預設格式使用的年格式(不含「年」字)
%x 模板啟用縮寫後使用的年格式
%Y 年分,數字位數補0補到4位數
%y 年分,未補0
%M 月分,數字位數補0補到2位數
%m 月分,未補0
%D 日期,數字位數補0補到2位數
%d 日期,未補0
%% 跳脫
輸入碼 隱藏排序鍵 顯示的輸出

Template:Date table sorting/doc/row Template:Date table sorting/doc/row

註解[編輯]

排序非完整日期[編輯]

完整年份或月份[編輯]

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

沒有年份[編輯]

如果未指定年份,系統將會視年份為現時年份來進行排序。

處理錯誤[編輯]

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

Template:Dts

曆法選擇[編輯]

本模板無法區分儒略曆和公曆日期。另外,它不能從一個曆法輸入日期並按另一曆法輸出日期。所以,要確保排序良好,用戶必須把日期統一於一個曆法,或者確定一個轉折日(例如,確定1582年10月4日為儒略曆,以後的所有日期為公曆),這可以用一條條的方法實現。如果可能造成混淆,用家有責任解釋給讀者究竟顯示的日期是儒略曆還是公曆。

連結[編輯]

本模板默認自動連結到日期。若要關閉連結,則可使用參數link=off。根據目前的指引,此模板不再支持日期的內部連結。請不要使用此參數,並請將此參數從目前的模板調用中移除。

參見[編輯]

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