<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.p1gsel.com/p1gwars/index.php?action=history&amp;feed=atom&amp;title=Module%3AISOdate</id>
	<title>Module:ISOdate - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://www.p1gsel.com/p1gwars/index.php?action=history&amp;feed=atom&amp;title=Module%3AISOdate"/>
	<link rel="alternate" type="text/html" href="https://www.p1gsel.com/p1gwars/index.php?title=Module:ISOdate&amp;action=history"/>
	<updated>2026-04-19T15:34:30Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.1</generator>
	<entry>
		<id>https://www.p1gsel.com/p1gwars/index.php?title=Module:ISOdate&amp;diff=6283&amp;oldid=prev</id>
		<title>Rosie: Created page with &quot;--[[     __  __           _       _        ___ ____   ___      _       _         |  \/  | ___   __| |_   _| | ___ _|_ _/ ___| / _ \  __| | __ _| |_ ___   | |\/| |/ _ \ / _` | | | | |/ _ (_)| |\___ \| | | |/ _` |/ _` | __/ _ \  | |  | | (_) | (_| | |_| | |  __/_ | | ___) | |_| | (_| | (_| | ||  __/  |_|  |_|\___/ \__,_|\__,_|_|\___(_)___|____/ \___/ \__,_|\__,_|\__\___|       This module is intended for processing of date strings.  Please do not modify this code without a...&quot;</title>
		<link rel="alternate" type="text/html" href="https://www.p1gsel.com/p1gwars/index.php?title=Module:ISOdate&amp;diff=6283&amp;oldid=prev"/>
		<updated>2026-01-11T15:17:08Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;--[[     __  __           _       _        ___ ____   ___      _       _         |  \/  | ___   __| |_   _| | ___ _|_ _/ ___| / _ \  __| | __ _| |_ ___   | |\/| |/ _ \ / _` | | | | |/ _ (_)| |\___ \| | | |/ _` |/ _` | __/ _ \  | |  | | (_) | (_| | |_| | |  __/_ | | ___) | |_| | (_| | (_| | ||  __/  |_|  |_|\___/ \__,_|\__,_|_|\___(_)___|____/ \___/ \__,_|\__,_|\__\___|       This module is intended for processing of date strings.  Please do not modify this code without a...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;--[[  &lt;br /&gt;
  __  __           _       _        ___ ____   ___      _       _       &lt;br /&gt;
 |  \/  | ___   __| |_   _| | ___ _|_ _/ ___| / _ \  __| | __ _| |_ ___ &lt;br /&gt;
 | |\/| |/ _ \ / _` | | | | |/ _ (_)| |\___ \| | | |/ _` |/ _` | __/ _ \&lt;br /&gt;
 | |  | | (_) | (_| | |_| | |  __/_ | | ___) | |_| | (_| | (_| | ||  __/&lt;br /&gt;
 |_|  |_|\___/ \__,_|\__,_|_|\___(_)___|____/ \___/ \__,_|\__,_|\__\___|&lt;br /&gt;
     &lt;br /&gt;
This module is intended for processing of date strings.&lt;br /&gt;
&lt;br /&gt;
Please do not modify this code without applying the changes first at Module:ISOdate/sandbox and testing &lt;br /&gt;
at Module:ISOdate/sandbox/testcases and Module talk:ISOdate/sandbox/testcases.&lt;br /&gt;
&lt;br /&gt;
Authors and maintainers:&lt;br /&gt;
* User:Parent5446 - original version of the function mimicking template:ISOdate&lt;br /&gt;
* User:Jarekt - original version of the functions mimicking template:Date and template:ISOyear&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
-- =======================================&lt;br /&gt;
-- === Dependencies ======================&lt;br /&gt;
-- =======================================&lt;br /&gt;
local Date = require(&amp;#039;Module:DateI18n&amp;#039;)._Date&lt;br /&gt;
&lt;br /&gt;
-- =======================================&lt;br /&gt;
-- === Local Functions ===================&lt;br /&gt;
-- =======================================&lt;br /&gt;
&lt;br /&gt;
local function parse_ISOdate(datestr)&lt;br /&gt;
-- Core function of this module, which splits &amp;quot;datestr&amp;quot; contining date in ISO format into Year, month, day, ... components&lt;br /&gt;
-- Output is &amp;quot;datevec&amp;quot; array with numbers representing date components. We also return &amp;quot;tail&amp;quot; storing text following the date&lt;br /&gt;
&lt;br /&gt;
	-- pattern: regexp - regular expresion to test; dlen - number of date elements; tail = which element is a &amp;quot;tail&amp;quot; if any&lt;br /&gt;
	-- regexp hints:&lt;br /&gt;
	--  1) Strings starting with &amp;quot;^&amp;quot; and ending with &amp;quot;$&amp;quot; indicate whole string match&lt;br /&gt;
	--  2) optional tail part copied as-is and following the main parsed part of the date have to be separated from the date by a whitespace, so &amp;quot;(\s.+)?&amp;quot;&lt;br /&gt;
	local patterns = {&lt;br /&gt;
		-- strings starting with YYYY-MM-DD HH:MM:SS. Year 4 digits (if we know seconds than it was within the last 100 years), the rest 1-2&lt;br /&gt;
		-- date and time can be separated by space or &amp;quot;T&amp;quot; and there could be a &amp;quot;Z&amp;quot; on the end indicating &amp;quot;Zulu&amp;quot; time zone&lt;br /&gt;
		{dlen=6, tail=7, regexp=&amp;quot;^+?(%d%d%d%d)-(%d%d?)-(%d%d?)[ T](%d%d?):(%d%d?):(%d%d?)Z?(%s.*)&amp;quot;}, &lt;br /&gt;
		{dlen=6, tail=0, regexp=&amp;quot;^+?(%d%d%d%d)-(%d%d?)-(%d%d?)[ T](%d%d?):(%d%d?):(%d%d?)Z?$&amp;quot;}, &lt;br /&gt;
		-- strings starting with YYYY-MM-DD HH:MM. Year 4 digits, the rest 1-2&lt;br /&gt;
		-- (if one knows hour and minute than it was probably after a year 1000)&lt;br /&gt;
		{dlen=5, tail=6, regexp=&amp;quot;^+?(%d%d%d%d)-(%d%d?)-(%d%d?)[ T](%d%d?):(%d%d?)(%s.+)&amp;quot;},&lt;br /&gt;
		{dlen=5, tail=0, regexp=&amp;quot;^+?(%d%d%d%d)-(%d%d?)-(%d%d?)[ T](%d%d?):(%d%d?)$&amp;quot;},&lt;br /&gt;
		-- strings starting with YYYY-MM-DD. Year 1-4 digits, the rest 1-2&lt;br /&gt;
		{dlen=3, tail=4, regexp=&amp;quot;^+?(%d%d?%d?%d?)-(%d%d?)-(%d%d?)(%s.+)&amp;quot;},&lt;br /&gt;
		{dlen=3, tail=0, regexp=&amp;quot;^+?(%d%d?%d?%d?)-(%d%d?)-(%d%d?)$&amp;quot;},&lt;br /&gt;
		-- strings starting with YYYY-MM. Year 3-4 digits, month 2 digits&lt;br /&gt;
		-- (want to avoit converting to dates strings like 10-5 = 5&lt;br /&gt;
		{dlen=2, tail=3, regexp=&amp;quot;^+?(%d%d%d%d?)-(%d%d)(%s.+)&amp;quot;}, &lt;br /&gt;
		-- if whole string is in YYYY-MM form: If Year 1-4 digits, month 1-2 digits&lt;br /&gt;
		{dlen=2, tail=0, regexp=&amp;quot;^+?(%d%d?%d?%d?)-(%d%d?)$&amp;quot;}, &lt;br /&gt;
		-- string starts with a number -&amp;gt; it has to be 3 or 4 digit long to be a year&lt;br /&gt;
		{dlen=1, tail=2, regexp=&amp;quot;^+?(%d%d%d%d?)(%s.+)&amp;quot;},	&lt;br /&gt;
		 -- if whole string is a number (1-4 digit long) than it will be interpreted as a year&lt;br /&gt;
		{dlen=1, tail=0, regexp=&amp;quot;^+?(%d%d?%d?%d?)$&amp;quot;},&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	-- create datevec based on which variables are provided&lt;br /&gt;
	local datevec = {}&lt;br /&gt;
	local tail    = &amp;#039;&amp;#039;&lt;br /&gt;
	for i, pat in ipairs( patterns ) do&lt;br /&gt;
		local vec = {datestr:match( pat.regexp )}&lt;br /&gt;
		if vec and vec[1]~=nil then&lt;br /&gt;
			for j=1, pat.dlen do&lt;br /&gt;
				datevec[j] = vec[j]&lt;br /&gt;
			end&lt;br /&gt;
			if pat.tail&amp;gt;0 and vec[pat.tail]~=nil then&lt;br /&gt;
				tail = mw.ustring.gsub(&amp;#039; &amp;#039; .. vec[pat.tail], &amp;#039; +&amp;#039;, &amp;#039; &amp;#039;)&lt;br /&gt;
			end&lt;br /&gt;
			break&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	if not datevec[1] or datevec[1]==&amp;#039;&amp;#039; then&lt;br /&gt;
		-- quickly return if datestr does not look like date (it could be a template)&lt;br /&gt;
		return nil, nil&lt;br /&gt;
	end&lt;br /&gt;
	return datevec, tail&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- ==================================================&lt;br /&gt;
-- === External functions ===========================&lt;br /&gt;
-- ==================================================&lt;br /&gt;
local p = {}&lt;br /&gt;
&lt;br /&gt;
-- ===========================================================================&lt;br /&gt;
-- === Version of the function to be called from other LUA codes&lt;br /&gt;
-- ===========================================================================&lt;br /&gt;
&lt;br /&gt;
function p._ISOyear( datestr )&lt;br /&gt;
    &lt;br /&gt;
	-- if empty string then return it&lt;br /&gt;
	datestr = mw.text.trim(datestr or &amp;#039;&amp;#039; )&lt;br /&gt;
	if datestr == &amp;#039;&amp;#039; then&lt;br /&gt;
		return &amp;#039;&amp;#039;&lt;br /&gt;
	end&lt;br /&gt;
    &lt;br /&gt;
	-- if number then return it&lt;br /&gt;
	if tonumber( datestr ) then&lt;br /&gt;
		return mw.ustring.format( &amp;#039;%04i&amp;#039;, datestr )&lt;br /&gt;
	end&lt;br /&gt;
    &lt;br /&gt;
	-- otherwise use regular expression match&lt;br /&gt;
	datestr = mw.ustring.match( datestr, &amp;#039;^+?(-?%d%d?%d?%d?)-&amp;#039; )&lt;br /&gt;
	if datestr and tonumber( datestr ) then&lt;br /&gt;
		return mw.ustring.format( &amp;#039;%04i&amp;#039;, datestr )&lt;br /&gt;
	else&lt;br /&gt;
		return &amp;#039;&amp;#039;&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p._ISOdate(datestr, lang, case, class, trim_year)&lt;br /&gt;
	datestr = mw.text.trim(datestr or &amp;#039;&amp;#039; )&lt;br /&gt;
	local datevec, tail = parse_ISOdate(datestr)&lt;br /&gt;
	if not datevec then	&lt;br /&gt;
		return datestr, false -- quickly return if datestr does not look like date (it could be a template)&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- call p._Date function to format date string&lt;br /&gt;
	local datestr2 = Date(datevec, lang, case, class, trim_year)&lt;br /&gt;
	if datestr2~=&amp;#039;&amp;#039; then&lt;br /&gt;
		return mw.text.trim( datestr2 .. tail), true&lt;br /&gt;
	else -- in case of errors return the original string&lt;br /&gt;
		return datestr, false&lt;br /&gt;
	end	&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- ===========================================================================&lt;br /&gt;
-- === Versions of the function to be called from template namespace&lt;br /&gt;
-- ===========================================================================&lt;br /&gt;
--[[&lt;br /&gt;
ISOdate&lt;br /&gt;
 &lt;br /&gt;
This function is the core part of the ISOdate template. &lt;br /&gt;
 &lt;br /&gt;
Usage:&lt;br /&gt;
{{#invoke:ISOdate|ISOdate|target_string|lang=}}&lt;br /&gt;
 &lt;br /&gt;
Parameters:&lt;br /&gt;
     1: The date string &lt;br /&gt;
  lang: The language to display it in&lt;br /&gt;
  form: Language format (genitive, etc.) for some languages&lt;br /&gt;
 class: CSS class for the &amp;lt;time&amp;gt; node&lt;br /&gt;
&lt;br /&gt;
 Error Handling:&lt;br /&gt;
   If the string does not look like it contain the proper ISO date than the function will return the original string.&lt;br /&gt;
   &lt;br /&gt;
   That is the preferred treatment for the template:Information (and similar templates) which calling it.&lt;br /&gt;
]]&lt;br /&gt;
function p.ISOdate(frame)&lt;br /&gt;
	local args = {}&lt;br /&gt;
	for name, value in pairs( frame.args ) do &lt;br /&gt;
		if value ~= &amp;#039;&amp;#039; then -- nuke empty strings&lt;br /&gt;
			if type(name)==&amp;#039;string&amp;#039; then &lt;br /&gt;
				name = string.gsub( string.lower(name), &amp;#039; &amp;#039;, &amp;#039;_&amp;#039;)&lt;br /&gt;
			end&lt;br /&gt;
			args[name] = value&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	local datestr, succeded = p._ISOdate(&lt;br /&gt;
		args[1] or &amp;#039;&amp;#039;,&lt;br /&gt;
		args.lang,                  -- language&lt;br /&gt;
		args.case,                  -- allows to specify grammatical case for the month for languages that use them&lt;br /&gt;
		args.class or &amp;#039;dtstart&amp;#039;,    -- allows to set the html class of the time node where the date is included. &lt;br /&gt;
		args.trim_year or &amp;#039;100-999&amp;#039; -- by default pad one and 2 digit years to be 4 digit long, while keeping 3 digit years as is	&lt;br /&gt;
	)&lt;br /&gt;
	return datestr&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
ISOyear&lt;br /&gt;
 &lt;br /&gt;
This function returns year part of date string.&lt;br /&gt;
 &lt;br /&gt;
Usage:&lt;br /&gt;
{{#invoke:ISOdate|ISOyear|target_string}}&lt;br /&gt;
 &lt;br /&gt;
Parameters&lt;br /&gt;
    1: The date string &lt;br /&gt;
 &lt;br /&gt;
Error Handling:&lt;br /&gt;
   If the string does not look like it contain the year than the function will not return anything.&lt;br /&gt;
   That is the preferred treatment for the template:Creator which is the main (only?) template calling it.&lt;br /&gt;
]]&lt;br /&gt;
function p.ISOyear( frame )&lt;br /&gt;
	 return p._ISOyear( frame.args[1] )&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
ISOdate_part&lt;br /&gt;
 &lt;br /&gt;
This function returns any part of the date string (if present)&lt;br /&gt;
 &lt;br /&gt;
Usage:&lt;br /&gt;
{{#invoke:ISOdate|ISOdate_part|target_string|part number}}&lt;br /&gt;
 &lt;br /&gt;
Parameters&lt;br /&gt;
    1: The date string &lt;br /&gt;
    2: part number: 1-year, 2-month, 3-day, 4-hour, 5-minute, 6-second&lt;br /&gt;
 &lt;br /&gt;
]]&lt;br /&gt;
function p.ISOdate_part(frame)&lt;br /&gt;
	local date_str = mw.text.trim(frame.args[1] or &amp;#039;&amp;#039; )&lt;br /&gt;
	local part_num = tonumber(frame.args[2] or &amp;#039;1&amp;#039;)&lt;br /&gt;
	local datevec, tail = parse_ISOdate(date_str)&lt;br /&gt;
	return tonumber(datevec[part_num] or &amp;#039;0&amp;#039;)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>Rosie</name></author>
	</entry>
</feed>