首頁
關於我們
隨機
新手使用指南
貢獻分數
建立新頁面
最近修改
特殊頁面
社群入口
設定
關於合眾百科 Unitedbook
免責聲明
搜尋
使用者選單
討論
貢獻
建立賬號
登入
正在編輯
模組:Hms
警告:
您尚未登入。 若您進行任何的編輯您的 IP 位址將會被公開。 若您
登入
或
建立帳號
,您的編輯將會以您的使用者名稱標示,並能擁有另外的益處。
防垃圾訊息檢查用。
請勿
填寫此欄位!
local p = {} function p._error( error_str ) return '[[Category:輸入值出現錯誤的持續時間]]<strong class="error">錯誤:' .. error_str .. '</strong>' end function p.main(frame) local args = require('Module:Arguments').getArgs(frame, {wrappers = {'Template:Duration', 'Template:Duration/sandbox'}}) local tmp = args.duration or args[1] or '' local duration = {} if tonumber(args[1]) or args[2] or args[3] then if args[4] then return p._error('不應指定參數4') end if not args[1] or args[1] == '' then duration = {args[2] or 0, args[3] or 0} else duration = {args[1], args[2] or 0, args[3] or 0} end tmp = nil for k, v in ipairs(duration) do duration[k] = tonumber(v) if not duration[k] then return p._error('無效的值') end end elseif args.h or args.m or args.s then if not args.h or args.h == '' then duration = {args.m or 0, args.s or 0} else duration = {args.h, args.m or 0, args.s or 0} end tmp = nil for k, v in ipairs(duration) do duration[k] = tonumber(v) if not duration[k] then return p._error('無效的值') end end else if mw.ustring.find(tmp, 'class="duration"', 1, yes) then return tmp end -- if there is already a microformat, don't do anything duration = mw.text.split(mw.ustring.match(tmp, '%d*:?%d+:%d+%.?%d*') or '', ':') -- split into table if duration[4] then return p._error('不能超過兩個冒號') end for k, v in ipairs(duration) do duration[k] = tonumber(v) or 0 end -- convert values to numbers end if duration[3] then if (duration[1] + duration[2] + duration[3]) == 0 then return nil end if (duration[1] ~= math.ceil(duration[1])) or (duration[2] ~= math.ceil(duration[2])) then return p._error('小時數和分鐘數必須是整數') end if duration[3] >= 60 then return p._error('秒數不能大於59') end if duration[2] >= 60 then return p._error('當小時數存在時,分鐘數不能大於59') end if duration[2] < 10 then duration[2] = '0'..duration[2] end -- zero padding if duration[3] < 10 then duration[3] = '0'..duration[3] end duration = '<span class="duration"><span class="h">' .. duration[1] .. '</span>:<span class="min">' .. duration[2] .. '</span>:<span class="s">' .. duration[3] .. '</span></span>' elseif duration[2] then if (duration[1] + duration[2]) == 0 then return nil end if duration[1] ~= math.ceil(duration[1]) then return p._error('小時數和分鐘數必須是整數') end if duration[2] >= 60 then return p._error('秒數不能大於59') end if duration[2] < 10 then duration[2] = '0'..duration[2] end -- zero padding duration = '<span class="duration"><span class="min">' .. duration[1] .. '</span>:<span class="s">' .. duration[2] .. '</span></span>' else duration = '' end if tmp and tmp ~= '' then if duration ~= '' then tmp = mw.ustring.gsub(tmp, '%d*:?%d+:%d+%.?%d*', duration, 1) else tmp = tmp .. ' [[Category:不含hAudio微格式的持續時間]]' end else if duration ~= '' then tmp = duration end end return tmp end return p
摘要:
請注意,所有於合眾百科 Unitedbook所做的貢獻會依據CC BY-NC-SA(創用CC 姓名標示─非商業性─相同方式分享)授權條款發佈(詳情請見
合眾百科:版權
)。若您不希望您的著作被任意修改與散佈,請勿在此發表文章。
您同時向我們保證在此的著作內容是您自行撰寫,或是取自不受版權保護的公開領域或自由資源。
請勿在未經授權的情況下發表文章!
取消
編輯說明
(在新視窗開啟)
此頁面使用了以下模板:
模組:Hms/doc
(
編輯
)