<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://stockhub.co/index.php?action=history&amp;feed=atom&amp;title=Module%3ASandbox%2Ftrappist_the_monk%2Fdiff_time</id>
	<title>Module:Sandbox/trappist the monk/diff time - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://stockhub.co/index.php?action=history&amp;feed=atom&amp;title=Module%3ASandbox%2Ftrappist_the_monk%2Fdiff_time"/>
	<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:Sandbox/trappist_the_monk/diff_time&amp;action=history"/>
	<updated>2026-04-22T00:27:29Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://stockhub.co/index.php?title=Module:Sandbox/trappist_the_monk/diff_time&amp;diff=146610&amp;oldid=prev</id>
		<title>imported&gt;Legoktm: Replace Module:No globals with require( &quot;strict&quot; )</title>
		<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:Sandbox/trappist_the_monk/diff_time&amp;diff=146610&amp;oldid=prev"/>
		<updated>2022-10-23T21:02:14Z</updated>

		<summary type="html">&lt;p&gt;Replace &lt;a href=&quot;/research/Module:No_globals&quot; title=&quot;Module:No globals&quot;&gt;Module:No globals&lt;/a&gt; with require( &amp;quot;strict&amp;quot; )&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;require(&amp;#039;strict&amp;#039;);&lt;br /&gt;
&lt;br /&gt;
local lang_object = mw.getContentLanguage();&lt;br /&gt;
&lt;br /&gt;
--[[--------------------------&amp;lt; D I F F _ D A Y S &amp;gt;------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
return difference between two date/time strings &amp;lt;t1&amp;gt;, and &amp;lt;t2&amp;gt;, in days to &amp;lt;precision&amp;gt; decimal places.  Converts&lt;br /&gt;
each date/time string to a unix timestamp (seconds), subtracts &amp;lt;t1&amp;gt; from &amp;lt;t2&amp;gt;, divides the difference by the number&lt;br /&gt;
of seconds in a day (86400) and returns a formatted string to &amp;lt;precision&amp;gt; decimal places.  The default precision&lt;br /&gt;
is 3 decimal places.  A positive result is returned when &amp;lt;t2&amp;gt; is the same as, or is &amp;#039;later&amp;#039; (more recent) than,&lt;br /&gt;
&amp;lt;t1&amp;gt;; negative results else.&lt;br /&gt;
&lt;br /&gt;
to call this from a template:&lt;br /&gt;
	{{#invoke:diff days|diff_days|&amp;lt;t1&amp;gt;|&amp;lt;t2&amp;gt;|precision=}}&lt;br /&gt;
where &amp;lt;t1&amp;gt; and &amp;lt;t2&amp;gt; are date/time strings acceptable to the MediaWiki #time parser&lt;br /&gt;
&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
local function diff_days (frame)&lt;br /&gt;
	local t1 = frame.args[1];													-- t1 is &amp;#039;start&amp;#039; time&lt;br /&gt;
	local t2 = frame.args[2];													-- t2 is &amp;#039;end&amp;#039; time&lt;br /&gt;
	local precision = tonumber (frame.args.precision) or 3;						-- number of decimal places to show; default is 3&lt;br /&gt;
	if 0 &amp;gt; precision then&lt;br /&gt;
		return &amp;#039;&amp;lt;span style=&amp;quot;color:#d33&amp;quot;&amp;gt;invalid precision: &amp;#039; .. precision .. &amp;#039;&amp;lt;/span&amp;gt;&amp;#039;;&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	local good;&lt;br /&gt;
	local time1, time2;															-- to hold Unix time stamps representing the dates&lt;br /&gt;
&lt;br /&gt;
	good, time1 = pcall (lang_object.formatDate, lang_object, &amp;#039;U&amp;#039;, t1 );		-- convert t1 value to unix timestamp &lt;br /&gt;
	if not good then&lt;br /&gt;
		return &amp;#039;&amp;lt;span style=&amp;quot;color:#d33&amp;quot;&amp;gt;invalid time: &amp;#039; .. t1 .. &amp;#039;&amp;lt;/span&amp;gt;&amp;#039;;&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	good, time2 = pcall (lang_object.formatDate, lang_object, &amp;#039;U&amp;#039;, t2 );		-- convert t2 value to unix timestamp &lt;br /&gt;
	if not good then&lt;br /&gt;
		return &amp;#039;&amp;lt;span style=&amp;quot;color:#d33&amp;quot;&amp;gt;invalid time: &amp;#039; .. t2 .. &amp;#039;&amp;lt;/span&amp;gt;&amp;#039;;&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	return string.format (&amp;#039;%.&amp;#039;.. precision .. &amp;#039;f&amp;#039;, (time2 - time1)/86400);&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[--------------------------&amp;lt; E X P O R T E D   F U N C T I O N &amp;gt;--------------------------------------------&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
return {&lt;br /&gt;
	diff_days = diff_days,&lt;br /&gt;
	diff_time = diff_days&lt;br /&gt;
	}&lt;/div&gt;</summary>
		<author><name>imported&gt;Legoktm</name></author>
	</entry>
</feed>