<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.zombiepanicsource.com/index.php?action=history&amp;feed=atom&amp;title=Module%3ATime_Ago</id>
	<title>Module:Time Ago - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.zombiepanicsource.com/index.php?action=history&amp;feed=atom&amp;title=Module%3ATime_Ago"/>
	<link rel="alternate" type="text/html" href="https://wiki.zombiepanicsource.com/index.php?title=Module:Time_Ago&amp;action=history"/>
	<updated>2026-05-14T14:55:20Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.1</generator>
	<entry>
		<id>https://wiki.zombiepanicsource.com/index.php?title=Module:Time_Ago&amp;diff=246&amp;oldid=prev</id>
		<title>Wuffesan: Created page with &quot;local p = {} local lang = mw.language.getContentLanguage() local lib = require(&#039;Module:Feature&#039;) local search = lib.inArray local ne = lib.isNotEmpty local i18n = require(&#039;Module:I18n&#039;).loadMessages(&#039;Time Ago&#039;)  local units = { 	{ 		terms = {&#039;year&#039;,&#039;y&#039;}, 		higher = {&#039;&#039;}, 		insec = 31557600 	}, 	{ 		terms = {&#039;month&#039;,&#039;mth&#039;}, 		higher = {&#039;year&#039;,&#039;y&#039;}, 		insec = 2629800 	}, 	{ 		terms = {&#039;week&#039;,&#039;w&#039;}, 		higher = {&#039;year&#039;,&#039;y&#039;,&#039;month&#039;,&#039;mth&#039;}, 		insec = 604800 	}, 	{ 		terms = {&#039;d...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.zombiepanicsource.com/index.php?title=Module:Time_Ago&amp;diff=246&amp;oldid=prev"/>
		<updated>2025-06-10T21:39:04Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;local p = {} local lang = mw.language.getContentLanguage() local lib = require(&amp;#039;Module:Feature&amp;#039;) local search = lib.inArray local ne = lib.isNotEmpty local i18n = require(&amp;#039;Module:I18n&amp;#039;).loadMessages(&amp;#039;Time Ago&amp;#039;)  local units = { 	{ 		terms = {&amp;#039;year&amp;#039;,&amp;#039;y&amp;#039;}, 		higher = {&amp;#039;&amp;#039;}, 		insec = 31557600 	}, 	{ 		terms = {&amp;#039;month&amp;#039;,&amp;#039;mth&amp;#039;}, 		higher = {&amp;#039;year&amp;#039;,&amp;#039;y&amp;#039;}, 		insec = 2629800 	}, 	{ 		terms = {&amp;#039;week&amp;#039;,&amp;#039;w&amp;#039;}, 		higher = {&amp;#039;year&amp;#039;,&amp;#039;y&amp;#039;,&amp;#039;month&amp;#039;,&amp;#039;mth&amp;#039;}, 		insec = 604800 	}, 	{ 		terms = {&amp;#039;d...&amp;quot;&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 lang = mw.language.getContentLanguage()&lt;br /&gt;
local lib = require(&amp;#039;Module:Feature&amp;#039;)&lt;br /&gt;
local search = lib.inArray&lt;br /&gt;
local ne = lib.isNotEmpty&lt;br /&gt;
local i18n = require(&amp;#039;Module:I18n&amp;#039;).loadMessages(&amp;#039;Time Ago&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
local units = {&lt;br /&gt;
	{&lt;br /&gt;
		terms = {&amp;#039;year&amp;#039;,&amp;#039;y&amp;#039;},&lt;br /&gt;
		higher = {&amp;#039;&amp;#039;},&lt;br /&gt;
		insec = 31557600&lt;br /&gt;
	},&lt;br /&gt;
	{&lt;br /&gt;
		terms = {&amp;#039;month&amp;#039;,&amp;#039;mth&amp;#039;},&lt;br /&gt;
		higher = {&amp;#039;year&amp;#039;,&amp;#039;y&amp;#039;},&lt;br /&gt;
		insec = 2629800&lt;br /&gt;
	},&lt;br /&gt;
	{&lt;br /&gt;
		terms = {&amp;#039;week&amp;#039;,&amp;#039;w&amp;#039;},&lt;br /&gt;
		higher = {&amp;#039;year&amp;#039;,&amp;#039;y&amp;#039;,&amp;#039;month&amp;#039;,&amp;#039;mth&amp;#039;},&lt;br /&gt;
		insec = 604800&lt;br /&gt;
	},&lt;br /&gt;
	{&lt;br /&gt;
		terms = {&amp;#039;day&amp;#039;,&amp;#039;d&amp;#039;},&lt;br /&gt;
		higher = {&amp;#039;year&amp;#039;,&amp;#039;y&amp;#039;,&amp;#039;month&amp;#039;,&amp;#039;mth&amp;#039;,&amp;#039;week&amp;#039;,&amp;#039;w&amp;#039;},&lt;br /&gt;
		insec = 86400&lt;br /&gt;
	},&lt;br /&gt;
	{&lt;br /&gt;
		terms = {&amp;#039;hour&amp;#039;,&amp;#039;h&amp;#039;},&lt;br /&gt;
		higher = {&amp;#039;year&amp;#039;,&amp;#039;y&amp;#039;,&amp;#039;month&amp;#039;,&amp;#039;mth&amp;#039;,&amp;#039;week&amp;#039;,&amp;#039;w&amp;#039;,&amp;#039;day&amp;#039;,&amp;#039;d&amp;#039;},&lt;br /&gt;
		insec = 3600&lt;br /&gt;
	},&lt;br /&gt;
	{&lt;br /&gt;
		terms = {&amp;#039;minute&amp;#039;,&amp;#039;min&amp;#039;},&lt;br /&gt;
		higher = {&amp;#039;year&amp;#039;,&amp;#039;y&amp;#039;,&amp;#039;month&amp;#039;,&amp;#039;mth&amp;#039;,&amp;#039;week&amp;#039;,&amp;#039;w&amp;#039;,&amp;#039;day&amp;#039;,&amp;#039;d&amp;#039;,&amp;#039;hour&amp;#039;,&amp;#039;h&amp;#039;},&lt;br /&gt;
		insec = 60&lt;br /&gt;
	},&lt;br /&gt;
	{&lt;br /&gt;
		terms = {&amp;#039;second&amp;#039;,&amp;#039;s&amp;#039;},&lt;br /&gt;
		higher = {&amp;#039;year&amp;#039;,&amp;#039;y&amp;#039;,&amp;#039;month&amp;#039;,&amp;#039;mth&amp;#039;,&amp;#039;week&amp;#039;,&amp;#039;w&amp;#039;,&amp;#039;day&amp;#039;,&amp;#039;d&amp;#039;,&amp;#039;hour&amp;#039;,&amp;#039;h&amp;#039;,&amp;#039;minute&amp;#039;,&amp;#039;min&amp;#039;},&lt;br /&gt;
		insec = 1&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function p.main( frame )&lt;br /&gt;
	local args = require( &amp;#039;Module:Arguments&amp;#039; ).getArgs( frame, {&lt;br /&gt;
		valueFunc = function( k, v )&lt;br /&gt;
			if v then&lt;br /&gt;
				v = v:match( &amp;#039;^%s*(.-)%s*$&amp;#039; ) -- Trim whitespace.&lt;br /&gt;
				if k == &amp;#039;ago&amp;#039; or v ~= &amp;#039;&amp;#039; then&lt;br /&gt;
					return v&lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
			return nil&lt;br /&gt;
		end,&lt;br /&gt;
		wrappers = {&amp;#039;Template:Time Ago&amp;#039;}&lt;br /&gt;
	})&lt;br /&gt;
	-- Check that a timestamp was entered, return blank if it wasn&amp;#039;t.&lt;br /&gt;
	if not args[1] then return &amp;#039;&amp;#039; end&lt;br /&gt;
	&lt;br /&gt;
	-- Check that the entered timestamp is valid. If it isn&amp;#039;t, then give an error message.&lt;br /&gt;
	local success, inputTime = pcall(lang.formatDate, lang, &amp;#039;xnU&amp;#039;, args[1])&lt;br /&gt;
	assert(success, i18n:msg(&amp;#039;parse-error&amp;#039;))&lt;br /&gt;
	&lt;br /&gt;
	--Output formats&lt;br /&gt;
	if args.include then&lt;br /&gt;
		return p.include(args,inputTime)&lt;br /&gt;
	else&lt;br /&gt;
		return p.last(args,inputTime)&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.include(args,inputTime)&lt;br /&gt;
	local output = &amp;#039;&amp;#039;&lt;br /&gt;
	local include = lib.split(args.include,&amp;#039;,&amp;#039;)&lt;br /&gt;
	if (type(include) == &amp;#039;string&amp;#039;) then include = {include} end&lt;br /&gt;
	local hidelabel = tostring(args[&amp;#039;hidelabel&amp;#039;]) == &amp;#039;1&amp;#039;&lt;br /&gt;
	local hidefixes = tostring(args[&amp;#039;hidefixes&amp;#039;]) == &amp;#039;1&amp;#039;&lt;br /&gt;
	&lt;br /&gt;
	-- Store the difference between the current time and the inputted time, as well as its absolute value.&lt;br /&gt;
	local timeDiff = lang:formatDate(&amp;#039;xnU&amp;#039;) - inputTime&lt;br /&gt;
	local absTimeDiff = math.abs(timeDiff)&lt;br /&gt;
	&lt;br /&gt;
	local ValueTable = {&amp;#039;&amp;#039;,&amp;#039;&amp;#039;,&amp;#039;&amp;#039;,&amp;#039;&amp;#039;,&amp;#039;&amp;#039;,&amp;#039;&amp;#039;,&amp;#039;&amp;#039;}&lt;br /&gt;
	local trueVal = {}&lt;br /&gt;
	for k,v in ipairs(units) do&lt;br /&gt;
		local Value = 0&lt;br /&gt;
		local i,IsIn = false,false&lt;br /&gt;
		for K,V in ipairs(include) do&lt;br /&gt;
			if (absTimeDiff &amp;gt;= v.insec and (search(v.terms,V))) then i = true end&lt;br /&gt;
		end&lt;br /&gt;
		while i == true do&lt;br /&gt;
			Value=Value+1&lt;br /&gt;
			absTimeDiff = absTimeDiff - v.insec&lt;br /&gt;
			if absTimeDiff &amp;lt; v.insec then i = false end&lt;br /&gt;
		end&lt;br /&gt;
		if Value &amp;gt; 0 then&lt;br /&gt;
			if hidelabel then&lt;br /&gt;
				ValueTable[k] = tostring(Value)&lt;br /&gt;
			else&lt;br /&gt;
				ValueTable[k] = i18n:msg(v.terms[1], Value, (Value &amp;gt; 1 and 2 or 1))&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	for k,v in ipairs(ValueTable) do&lt;br /&gt;
		if ne(v) then&lt;br /&gt;
			trueVal[#trueVal+1] = v&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	if (#trueVal == 0) then&lt;br /&gt;
		local start,i = false,true&lt;br /&gt;
		for k,v in ipairs(units) do&lt;br /&gt;
			if start then&lt;br /&gt;
				if (absTimeDiff &amp;gt;= v.insec) then&lt;br /&gt;
					local Value = 0&lt;br /&gt;
					while i == true do&lt;br /&gt;
						Value=Value+1&lt;br /&gt;
						absTimeDiff = absTimeDiff - v.insec&lt;br /&gt;
						if absTimeDiff &amp;lt; v.insec then i = false end&lt;br /&gt;
					end&lt;br /&gt;
					if hidelabel then&lt;br /&gt;
						output = tostring(Value)&lt;br /&gt;
					else&lt;br /&gt;
						output = i18n:msg(v.terms[1], Value, (Value &amp;gt; 1 and 2 or 1))&lt;br /&gt;
					end&lt;br /&gt;
					if (timeDiff &amp;lt; 0 and (not hidefixes) and (not hidelabel) and ne(output)) then output = i18n:msg(&amp;#039;future&amp;#039; .. (ne(args.lowercase) and &amp;#039;-low&amp;#039; or &amp;#039;&amp;#039;), output) end&lt;br /&gt;
					if (timeDiff &amp;gt; 0 and (not hidefixes) and (not hidelabel) and ne(output)) then output = i18n:msg(&amp;#039;past&amp;#039;, output) end&lt;br /&gt;
					return output&lt;br /&gt;
				end&lt;br /&gt;
			elseif search(v.terms,include[#include]) then&lt;br /&gt;
				start = true&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	output = table.concat(trueVal,&amp;#039;, &amp;#039;)&lt;br /&gt;
	if (timeDiff &amp;lt; 0 and (not hidefixes) and (not hidelabel) and ne(output)) then output = i18n:msg(&amp;#039;future&amp;#039; .. (ne(args.lowercase) and &amp;#039;-low&amp;#039; or &amp;#039;&amp;#039;), output)  end&lt;br /&gt;
	if (timeDiff &amp;gt; 0 and (not hidefixes) and (not hidelabel) and ne(output)) then output = i18n:msg(&amp;#039;past&amp;#039;, output) end&lt;br /&gt;
	return output&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.last(args,inputTime)&lt;br /&gt;
	local output = &amp;#039;&amp;#039;&lt;br /&gt;
	local last = args.last or &amp;#039;sweet potato&amp;#039;&lt;br /&gt;
	local hidelabel = tostring(args[&amp;#039;hidelabel&amp;#039;]) == &amp;#039;1&amp;#039;&lt;br /&gt;
	local hidefixes = tostring(args[&amp;#039;hidefixes&amp;#039;]) == &amp;#039;1&amp;#039;&lt;br /&gt;
	&lt;br /&gt;
	-- Store the difference between the current time and the inputted time, as well as its absolute value.&lt;br /&gt;
	local timeDiff = lang:formatDate(&amp;#039;xnU&amp;#039;) - inputTime&lt;br /&gt;
	local absTimeDiff = math.abs(timeDiff)&lt;br /&gt;
	&lt;br /&gt;
	local ValueTable = {&amp;#039;&amp;#039;,&amp;#039;&amp;#039;,&amp;#039;&amp;#039;,&amp;#039;&amp;#039;,&amp;#039;&amp;#039;,&amp;#039;&amp;#039;,&amp;#039;&amp;#039;}&lt;br /&gt;
	local trueVal = {}&lt;br /&gt;
	for k,v in ipairs(units) do&lt;br /&gt;
		local Value = 0&lt;br /&gt;
		local i = false&lt;br /&gt;
		if (absTimeDiff &amp;gt;= v.insec and (not search(v.higher,last))) then i = true end&lt;br /&gt;
		for iter=1,k do&lt;br /&gt;
			if (lib.isEmpty(ValueTable[iter]) and absTimeDiff &amp;gt;= v.insec) then&lt;br /&gt;
				i = true&lt;br /&gt;
			else &lt;br /&gt;
				i = false&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		while i == true do&lt;br /&gt;
			Value=Value+1&lt;br /&gt;
			absTimeDiff = absTimeDiff - v.insec&lt;br /&gt;
			if absTimeDiff &amp;lt; v.insec then i = false end&lt;br /&gt;
		end&lt;br /&gt;
		if Value &amp;gt; 0 then&lt;br /&gt;
			if hidelabel then&lt;br /&gt;
				ValueTable[k] = tostring(Value)&lt;br /&gt;
			else&lt;br /&gt;
				ValueTable[k] = i18n:msg(v.terms[1], Value, (Value &amp;gt; 1 and 2 or 1))&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	for k,v in ipairs(ValueTable) do&lt;br /&gt;
		if (((not search(units[k].higher,last)) or search(units[k].terms,last)) and ne(v)) then&lt;br /&gt;
			trueVal[#trueVal+1] = v&lt;br /&gt;
		elseif ((#trueVal == 0) and ne(v)) then&lt;br /&gt;
			trueVal[1] = v&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	output = table.concat(trueVal,&amp;#039;, &amp;#039;)&lt;br /&gt;
	if (timeDiff &amp;lt; 0 and (not hidefixes) and (not hidelabel) and ne(output)) then output = i18n:msg(&amp;#039;future&amp;#039; .. (ne(args.lowercase) and &amp;#039;-low&amp;#039; or &amp;#039;&amp;#039;), output)  end&lt;br /&gt;
	if (timeDiff &amp;gt; 0 and (not hidefixes) and (not hidelabel) and ne(output)) then output = i18n:msg(&amp;#039;past&amp;#039;, output) end&lt;br /&gt;
	return output&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>Wuffesan</name></author>
	</entry>
</feed>