<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://mindpowe.red/wiki/index.php?action=history&amp;feed=atom&amp;title=Module%3ATime</id>
	<title>Module:Time - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://mindpowe.red/wiki/index.php?action=history&amp;feed=atom&amp;title=Module%3ATime"/>
	<link rel="alternate" type="text/html" href="https://mindpowe.red/wiki/index.php?title=Module:Time&amp;action=history"/>
	<updated>2026-04-06T12:58:51Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.34.2</generator>
	<entry>
		<id>https://mindpowe.red/wiki/index.php?title=Module:Time&amp;diff=6712&amp;oldid=prev</id>
		<title>imported&gt;Pppery: Sync from sandbox per edit request: support |dst=always; use Module:Yesno to handle more truthy values</title>
		<link rel="alternate" type="text/html" href="https://mindpowe.red/wiki/index.php?title=Module:Time&amp;diff=6712&amp;oldid=prev"/>
		<updated>2020-05-25T02:32:35Z</updated>

		<summary type="html">&lt;p&gt;Sync from sandbox per edit request: support |dst=always; use &lt;a href=&quot;/wiki/index.php/Module:Yesno&quot; title=&quot;Module:Yesno&quot;&gt;Module:Yesno&lt;/a&gt; to handle more truthy values&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;require ('Module:No globals')&lt;br /&gt;
