maxdec = maxdefault
end  
local tspace = ' ' --assume trailing space for "1950s in X"-type cats
if string.match(lastpart, '^-') then tspace = '' end --DNE for "1970s-related"-type cats  
--AD/BC switches & vars  
local parentBC = string.match(lastpart, '^கிமு') --following the "0s BC" convention for all years BC
lastpart = mw.ustring.gsub(lastpart, '^கிமு%s*', '') --handle BC separately; AD never used
--TODO?: handle BCE, but only if it exists in the wild  
local dec0to40AD = (ndec >= 0 and ndec <= 40 and not parentBC) --special behavior in this range
local switchADBC = 1 -- 1=AD parent
if parentBC then switchADBC = -1 end -- -1=BC parent; possibly adjusted later
local BCdisp = ''
local D = -math.huge --secondary switch & iterator for AD/BC transition  
--check non-default min/max more carefully
if mindec ~= mindefault then
if tonumber(mindec) > ndec*switchADBC then
mindec = tostring(ndec*switchADBC) --input error; mindec should be <= parent
end
end
if maxdec ~= maxdefault then
if tonumber(maxdec) < ndec*switchADBC then
maxdec = tostring(ndec*switchADBC) --input error; maxdec should be >= parent
end
end
local nmindec = tonumber(mindec) --similar behavior to nav_year & nav_nordinal
local nmaxdec = tonumber(maxdec) --similar behavior to nav_nordinal  
--begin navdecade
local bnb = '' --/no
if navborder == false then --for Navseasoncats year and decade
bnb = ' -style: ; background-color: transparent;'
end
local navd = '{|\n'..'|\n'  
local i = -50 --nav position x 10
while i <= 50 do
local d = ndec + i*switchADBC  
local BC = ''
BCdisp = ''
if dec0to40AD then
if D < -10 then
d = math.abs(d + 10) --b/c 2 "0கள்" decades exist: "கிமு 0கள்" & "0கள்" (கிபி)
BC = 'கிமு '
if d == 0 then
D = -10 --track 1st d = 0 use (கிமு)
end
elseif D >= -10 then
D = D + 10 --now iterate from கிபி 0கள்
d = D --2nd d = 0 use
end
elseif parentBC then
if switchADBC == -1 then --parentBC looking at the BC side (the common case)
BC = 'கிமு '
if d == 0 then --prepare to switch to the AD side on the next iteration
switchADBC = 1 --1st d = 0 use (BC)
D = -10 --prep
end
elseif switchADBC == 1 then --switched to the AD side
D = D + 10 --now iterate from 0s AD
d = D --2nd d = 0 use (on first use)
end
end
if BC ~= '' and ndec <= 50 then
BCdisp = 'கிமு ' --show BC for all BC decades whenever a "0s" is displayed on the nav
end  
--determine target cat
local disp = BCdisp..d..'கள்'
local catlink = catlinkfollowr( , firstpart..' '..d..'களில்'..tspace..BC..lastpart, disp )
if catlink.rtarget then --a was followed
trackcat(18, 'Navseasoncats decade redirected')
end  
--populate / navd
local shown = navcenter(i, catlink)
local hidden = '<span>'..disp..'</span>'
local dsign = d --use d for display & dsign for logic
if BC ~= '' then dsign = -dsign end
if (nmindec <= dsign) and (dsign <= nmaxdec) then
if dsign == 0 and (nmindec == 0 or nmaxdec == 0) then --distinguish b/w -0 (BC) & 0 (AD)
--"zoom in" on +/- 0 and turn dsign/min/max temporarily into +/- 1 for easier processing
local zsign, zmin, zmax = 1, nmindec, nmaxdec
if BC ~= '' then zsign = -1 end
if mindec == '-0' then zmin = -1
elseif mindec == '0' then zmin = 1 end
if maxdec == '-0' then zmax = -1
elseif maxdec == '0' then zmax = 1 end  
if (zmin <= zsign) and (zsign <= zmax) then
navd = navd..shown
hidden = nil
else
navd = navd..'*'..hidden..'\n'
end
else
navd = navd..shown --the common case
hidden = nil
end
else
navd = navd..'*'..hidden..'\n'
end
if listall and hidden then
tlistall[#tlistall] = tlistall[#tlistall]..' ('..hidden..')'
end  
i = i + 10
end  
isolatedcat
if listall then
return listalllinks
else
return navd..'|}'
end
end  
--==========================================================  
local function nav_year( , firstpart, year, lastpart, minimumyear, maximumyear )
--Expects a PAGENAME of the form "Some sequential 1760 example cat", where
-- firstpart = Some sequential
-- year = 1760
-- lastpart = example cat
-- minimumyear = 1758 ('min' year parameter; optional)
-- maximumyear = 1800 ('max' year parameter; optional)
local minyear_default = -9999
local maxyear_default = 9999
year = tonumber(year) or tonumber(mw.ustring.match(year or '', '^%s*(%d*)'))
local minyear = tonumber(string.match(minimumyear or '', '-?%d+')) or minyear_default --allow +/- qualifier
local maxyear = tonumber(string.match(maximumyear or '', '-?%d+')) or maxyear_default --allow +/- qualifier
if string.match(minimumyear or '', 'கிமு') then minyear = -math.abs(minyear) end --allow BC qualifier (AD otherwise assumed)
if string.match(maximumyear or '', 'கிமு') then maxyear = -math.abs(maxyear) end --allow BC qualifier (AD otherwise assumed)  
if year == nil then
errors = p.errorclass('Function nav_year can\'t recognize the year sent to its 2nd parameter.')
return p.failedcat(errors, 'Y')
end  
--AD/BC switches & vars  
local yearBCElastparts = { --needed for parent = AD 1-5, when the BC/E format is unknown
--"BCE" removed to match both AD & BCE cats; easier & faster than multiple string.matchs
['example_Hebrew people_example'] = 'BCE', --example entry format; add to & adjust as needed
}
local parentAD = string.match(firstpart, 'AD$') --following the "AD 1" convention from AD 1 to AD 10
local parentBC = string.match(lastpart, '^BCE?') --following the "1 BC" convention for all years BC
firstpart = mw.ustring.gsub(firstpart, '%s*AD$', '') --handle AD/BC separately for easier & faster accounting
lastpart = mw.ustring.gsub(lastpart, '^BCE?%s*', '')
local BCe = parentBC or yearBCElastparts[lastpart] or 'கிமு' --"BC" default  
local year1to10 = (year >= 1 and year <= 10)
local year1to10ADBC = year1to10 and (parentBC or parentAD) --special behavior 1-10 for low-# non-year series
local year1to15AD = (year >= 1 and year <= 15 and not parentBC) --special behavior 1-15 for AD/BC display
local switchADBC = 1 -- 1=AD parent
if parentBC then switchADBC = -1 end -- -1=BC parent; possibly adjusted later
local Y = 0 --secondary iterator for AD-on-a-BC-parent  
if minyear > year*switchADBC then minyear = year*switchADBC end --input error; minyear should be <= parent
if maxyear < year*switchADBC then maxyear = year*switchADBC end --input error; maxyear should be >= parent  
local lspace = ' ' --leading space before year, after firstpart
if string.match(firstpart, '[%-VW]$') then
lspace = '' --e.g. "Straight-8 engines"
end  
local tspace = ' ' --trailing space after year, before lastpart
if string.match(lastpart, '^-') then
tspace = '' --e.g. "2018-related timelines"
end  
--determine interyear gap size to condense special category types, if possible
local ygapdefault = 1 --assume/start at the most common case: 2001, 2002, etc.
local ygap = ygapdefault
if string.match(lastpart, 'presidential') then
local ygap1, ygap2 = ygapdefault, ygapdefault --need to determine previous & next year gaps indepedently
local ygap1_success, ygap2_success = false, false  
local prevseason = nil
while ygap1 <= 5 do --Czech Republic, Poland, Sri Lanka, etc. have 5-year terms
prevseason = firstpart..lspace..(year-ygap1)..tspace..lastpart
if catexists(prevseason) then
ygap1_success = true
break
end
ygap1 = ygap1 + 1
end  
local nextseason = nil
while ygap2 <= 5 do --Czech Republic, Poland, Sri Lanka, etc. have 5-year terms
nextseason = firstpart..lspace..(year+ygap2)..tspace..lastpart
if catexists(nextseason) then
ygap2_success = true
break
end
ygap2 = ygap2 + 1
end  
if ygap1_success and ygap2_success then
if ygap1 == ygap2 then ygap = ygap1 end
elseif ygap1_success then ygap = ygap1
elseif ygap2_success then ygap = ygap2
end
end  
--skip non-existing years, if requested
local ynogaps = {} --populate with existing years in the range, at most, [year - (skipgaps_limit * 5), year + (skipgaps_limit * 5)]
local skipgaps_limit = 25
if skipgaps then
if minyear == minyear_default then
minyear = 0 --automatically set minyear to 0, as AD/BC not supported anyway
end
if (year > 70) or --add support for AD/BC (<= AD 10) if/when needed
(minyear >= 0 and --must be a non-year series like "AC with 0 elements"