匿名使用者
無編輯摘要
imported>CYL992 (建立內容為「-- Implement various "age of" and other date-related templates. local _Date, _currentDate local function getExports(frame) -- Return objects exported from the date module or its sandbox. if not _Date then local sandbox = frame:getTitle():find('sandbox', 1, true) and '/sandbox' or '' local datemod = require('Module:Date' .. sandbox) _Date = datemod._Date _currentDate = datemod._current end return _Date, _currentDate end local Collection -- a ta…」的新頁面) |
imported>NoahLDW 無編輯摘要 |
||
第53行: | 第53行: | ||
-- Return formatted message text for an error or warning. | -- Return formatted message text for an error or warning. | ||
local categories = { | local categories = { | ||
error = '[[Category: | error = '[[Category:Age模組錯誤]]', | ||
warning = '[[Category: | warning = '[[Category:Age模組錯誤]]', -- same as error until determine whether 'Age warning' would be worthwhile | ||
} | } | ||
local a, b, category | local a, b, category | ||
第61行: | 第61行: | ||
b = '</i>]</sup>' | b = '</i>]</sup>' | ||
else | else | ||
a = '<strong class="error"> | a = '<strong class="error">錯誤:' | ||
b = '</strong>' | b = '</strong>' | ||
end | end | ||
第241行: | 第241行: | ||
date = date + item | date = date + item | ||
if not date then | if not date then | ||
return message(' | return message('無法添加“' .. item .. '”') | ||
end | end | ||
end | end | ||
第266行: | 第266行: | ||
local function rangeJoin(range) | local function rangeJoin(range) | ||
-- Return text to be used between a range of ages. | -- Return text to be used between a range of ages. | ||
return range == 'dash' and ' | return range == 'dash' and '–' or '或' | ||
end | end | ||
第329行: | 第329行: | ||
first = '' | first = '' | ||
last = text.n > 2 and (names.y == '年' and '又' or '零') or '' | last = text.n > 2 and (names.y == '年' and '又' or '零') or '' | ||
end | |||
if yes(options.range, true) and options.join ~= 'sep_space' and string.sub(last, 1, 1) ~= ',' then | |||
last = ',' .. last | |||
end | end | ||
for i, v in ipairs(text) do | for i, v in ipairs(text) do | ||
第362行: | 第365行: | ||
sep = '', | sep = '', | ||
y = '年', | y = '年', | ||
m = ' | m = '個月', | ||
w = ' | w = '週', | ||
d = '天', | d = '天', | ||
H = ' | H = '小時', | ||
M = '分', | M = '分', | ||
S = '秒', | S = '秒', | ||
第381行: | 第384行: | ||
plural = '', | plural = '', | ||
sep = '', | sep = '', | ||
y = ' | y = '歲', | ||
m = ' | m = '個月', | ||
w = ' | w = '週', | ||
d = '天', | d = '天', | ||
H = ' | H = '小時', | ||
M = '分', | M = '分', | ||
S = '秒', | S = '秒', | ||
第468行: | 第471行: | ||
(textOptions.suffix or '') | (textOptions.suffix or '') | ||
end | end | ||
return message(' | return message('此處不支援參數show=' .. show.id) | ||
end | end | ||
第572行: | 第575行: | ||
end | end | ||
if not dates[2] then | if not dates[2] then | ||
return message(' | return message('第二個日期應為年月日') | ||
end | end | ||
return dates[1], dates[2] | return dates[1], dates[2] | ||
第583行: | 第586行: | ||
local name = frame.args.template | local name = frame.args.template | ||
if not name then | if not name then | ||
return message(' | return message('有關模板需有“|template=x”參數,其中x是所需的操作') | ||
end | end | ||
local args = frame:getParent().args | local args = frame:getParent().args | ||
第674行: | 第677行: | ||
age_ymd = { -- {{age in years, months and days}} | age_ymd = { -- {{age in years, months and days}} | ||
show = 'ymd', | show = 'ymd', | ||
}, | }, | ||
age_ymwd = { -- {{age in years, months, weeks and days}} | age_ymwd = { -- {{age in years, months, weeks and days}} | ||
第683行: | 第685行: | ||
local spec = specs[name] | local spec = specs[name] | ||
if not spec then | if not spec then | ||
return message(' | return message('指定的模板名稱無效') | ||
end | end | ||
if name == 'age_days' then | if name == 'age_days' then | ||
第700行: | 第702行: | ||
-- "|range=" (empty value) has no effect (spec is used). | -- "|range=" (empty value) has no effect (spec is used). | ||
-- "|range=yes" or spec.range == true sets range = true (gives "11 or 12") | -- "|range=yes" or spec.range == true sets range = true (gives "11 or 12") | ||
-- "|range=dash" or spec.range == 'dash' sets range = 'dash' (gives " | -- "|range=dash" or spec.range == 'dash' sets range = 'dash' (gives "11–12"). | ||
-- "|range=no" or spec.range == 'no' sets range = nil and fills each date in the diff (gives "12"). | -- "|range=no" or spec.range == 'no' sets range = nil and fills each date in the diff (gives "12"). | ||
-- ("on" is equivalent to "yes", and "off" is equivalent to "no"). | -- ("on" is equivalent to "yes", and "off" is equivalent to "no"). | ||
第751行: | 第753行: | ||
} | } | ||
if (spec.negative or frame.args.negative) == 'error' and parms.diff.isnegative then | if (spec.negative or frame.args.negative) == 'error' and parms.diff.isnegative then | ||
return message(' | return message('第二個日期不應在第一個日期之前') | ||
end | end | ||
return dateDifference(parms) | return dateDifference(parms) | ||
第767行: | 第769行: | ||
local diff = Date('currentdate') - date | local diff = Date('currentdate') - date | ||
if diff.isnegative or diff.years > 150 then | if diff.isnegative or diff.years > 150 then | ||
return message(' | return message('計算年齡所需的出生日期無效') | ||
end | end | ||
local disp, show = 'disp_raw', 'y' | local disp, show = 'disp_raw', 'y' | ||
第820行: | 第822行: | ||
end | end | ||
if invalid then | if invalid then | ||
result = result .. message(invalid .. ' | result = result .. message(invalid .. '參數無效', 'warning') | ||
end | end | ||
end | end | ||
第848行: | 第850行: | ||
return date:text() | return date:text() | ||
end | end | ||
return message(' | return message('需要有效的儒略曆日期') | ||
end | end | ||
第861行: | 第863行: | ||
return tostring(date.jd) | return tostring(date.jd) | ||
end | end | ||
return message('需要有效的年/月/ | return message('需要有效的年/月/日或“currentdate”(當前日期)') | ||
end | end | ||
第879行: | 第881行: | ||
local date1 = Date(fix, 'partial', stripToNil(args[1]) or 'currentdatetime') | local date1 = Date(fix, 'partial', stripToNil(args[1]) or 'currentdatetime') | ||
if not date1 then | if not date1 then | ||
return message(' | return message('開始日期無效') | ||
end | end | ||
local date2 = Date(fix, 'partial', stripToNil(args[2]) or 'currentdatetime') | local date2 = Date(fix, 'partial', stripToNil(args[2]) or 'currentdatetime') | ||
if not date2 then | if not date2 then | ||
return message(' | return message('結束日期無效') | ||
end | end | ||
parms.diff = date2 - date1 | parms.diff = date2 - date1 | ||
第891行: | 第893行: | ||
parm = translate[parm] | parm = translate[parm] | ||
if parm == nil then -- test for nil because false is a valid setting | if parm == nil then -- test for nil because false is a valid setting | ||
return message(' | return message('參數' .. argname .. '=' .. args[argname] .. '無效') | ||
end | end | ||
parms[argname] = parm | parms[argname] = parm | ||
第902行: | 第904行: | ||
if show then | if show then | ||
if show.id ~= round then | if show.id ~= round then | ||
return message(' | return message('參數show=' .. args.show .. '與round=' .. args.round .. '互有衝突') | ||
end | end | ||
else | else |