Module:ArtJapan
Lua
CodeDiscussionEditHistoryLinksLink count Subpages:DocumentationTestsResultsSandboxLive code All modules
Module:ArtJapan (talk · edit · hist · links · doc · subpages · tests / results · sandbox · all modules)
Code
local p = {}
--{{PAGENAME}}
local pagename = mw.title.getCurrentTitle().text
local pgnm_d = string.match(pagename, '%d+')
local BC = string.match(pagename, ' BC ') or
string.match(pagename, ' BC$')
--timespan
local pgnm_decade = string.match(pagename, '%d+0s')
local pgnm_century = string.match(pagename, 'century')
local pgnm_millennium = string.match(pagename, 'millennium')
--frominof
function p.error(msg)
return '<strong class=\"error\">'..msg..'</strong>'
end
function p.sort_years(frame)
-- param: 1,d,digit , 2,n,nod
local args_d = frame.args[1] or frame.args.d or frame.args.digit
local args_n = frame.args[2] or frame.args.n or frame.args.nod
-- var d=digit, nod=number of digit
local d = tonumber( pgnm_d or args_d )
local nod = tonumber( args_n ) or 4
-- if century/millennium = 2digits
if( pgnm_century or pgnm_millennium ) then nod = 2 end
local sortkey = ( type(d)~='number' )
and p.error('sort: no digits found..')
or
( d<0 or BC and 0<d ) -- 'BC' → '-'
and -10000 + math.abs(d) -- minus:e.g.100→(space/minus)-9900
or string.format('%0'..nod..'d', d)
return sortkey
end
return p