<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://mywikibiz.com/index.php?action=history&amp;feed=atom&amp;title=Module%3ANavseasoncats_with_year_navigation</id>
	<title>Module:Navseasoncats with year navigation - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://mywikibiz.com/index.php?action=history&amp;feed=atom&amp;title=Module%3ANavseasoncats_with_year_navigation"/>
	<link rel="alternate" type="text/html" href="https://mywikibiz.com/index.php?title=Module:Navseasoncats_with_year_navigation&amp;action=history"/>
	<updated>2026-06-19T21:24:33Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.3</generator>
	<entry>
		<id>https://mywikibiz.com/index.php?title=Module:Navseasoncats_with_year_navigation&amp;diff=478805&amp;oldid=prev</id>
		<title>Zoran: Pywikibot 6.4.0</title>
		<link rel="alternate" type="text/html" href="https://mywikibiz.com/index.php?title=Module:Navseasoncats_with_year_navigation&amp;diff=478805&amp;oldid=prev"/>
		<updated>2021-07-16T05:11:52Z</updated>

		<summary type="html">&lt;p&gt;Pywikibot 6.4.0&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;local p = {}&lt;br /&gt;
local nsc = require('Module:Navseasoncats')&lt;br /&gt;
&lt;br /&gt;
local errorList = {&lt;br /&gt;
	[&amp;quot;FIND_VAR&amp;quot;] = &amp;quot;Function find_var can't recognize the decade for category %s.&amp;quot;,&lt;br /&gt;
	[&amp;quot;NO_YEAR&amp;quot;] = &amp;quot;{{Navseasoncats with centuries below decade}} can't recognize the year for category %s.&amp;quot;,&lt;br /&gt;
	[&amp;quot;NO_DECADE&amp;quot;] = &amp;quot;{{Navseasoncats with centuries below decade}} can't recognize the decade for category %s.&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
local function create_category(firstPart, lastPart, dateValue, dateWord)&lt;br /&gt;
	local category = mw.text.trim(firstPart .. ' ' .. nsc.addord(dateValue) .. dateWord .. lastPart)&lt;br /&gt;
&lt;br /&gt;
	if (mw.title.new(category, 'Category').exists) then&lt;br /&gt;
		return category&lt;br /&gt;
	else&lt;br /&gt;
		return nil&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function getCentury(decade)&lt;br /&gt;
	decade = tonumber(decade)&lt;br /&gt;
	local century = math.floor(((decade - 1) / 100) + 1) --from {{CENTURY}}&lt;br /&gt;
	if (string.match(decade, '00$')) then&lt;br /&gt;
		century = century + 1&lt;br /&gt;
	end --'2000' is technically in the 20th, but the rest of the 2000s is in the 21st&lt;br /&gt;
	&lt;br /&gt;
	return century&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function getDecade(year)&lt;br /&gt;
	year = tonumber(year)&lt;br /&gt;
	local decade = year / 10&lt;br /&gt;
	decade = math.floor(decade)&lt;br /&gt;
	return decade .. &amp;quot;0s&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function getNestTierDateCategory(dateArgs, dateValue, firstPart, lastPart, decade)&lt;br /&gt;
	local nextTierDateCategory = &amp;quot;&amp;quot;&lt;br /&gt;
	if (dateArgs.dateType == &amp;quot;year&amp;quot;) then&lt;br /&gt;
		local decade = getDecade(dateValue)&lt;br /&gt;
		nextTierDateCategory = create_category(firstPart, lastPart, decade, &amp;quot; &amp;quot;)&lt;br /&gt;
		if (not nextTierDateCategory) then --check for &amp;quot;the YYYY&amp;quot;&lt;br /&gt;
			nextTierDateCategory = create_category(firstPart, lastPart, &amp;quot;the &amp;quot; .. decade, &amp;quot; &amp;quot;)&lt;br /&gt;
		end&lt;br /&gt;
	elseif (dateArgs.dateType == &amp;quot;decade&amp;quot;) then&lt;br /&gt;
		local century = getCentury(dateValue)&lt;br /&gt;
		nextTierDateCategory = create_category(firstPart, lastPart, century, &amp;quot; century &amp;quot;)&lt;br /&gt;
		if (not nextTierDateCategory) then --check for hyphenated century&lt;br /&gt;
			nextTierDateCategory = create_category(firstPart, lastPart, century, &amp;quot;-century &amp;quot;)&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	return nextTierDateCategory&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function isCategoryValid(dateValue, dateType, dateArgs)&lt;br /&gt;
	if ((dateValue) and (dateType == dateArgs.dateType)) then&lt;br /&gt;
		return true&lt;br /&gt;
	else&lt;br /&gt;
		return false&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function getError(pageName, avoidSelf, testcases, errorMessage)&lt;br /&gt;
	local errorOut = ''&lt;br /&gt;
	if (avoidSelf) then&lt;br /&gt;
		local errors = nsc.errorclass(string.format(errorMessage, pageName))&lt;br /&gt;
		errorOut = nsc.failedcat(errors, 'P')&lt;br /&gt;
		if (testcases) then&lt;br /&gt;
			string.gsub(errorOut, '(%[%[)(Category)', '%1:%2')&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return errorOut&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function getAvoidSelf(currentTitle, testcases)&lt;br /&gt;
	local avoidSelf = (currentTitle.text ~= 'Navseasoncats with year navigation' and&lt;br /&gt;
		currentTitle.text ~= 'Navseasoncats with year navigation/doc' and&lt;br /&gt;
		currentTitle.text ~= 'Navseasoncats with year navigation/sandbox' and&lt;br /&gt;
		(currentTitle.nsText ~= 'Template' or testcases)) --avoid nested transclusion errors&lt;br /&gt;
	return avoidSelf&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function main(frame, dateArgs)&lt;br /&gt;
	local currentTitle = mw.title.getCurrentTitle()&lt;br /&gt;
	local testcases = (currentTitle.subpageText == 'testcases')&lt;br /&gt;
	local avoidSelf = getAvoidSelf(currentTitle, testcases)&lt;br /&gt;
&lt;br /&gt;
	local getArgs = require('Module:Arguments').getArgs&lt;br /&gt;
	local args = getArgs(frame)&lt;br /&gt;
	&lt;br /&gt;
	local testcase = args[1]&lt;br /&gt;
&lt;br /&gt;
	if ((testcase == nil) and (avoidself == false)) then&lt;br /&gt;
		return ''&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	local pageName = testcase or currentTitle.baseText&lt;br /&gt;
	&lt;br /&gt;
	local findVar = nsc.find_var(pageName) --picks up decades/seasons/etc.&lt;br /&gt;
	if (findVar[1] == 'error') then&lt;br /&gt;
		return getError(pageName, avoidSelf, testcases, errorList[&amp;quot;FIND_VAR&amp;quot;])&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	local dateValue = tonumber(string.match(findVar[2], dateArgs.pattern))&lt;br /&gt;
	if (not isCategoryValid(dateValue, findVar[1], dateArgs)) then&lt;br /&gt;
		return getError(pageName, avoidSelf, testcases, dateArgs.errorMessage)&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	local nav1 = ''&lt;br /&gt;
	if (testcase) then&lt;br /&gt;
		nav1 = frame:expandTemplate{title = 'Navseasoncats', args = {testcase = testcase}} --not sure how else to pass frame &amp;amp; args together&lt;br /&gt;
	else&lt;br /&gt;
		nav1 = nsc.navseasoncats(frame)&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	local firstPart, lastPart = string.match(pageName, '^(.*)' .. findVar[2] .. '(.*)$')&lt;br /&gt;
	firstPart = mw.text.trim(firstPart or '')&lt;br /&gt;
	lastPart  = mw.text.trim(lastPart or '')&lt;br /&gt;
&lt;br /&gt;
	local nextTierDateCategory = getNestTierDateCategory(dateArgs, dateValue, firstPart, lastPart, decade)&lt;br /&gt;
&lt;br /&gt;
	if (nextTierDateCategory) then&lt;br /&gt;
		local nav2 = frame:expandTemplate{title = 'Navseasoncats', args = {[dateArgs.argName] = nextTierDateCategory}} --not sure how else to pass frame &amp;amp; args together&lt;br /&gt;
		return '&amp;lt;div style=&amp;quot;display:block !important; max-width: calc(100% - 25em);&amp;quot;&amp;gt;' ..&amp;quot;\n&amp;quot; .. nav1 .. nav2 ..&amp;quot;\n&amp;quot; .. '&amp;lt;/div&amp;gt;'&lt;br /&gt;
	else&lt;br /&gt;
		return nav1&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.centuriesBelowDecade(frame)&lt;br /&gt;
	local dateArgs = {dateType = &amp;quot;decade&amp;quot;, pattern = '^(%d+)s', argName = &amp;quot;century-below-decade&amp;quot;, errorMessage = errorList[&amp;quot;NO_DECADE&amp;quot;]}&lt;br /&gt;
	return main(frame, dateArgs)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.decadesBelowYear(frame)&lt;br /&gt;
	local dateArgs = {dateType = &amp;quot;year&amp;quot;, pattern = '^(%d+)', argName = &amp;quot;decade-below-year&amp;quot;, errorMessage = errorList[&amp;quot;NO_YEAR&amp;quot;]}&lt;br /&gt;
	return main(frame, dateArgs)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>Zoran</name></author>
	</entry>
</feed>