local yesno = require('Module:Yesno')&lt;br /&gt;
local getArgs = require ('Module:Arguments').getArgs&lt;br /&gt;
&lt;br /&gt;
local tz = {};																	-- holds local copy of the specified timezone table from tz_data{}&lt;br /&gt;
local cfg = {};																	-- for internationalization &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[--------------------------&amp;lt; I S _ S E T &amp;gt;------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
Whether variable is set or not.  A variable is set when it is not nil and not empty.&lt;br /&gt;
&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
local function is_set( var )&lt;br /&gt;
	return not (nil == var or '' == var);&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[--------------------------&amp;lt; S U B S T I T U T E &amp;gt;----------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
Populates numbered arguments in a message string using an argument table.&lt;br /&gt;
&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
local function substitute (msg, args)&lt;br /&gt;
	return args and mw.message.newRawMessage (msg, args):plain() or msg;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[--------------------------&amp;lt; E R R O R _ M S G &amp;gt;------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
create an error message&lt;br /&gt;
&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
local function error_msg (msg, arg)&lt;br /&gt;
	return substitute (cfg.err_msg, substitute (cfg.err_text[msg], arg))&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[--------------------------&amp;lt; D E C O D E _ D S T _ E V E N T &amp;gt;----------------------------------------------&lt;br /&gt;
&lt;br /&gt;
extract ordinal, day-name, and month from daylight saving start/end definition string as digits:&lt;br /&gt;
	Second Sunday in March&lt;br /&gt;
returns&lt;br /&gt;
	2 0 3&lt;br /&gt;
&lt;br /&gt;
Casing doesn't matter but the form of the string does:&lt;br /&gt;
	&amp;lt;ordinal&amp;gt; &amp;lt;day&amp;gt; &amp;lt;any single word&amp;gt; &amp;lt;month&amp;gt; – all are separated by spaces&lt;br /&gt;
&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
local function decode_dst_event (dst_event_string)&lt;br /&gt;
	local ord, day, month;&lt;br /&gt;
	&lt;br /&gt;
	dst_event_string = dst_event_string:lower();								-- force the string to lower case because that is how the tables above are indexed&lt;br /&gt;
	ord, day, month = dst_event_string:match ('([%a%d]+)%s+(%a+)%s+%a+%s+(%a+)');&lt;br /&gt;
	&lt;br /&gt;
	if not (is_set (ord) and is_set (day) and is_set (month)) then				-- if one or more of these not set, then pattern didn't match&lt;br /&gt;
		return nil;&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	return cfg.ordinals[ord], cfg.days[day], cfg.months[month];&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[--------------------------&amp;lt; G E T _ D A Y S _ I N _ M O N T H &amp;gt;--------------------------------------------&lt;br /&gt;
&lt;br /&gt;
Returns the number of days in the month where month is a number 1–12 and year is four-digit Gregorian calendar.&lt;br /&gt;
Accounts for leap year.&lt;br /&gt;
&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
local function get_days_in_month (year, month)&lt;br /&gt;
	local days_in_month = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};&lt;br /&gt;
	&lt;br /&gt;
	year = tonumber (year);														-- force these to be numbers just in case&lt;br /&gt;
	month = tonumber (month);&lt;br /&gt;
&lt;br /&gt;
	if (2 == month) then														-- if February&lt;br /&gt;
		if (0 == (year%4) and (0 ~= (year%100) or 0 == (year%400))) then		-- is year a leap year?&lt;br /&gt;
			return 29;															-- if leap year then 29 days in February&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return days_in_month [month];&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[--------------------------&amp;lt; G E T _ D S T _ M O N T H _ D A Y &amp;gt;--------------------------------------------&lt;br /&gt;
&lt;br /&gt;
Return the date (month and day of the month) for the day that is the ordinal (nth) day-name in month (second&lt;br /&gt;
Friday in June) of the current year&lt;br /&gt;
&lt;br /&gt;
timestamp is today's date-time number from os.time(); used to supply year&lt;br /&gt;
timezone is the timezone parameter value from the template call&lt;br /&gt;
&lt;br /&gt;
Equations used in this function taken from Template:Weekday_in_month&lt;br /&gt;
&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
local function get_dst_month_day (timestamp, start)&lt;br /&gt;
	local ord, weekday_num, month;&lt;br /&gt;
	local first_day_of_dst_month_num;&lt;br /&gt;
	local last_day_of_dst_month_num;&lt;br /&gt;
	local days_in_month;&lt;br /&gt;
	local year;&lt;br /&gt;
&lt;br /&gt;
	if true == start then&lt;br /&gt;
		ord, weekday_num, month = decode_dst_event (tz.dst_begins);				-- get start string and convert to digits&lt;br /&gt;
	else&lt;br /&gt;
		ord, weekday_num, month = decode_dst_event (tz.dst_ends);				-- get end string and convert to digits&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	if not (is_set (ord) and is_set (weekday_num) and is_set (month)) then&lt;br /&gt;
		return nil;																-- could not decode event string&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	year = os.date ('%Y', timestamp);&lt;br /&gt;
&lt;br /&gt;
	if -1 == ord then		-- j = t + 7×(n + 1) - (wt - w) mod 7				-- if event occurs on the last day-name of the month ('last Sunday of October')&lt;br /&gt;
		days_in_month = get_days_in_month (year, month);&lt;br /&gt;
		last_day_of_dst_month_num = os.date ('%w', os.time ({['year']=year, ['month']=month, ['day']=days_in_month}));&lt;br /&gt;
		return month, days_in_month + 7*(ord + 1) - ((last_day_of_dst_month_num - weekday_num) % 7);&lt;br /&gt;
	else	-- j = 7×n - 6 + (w - w1) mod 7&lt;br /&gt;
		first_day_of_dst_month_num = os.date ('%w', os.time ({['year']=year, ['month']=month, ['day']=1}))&lt;br /&gt;
		return month, 7 * ord - 6 + (weekday_num - first_day_of_dst_month_num) % 7;		-- return month and calculated date&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[--------------------------&amp;lt; G E T _ U T C _ O F F S E T &amp;gt;--------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
Get utc offset in hours and minutes, convert to seconds.  If the offset can't be converted return nil.&lt;br /&gt;
TODO: return error message?&lt;br /&gt;
TODO: limit check this? +/-n hours?&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
local function get_utc_offset ()&lt;br /&gt;
	local sign;&lt;br /&gt;
	local hours;&lt;br /&gt;
	local minutes;&lt;br /&gt;
	&lt;br /&gt;
	sign, hours, minutes = mw.ustring.match (tz.utc_offset, '([%+%-±−]?)(%d%d):(%d%d)');&lt;br /&gt;
&lt;br /&gt;
	if '-' == sign then sign = -1; else sign = 1; end&lt;br /&gt;
	if is_set (hours) and is_set (minutes) then&lt;br /&gt;
		return sign * ((hours * 3600) + (minutes * 60));&lt;br /&gt;
	else&lt;br /&gt;
		return nil;																-- we require that all timezone tables have what appears to be a valid offset&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[--------------------------&amp;lt; M A K E _ D S T _ T I M E S T A M P S &amp;gt;----------------------------------------&lt;br /&gt;
&lt;br /&gt;
Return UTC timestamps for the date/time of daylight saving time events (beginning and ending).  These timestamps&lt;br /&gt;
will be compared to current UTC time.  A dst timestamp is the date/time in seconds UTC for the timezone at the&lt;br /&gt;
hour of the dst event.&lt;br /&gt;
&lt;br /&gt;
For dst rules that specify local event times, the timestamp is the sum of:&lt;br /&gt;
	timestamp = current year + dst_month + dst_day + dst_time (all in seconds) local time&lt;br /&gt;
Adjust local time to UTC by subtracting utc_offset:&lt;br /&gt;
	timestamp = timestamp - utc_offset (in seconds)&lt;br /&gt;
For dst_end timestamp, subtract an hour for DST&lt;br /&gt;
	timestamp = timestamp - 3600 (in seconds)&lt;br /&gt;
&lt;br /&gt;
For dst rules that specify utc event time the process is the same except that utc offset is not subtracted.&lt;br /&gt;
&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
local function make_dst_timestamps (timestamp)&lt;br /&gt;
	local dst_begin, dst_end;													-- dst begin and end time stamps &lt;br /&gt;
	local year;																	-- current year&lt;br /&gt;
	local dst_b_month, dst_e_month, dst_day;									-- month and date of dst event&lt;br /&gt;
	local dst_hour, dst_minute;													-- hour and minute of dst event on year-dst_month-dst_day&lt;br /&gt;
	local invert = false;														-- flag to pass on when dst_begin month is numerically larger than dst_end month (southern hemisphere)&lt;br /&gt;
	local utc_offset;&lt;br /&gt;
	local utc_flag;&lt;br /&gt;
&lt;br /&gt;
	year = os.date ('%Y', timestamp);											-- current year&lt;br /&gt;
	utc_offset = get_utc_offset ();												-- in seconds&lt;br /&gt;
	if not is_set (utc_offset) then												-- utc offset is a required timezone property&lt;br /&gt;
		return nil;&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	dst_b_month, dst_day = get_dst_month_day (timestamp, true);					-- month and day that dst begins&lt;br /&gt;
	if not is_set (dst_b_month) then&lt;br /&gt;
		return nil;&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	dst_hour, dst_minute = tz.dst_time:match ('(%d%d):(%d%d)');					-- get dst time&lt;br /&gt;
	utc_flag = tz.dst_time:find ('[Uu][Tt][Cc]%s*$');							-- set flag when dst events occur at a specified utc time&lt;br /&gt;
&lt;br /&gt;
	dst_begin = os.time ({['year'] = year, ['month'] = dst_b_month, ['day'] = dst_day, ['hour'] = dst_hour, ['min'] = dst_minute});	-- form start timestamp&lt;br /&gt;
	if not is_set (utc_flag) then												-- if dst events are specified to occur at local time&lt;br /&gt;
		dst_begin = dst_begin - utc_offset;										-- adjust local time to utc by subtracting utc offset&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	dst_e_month, dst_day = get_dst_month_day (timestamp, false);				-- month and day that dst ends&lt;br /&gt;
	if not is_set (dst_e_month) then&lt;br /&gt;
		return nil;&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	if is_set (tz.dst_e_time) then&lt;br /&gt;
		dst_hour, dst_minute = tz.dst_e_time:match ('(%d%d):(%d%d)');			-- get ending dst time; this one for those locales that use different start and end times&lt;br /&gt;
		utc_flag = tz.dst_e_time:find ('[Uu][Tt][Cc]%s*$');						-- set flag if dst is pegged to utc time&lt;br /&gt;
	end	&lt;br /&gt;
&lt;br /&gt;
	dst_end = os.time ({['year'] = year, ['month'] = dst_e_month, ['day'] = dst_day, ['hour'] = dst_hour, ['min'] = dst_minute});	-- form end timestamp&lt;br /&gt;
	if not is_set (utc_flag) then												-- if dst events are specified to occur at local time&lt;br /&gt;
		dst_end = dst_end - 3600;												-- assume that local end time is DST so adjust to local ST&lt;br /&gt;
		dst_end = dst_end - utc_offset;											-- adjust local time to utc by subtracting utc offset&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	if dst_b_month &amp;gt; dst_e_month then&lt;br /&gt;
		invert = true;															-- true for southern hemisphere eg: start September YYYY end April YYYY+1&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	return dst_begin, dst_end, invert;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[--------------------------&amp;lt; G E T _ T E S T _ T I M E &amp;gt;----------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
decode ISO formatted date/time into a table suitable for os.time().  Fallback to {{Timestamp}} format.&lt;br /&gt;
For testing, this time is UTC just as is returned by the os.time() function.&lt;br /&gt;
&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
local function get_test_time (iso_date)&lt;br /&gt;
	local year, month, day, hour, minute, second;&lt;br /&gt;
&lt;br /&gt;
	year, month, day, hour, minute, second = iso_date:match ('(%d%d%d%d)%-(%d%d)%-(%d%d)T(%d%d):(%d%d):(%d%d)');&lt;br /&gt;
	if not year then&lt;br /&gt;
		year, month, day, hour, minute, second = iso_date:match ('^(%d%d%d%d)(%d%d)(%d%d)(%d%d)(%d%d)(%d%d)$');&lt;br /&gt;
		if not year then&lt;br /&gt;
			return nil;															-- test time did not match the specified patterns&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return {['year'] = year, ['month'] = month, ['day'] = day, ['hour'] = hour, ['min'] = minute, ['sec'] = second};&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[----------------------&amp;lt; G E T _ F U L L _ U T C _ O F F S E T &amp;gt;-----------------------------------------------&lt;br /&gt;
&lt;br /&gt;
Creates a standard UTC offset from numerical inputs, for function time to convert to a table.  Expected inputs shall have the form:&lt;br /&gt;
	&amp;lt;sign&amp;gt;&amp;lt;hour&amp;gt;&amp;lt;separator&amp;gt;&amp;lt;portion&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
	&amp;lt;sign&amp;gt; – optional; one of the characters: '+', '-' (hyphen), '±', '−' (minus); defaults to '+'&lt;br /&gt;
	&amp;lt;hour&amp;gt; - one or two digits&lt;br /&gt;
	&amp;lt;separator&amp;gt; - one of the characters '.' or ':'; required when &amp;lt;portion&amp;gt; is included; ignored else&lt;br /&gt;
	&amp;lt;portion&amp;gt; - optional; one or two digits when &amp;lt;separator&amp;gt; is '.'; two digits else&lt;br /&gt;
&lt;br /&gt;
returns correct utc offset string when input has a correct form; else returns the unmodified input&lt;br /&gt;
&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
local function get_full_utc_offset (utc_offset)&lt;br /&gt;
	local h, m, sep, sign;&lt;br /&gt;
	&lt;br /&gt;
	local patterns = {&lt;br /&gt;
		'^([%+%-±−]?)(%d%d?)(%.)(%d%d?)$',										-- one or two fractional hour digits&lt;br /&gt;
		'^([%+%-±−]?)(%d%d?)(:)(%d%d)$',										-- two minute digits&lt;br /&gt;
		'^([%+%-±−]?)(%d%d?)[%.:]?$',											-- hours only; ignore trailing separator&lt;br /&gt;
		}&lt;br /&gt;
	&lt;br /&gt;
	for _, pattern in ipairs(patterns) do										-- loop through the patterns&lt;br /&gt;
		sign, h, sep, m = mw.ustring.match (utc_offset, pattern);&lt;br /&gt;
		if h then&lt;br /&gt;
			break;																-- if h is set then pattern matched&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	if not h then&lt;br /&gt;
		return utc_offset;														-- did not match a pattern&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	sign = ('' == sign) and '+' or sign;										-- sign character is required; set to '+' if not specified&lt;br /&gt;
&lt;br /&gt;
	m = ('.' == sep) and ((sep .. m) * 60) or m or 0;							-- fractional h to m&lt;br /&gt;
&lt;br /&gt;
	return string.format ('utc%s%02d:%02d', sign, h, m);&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[--------------------------&amp;lt; T A B L E _ L E N &amp;gt;------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
return number of elements in table&lt;br /&gt;
&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
local function table_len (tbl)&lt;br /&gt;
	local count = 0;&lt;br /&gt;
	for _ in pairs (tbl) do&lt;br /&gt;
		count = count + 1;&lt;br /&gt;
	end&lt;br /&gt;
	return count;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[--------------------------&amp;lt; F I R S T _ S E T &amp;gt;------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
scans through a list of parameter names that are aliases of each other and returns the value assigned to the&lt;br /&gt;
first args[alias] that has a set value; nil else. scan direction is right-to-left (top-to-bottom)&lt;br /&gt;
&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
local function first_set (list, args)&lt;br /&gt;
	local i = 1;&lt;br /&gt;
	local count = table_len (list);												-- get count of items in list&lt;br /&gt;
	&lt;br /&gt;
	while i &amp;lt;= count do															-- loop through all items in list&lt;br /&gt;
		if is_set( args[list[i]] ) then											-- if parameter name in list is set in args&lt;br /&gt;
			return args[list[i]];												-- return the value assigned to the args parameter&lt;br /&gt;
		end&lt;br /&gt;
		i = i + 1;																-- point to next&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[=[-------------------------&amp;lt; T I M E &amp;gt;----------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
This template takes several parameters (some positonal, some not); none are required:&lt;br /&gt;
	1. the time zone abbreviation/UTC offset (positional, always the first unnamed parameter)&lt;br /&gt;
	2. a date format flag; second positional parameter or |df=; can have one of several values&lt;br /&gt;
	3. |dst= when set to 'no' disables dst calculations for locations that do not observe dst – Arizona in MST&lt;br /&gt;
	4. |timeonly= when set to 'yes' only display the time&lt;br /&gt;
	5. |dateonly= when set to 'yes' only display the date&lt;br /&gt;
	6. |hide-refresh = when set to 'yes' removes the refresh link&lt;br /&gt;
	7. |hide-tz = when set to 'yes' removes the timezone name&lt;br /&gt;
	8. |unlink-tz = when set to 'yes' unlinks the timzone name&lt;br /&gt;
	9. |_TEST_TIME_= a specific utc time in ISO date time format used for testing this code&lt;br /&gt;
	&lt;br /&gt;
TODO: convert _TEST_TIME_ to |time=?&lt;br /&gt;
&lt;br /&gt;
Timezone abbreviations can be found here: [[List_of_time_zone_abbreviations]]&lt;br /&gt;
&lt;br /&gt;
For custom date format parameters |df-cust=,  |df-cust-a=,  |df-cust-p= use codes &lt;br /&gt;
described here: [[:mw:Help:Extension:ParserFunctions##time]]&lt;br /&gt;
&lt;br /&gt;
]=]&lt;br /&gt;
&lt;br /&gt;
local function time (frame)&lt;br /&gt;
	local args = getArgs (frame);&lt;br /&gt;
	local utc_timestamp, timestamp;												-- current or _TEST_TIME_ timestamps; timestamp is local ST or DST time used in output&lt;br /&gt;
	local dst_begin_ts, dst_end_ts;												-- DST begin and end timestamps in UTC&lt;br /&gt;
	local tz_abbr;																-- select ST or DST timezone abbreviaion used in output &lt;br /&gt;
	local time_string;															-- holds output time/date in |df= format&lt;br /&gt;
	local utc_offset;&lt;br /&gt;
	local invert;																-- true when southern hemisphere&lt;br /&gt;
	local DF;																	-- date format flag; the |df= parameter&lt;br /&gt;
	local is_dst_tz;&lt;br /&gt;
&lt;br /&gt;
	local data = table.concat ({'Module:Time/data', frame:getTitle():find('sandbox', 1, true) and '/sandbox' or ''}); -- make a data module name; sandbox or live&lt;br /&gt;
	data = mw.loadData (data);													-- load the data module&lt;br /&gt;
	cfg = data.cfg;																-- get the configuration table&lt;br /&gt;
	local tz_aliases = data.tz_aliases;											-- get the aliases table&lt;br /&gt;
	local tz_data = data.tz_data;												-- get the tz data table&lt;br /&gt;
&lt;br /&gt;
	local Timeonly = yesno(first_set (cfg.aliases['timeonly'], args));			-- boolean&lt;br /&gt;
	local Dateonly = yesno(first_set (cfg.aliases['dateonly'], args));			-- boolean&lt;br /&gt;
	if Timeonly and Dateonly then												-- invalid condition when both are set&lt;br /&gt;
		Timeonly, Dateonly = false;&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	local Hide_refresh = yesno(first_set (cfg.aliases['hide-refresh'], args));	-- boolean&lt;br /&gt;
	local Hide_tz = yesno(first_set (cfg.aliases['hide-tz'], args));			-- boolean&lt;br /&gt;
	local Unlink_tz = yesno(first_set (cfg.aliases['unlink-tz'], args));		-- boolean&lt;br /&gt;
	local DST = first_set (cfg.aliases['dst'], args) or true;					-- string 'always' or boolean&lt;br /&gt;
	&lt;br /&gt;
	local Lang = first_set (cfg.aliases['lang'], args);							-- to render in a language other than the local wiki's language&lt;br /&gt;
	&lt;br /&gt;
	local DF_cust = first_set (cfg.aliases['df-cust'], args);					-- custom date/time formats&lt;br /&gt;
	&lt;br /&gt;
	local DF_cust_a = first_set (cfg.aliases['df-cust-a'], args);				-- for am/pm sensitive formats&lt;br /&gt;
	local DF_cust_p = first_set (cfg.aliases['df-cust-p'], args);&lt;br /&gt;
&lt;br /&gt;
	if not ((DF_cust_a and DF_cust_p) or										-- DF_cust_a xor DF_cust_p&lt;br /&gt;
			(not DF_cust_a and not DF_cust_p))then&lt;br /&gt;
		return error_msg ('bad_df_pair');										-- both are required&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	if args[1] then&lt;br /&gt;
		args[1] = get_full_utc_offset (args[1]):lower();						-- make lower case because tz table member indexes are lower case&lt;br /&gt;
	else&lt;br /&gt;
		args[1] = 'utc';														-- default to utc&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	if mw.ustring.match (args[1], 'utc[%+%-±−]%d%d:%d%d') then					-- if rendering time for a UTC offset timezone&lt;br /&gt;
		tz.abbr = args[1]:upper():gsub('%-', '−');								-- set the link label to upper case and replace hyphen with a minus character (U+2212)&lt;br /&gt;
		tz.article = tz.abbr;													-- article title same as abbreviation&lt;br /&gt;
		tz.utc_offset = mw.ustring.match (args[1], 'utc([%+%-±−]?%d%d:%d%d)'):gsub('−', '%-');	-- extract the offset value; replace minus character with hyphen&lt;br /&gt;
		local s, t = mw.ustring.match (tz.utc_offset, '(±)(%d%d:%d%d)');		-- ± only valid for offset 00:00&lt;br /&gt;
		if s and '00:00' ~= t then&lt;br /&gt;
			return error_msg ('bad_sign');&lt;br /&gt;
		end&lt;br /&gt;
		tz.df = 'iso';&lt;br /&gt;
		args[1] = 'utc_offsets';												-- spoof to show that we recognize this timezone&lt;br /&gt;
	else&lt;br /&gt;
		tz = tz_aliases[args[1]] and tz_data[tz_aliases[args[1]]] or tz_data[args[1]];	-- make a local copy of the timezone table from tz_data{}&lt;br /&gt;
		if not tz then&lt;br /&gt;
			return error_msg ('unknown_tz', args[1]);							-- if the timezone given isn't in module:time/data(/sandbox)&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	DF = first_set (cfg.aliases['df'], args) or args[2] or tz.df or cfg.default_df;	-- template |df= overrides typical df from tz properties&lt;br /&gt;
	DF = DF:lower();															-- normalize to lower case&lt;br /&gt;
	if not cfg.df_vals[DF] then&lt;br /&gt;
		return error_msg ('bad_format', DF);&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	if is_set (args._TEST_TIME_) then											-- typically used to test the code at a specific utc time&lt;br /&gt;
		local test_time = get_test_time (args._TEST_TIME_);&lt;br /&gt;
		if not test_time then&lt;br /&gt;
			return error_msg ('test_time');&lt;br /&gt;
		end&lt;br /&gt;
&lt;br /&gt;
		utc_timestamp = os.time(test_time);&lt;br /&gt;
	else&lt;br /&gt;
		utc_timestamp = os.time ();												-- get current server time (UTC)&lt;br /&gt;
	end&lt;br /&gt;
	utc_offset = get_utc_offset ();												-- utc offset for specified timezone in seconds&lt;br /&gt;
	timestamp = utc_timestamp + utc_offset;										-- make local time timestamp&lt;br /&gt;
&lt;br /&gt;
	if 'always' == DST then														-- if needed to always display dst time&lt;br /&gt;
		timestamp = timestamp + 3600;											-- add a hour for dst&lt;br /&gt;
		tz_abbr = tz.dst_abbr;													-- dst abbreviation&lt;br /&gt;
	elseif not yesno(DST) then													-- for timezones that DO observe dst but for this location ...&lt;br /&gt;
		tz_abbr = tz.abbr;														-- ... dst is not observed (|dst=no) show time as standard time&lt;br /&gt;
	else&lt;br /&gt;
		if is_set (tz.dst_begins) and is_set (tz.dst_ends) and is_set (tz.dst_time) then	-- make sure we have all of the parts&lt;br /&gt;
			dst_begin_ts, dst_end_ts, invert = make_dst_timestamps (timestamp);	-- get begin and end dst timestamps and invert flag&lt;br /&gt;
&lt;br /&gt;
			if nil == dst_begin_ts or nil == dst_end_ts then&lt;br /&gt;
				return error_msg ('bad_dst');&lt;br /&gt;
			end&lt;br /&gt;
	&lt;br /&gt;
			if invert then														-- southern hemisphere; use beginning and ending of standard time in the comparison&lt;br /&gt;
				if utc_timestamp &amp;gt;= dst_end_ts and utc_timestamp &amp;lt; dst_begin_ts then	-- is current date time standard time?&lt;br /&gt;
					tz_abbr = tz.abbr;											-- standard time abbreviation&lt;br /&gt;
				else		&lt;br /&gt;
					timestamp = timestamp + 3600;								-- add an hour&lt;br /&gt;
					tz_abbr = tz.dst_abbr;										-- dst abbreviation&lt;br /&gt;
				end&lt;br /&gt;
			else																-- northern hemisphere&lt;br /&gt;
				if utc_timestamp &amp;gt;= dst_begin_ts and utc_timestamp &amp;lt; dst_end_ts then	-- all timestamps are UTC&lt;br /&gt;
					timestamp = timestamp + 3600;								-- add an hour &lt;br /&gt;
					tz_abbr = tz.dst_abbr;&lt;br /&gt;
				else&lt;br /&gt;
					tz_abbr = tz.abbr;&lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
		elseif is_set (tz.dst_begins) or is_set (tz.dst_ends) or is_set (tz.dst_time) then	-- if some but not all not all parts then emit error message&lt;br /&gt;
			return error_msg ('bad_def', args[1]:upper());&lt;br /&gt;
		else&lt;br /&gt;
			tz_abbr = tz.abbr;													-- dst not observed for this timezone&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	if Dateonly then&lt;br /&gt;
		if 'iso' == DF then														-- |df=iso&lt;br /&gt;
			DF = 'iso_date';&lt;br /&gt;
		elseif DF:find ('^dmy') or 'y' == DF then								-- |df=dmy, |df=dmy12, |df=dmy24, |df=y&lt;br /&gt;
			DF = 'dmy_date';&lt;br /&gt;
		else&lt;br /&gt;
			DF = 'mdy_date';													-- default&lt;br /&gt;
		end&lt;br /&gt;
&lt;br /&gt;
	elseif Timeonly or DF:match ('^%d+$') then									-- time only of |df= is just digits&lt;br /&gt;
		DF = table.concat ({'t', DF:match ('%l*(12)') or '24'});				-- |df=12, |df=24, |df=dmy12, |df=dmy24, |df=mdy12, |df=mdy24; default to t24&lt;br /&gt;
		&lt;br /&gt;
	elseif 'y' == DF or 'dmy24' == DF then&lt;br /&gt;
		DF = 'dmy';&lt;br /&gt;
&lt;br /&gt;
	elseif 'mdy24' == DF then&lt;br /&gt;
		DF = 'mdy';&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	local dformat;&lt;br /&gt;
	if is_set (DF_cust) then&lt;br /&gt;
		dformat=DF_cust;&lt;br /&gt;
	elseif is_set (DF_cust_a) then												-- custom format is am/pm sensitive?&lt;br /&gt;
		if 'am' == os.date ('%P', timestamp) then								-- if current time is am&lt;br /&gt;
			dformat = DF_cust_a;												-- use custom am format&lt;br /&gt;
		else&lt;br /&gt;
			dformat = DF_cust_p;												-- use custom pm format&lt;br /&gt;
		end&lt;br /&gt;
	else&lt;br /&gt;
		dformat = cfg.format[DF];												-- use format from tables or from |df=&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	time_string = frame:callParserFunction ({name='#time', args={dformat, '@'..timestamp, Lang}});&lt;br /&gt;
	if Lang then&lt;br /&gt;
		time_string = table.concat ({											-- bidirectional isolation of non-local language; yeah, rather brute force but simple&lt;br /&gt;
			'&amp;lt;bdi lang=&amp;quot;',														-- start of opening bdi tag&lt;br /&gt;
			Lang,																-- insert rendered language code&lt;br /&gt;
			'&amp;quot;&amp;gt;',																-- end of opening tag&lt;br /&gt;
			time_string,														-- insert the time string&lt;br /&gt;
			'&amp;lt;/bdi&amp;gt;'															-- and close the tag&lt;br /&gt;
			});&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	if not is_set (tz.article) then												-- if some but not all not all parts then emit error message&lt;br /&gt;
		return error_msg ('bad_def', args[1]:upper());&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	local refresh_link = (Hide_refresh and '') or&lt;br /&gt;
		table.concat ({&lt;br /&gt;
			' &amp;lt;span class=&amp;quot;plainlinks&amp;quot; style=&amp;quot;font-size:85%;&amp;quot;&amp;gt;[[',				-- open span&lt;br /&gt;
			mw.title.getCurrentTitle():fullUrl({action = 'purge'}),				-- add the a refresh link url&lt;br /&gt;
			' ',&lt;br /&gt;
			cfg['refresh-label'],												-- add the label&lt;br /&gt;
			']]&amp;lt;/span&amp;gt;',														-- close the span&lt;br /&gt;
			});&lt;br /&gt;
&lt;br /&gt;
	local tz_tag = (Hide_tz and '') or&lt;br /&gt;
		((Unlink_tz and table.concat ({' ', tz_abbr})) or						-- unlinked&lt;br /&gt;
			table.concat ({' [[', tz.article, '|', tz_abbr, ']]'}));			-- linked&lt;br /&gt;
	&lt;br /&gt;
	return table.concat ({time_string, tz_tag, refresh_link});&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[--------------------------&amp;lt; E X P O R T E D   F U N C T I O N S &amp;gt;------------------------------------------&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
return {time = time}&lt;/div&gt;</summary>
		<author><name>imported&gt;Pppery</name></author>
		
	</entry>
</feed>