<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://dharmawiki.org/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://dharmawiki.org/index.php?action=history&amp;feed=atom&amp;title=Module%3AISOdate"/>
	<link rel="alternate" type="text/html" href="https://dharmawiki.org/index.php?title=Module:ISOdate&amp;action=history"/>
	<updated>2026-04-03T14:49:32Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.4</generator>
	<entry>
		<id>https://dharmawiki.org/index.php?title=Module:ISOdate&amp;diff=117290&amp;oldid=prev</id>
		<title>WikiSysop: 1 revision imported</title>
		<link rel="alternate" type="text/html" href="https://dharmawiki.org/index.php?title=Module:ISOdate&amp;diff=117290&amp;oldid=prev"/>
		<updated>2019-02-09T16:52:37Z</updated>

		<summary type="html">&lt;p&gt;1 revision imported&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left diff-editfont-monospace&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en-GB&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 16:52, 9 February 2019&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;en-GB&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://dharmawiki.org/index.php?title=Module:ISOdate&amp;diff=117289&amp;oldid=prev</id>
		<title>en&gt;Jarekt: fix ISOyear</title>
		<link rel="alternate" type="text/html" href="https://dharmawiki.org/index.php?title=Module:ISOdate&amp;diff=117289&amp;oldid=prev"/>
		<updated>2017-08-26T02:41:54Z</updated>

		<summary type="html">&lt;p&gt;fix ISOyear&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;
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;
 &lt;br /&gt;
local p = {}&lt;br /&gt;
&lt;br /&gt;
-- =======================================&lt;br /&gt;
-- === Dependencies ======================&lt;br /&gt;
-- =======================================&lt;br /&gt;
local D = require('Module:Date')&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;
function p._ISOyear( input )&lt;br /&gt;
	if not input then&lt;br /&gt;
		return ''&lt;br /&gt;
	end&lt;br /&gt;
	input = mw.text.trim( input )&lt;br /&gt;
    &lt;br /&gt;
	-- if empty string then return it&lt;br /&gt;
	if input == &amp;quot;&amp;quot; then&lt;br /&gt;
		return input&lt;br /&gt;
	end&lt;br /&gt;
    &lt;br /&gt;
	-- if number then return it&lt;br /&gt;
	if tonumber( input ) then&lt;br /&gt;
		return mw.ustring.format( '%04i', input )&lt;br /&gt;
	end&lt;br /&gt;
    &lt;br /&gt;
	-- otherwise use regular expression match&lt;br /&gt;
	input = mw.ustring.match( input, '^+?(-?%d%d?%d?%d?)-' )&lt;br /&gt;
	if input and tonumber( input ) then&lt;br /&gt;
		return mw.ustring.format( '%04i', input )&lt;br /&gt;
	else&lt;br /&gt;
		return ''&lt;br /&gt;
	end&lt;br /&gt;
end&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 datestr, succeded&lt;br /&gt;
	local args = frame.args&lt;br /&gt;
	if not (args.lang and mw.language.isSupportedLanguage(args.lang)) then &lt;br /&gt;
		args.lang = frame:callParserFunction( &amp;quot;int&amp;quot;, &amp;quot;lang&amp;quot; ) -- get user's chosen language &lt;br /&gt;
	end&lt;br /&gt;
	datestr, succeded = p._ISOdate(&lt;br /&gt;
		mw.text.trim(args[1]),&lt;br /&gt;
		args.lang,                  -- language&lt;br /&gt;
		args.case  or '',           -- allows to specify grammatical case for the month for languages that use them&lt;br /&gt;
		args.class or 'dtstart',    -- allows to set the html class of the time node where the date is included. &lt;br /&gt;
		args.trim_year or '100-999' -- 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;
function p._ISOdate(datestr, lang, case, class, trim_year)&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, tail, formatNum&lt;br /&gt;
	datevec, tail, formatNum = p.test_date_formats(datestr or '', patterns)&lt;br /&gt;
	if datevec[1]=='' or datevec[1]==nil then&lt;br /&gt;
		-- quickly return if datestr does not look like date (it could be a template)&lt;br /&gt;
		return datestr, false&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- call p._Date function to format date string&lt;br /&gt;
	local succeded, datestr2&lt;br /&gt;
	succeded, datestr2 = pcall( D._Date, datevec, lang, case, class, trim_year)&lt;br /&gt;
	if succeded and datestr2~='' 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;
function p.ISOdate_extended(frame)&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;
&lt;br /&gt;
	local datestr, succeded&lt;br /&gt;
	local args = frame.args&lt;br /&gt;
	if not (args.lang and mw.language.isSupportedLanguage(args.lang)) then &lt;br /&gt;
		args.lang = frame:callParserFunction( &amp;quot;int&amp;quot;, &amp;quot;lang&amp;quot; ) -- get user's chosen language &lt;br /&gt;
	end&lt;br /&gt;
	datestr, succeded = p._ISOdate(&lt;br /&gt;
		mw.text.trim(args[1]),&lt;br /&gt;
		args.lang,                  -- language&lt;br /&gt;
		args.case  or '',           -- allows to specify grammatical case for the month for languages that use them&lt;br /&gt;
		args.class or 'dtstart',    -- allows to set the html class of the time node where the date is included. &lt;br /&gt;
		args.trim_year or '100-999' -- 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;
	if succeded then&lt;br /&gt;
		return datestr&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	local patterns = {&lt;br /&gt;
		-- Exended set of recognized formats: like MM/DD/YYYY&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;
		{dlen=3, tail=0, regexp=&amp;quot;^(%d%d?)%s(%w+)%s(%d%d%d%d)$&amp;quot;},&lt;br /&gt;
		{dlen=3, tail=0, regexp=&amp;quot;^(%w+)%s(%d%d?),%s(%d%d%d%d)$&amp;quot;},&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	local datevec, tail, formatNum, category = ''&lt;br /&gt;
	datevec, tail, formatNum = p.test_date_formats(frame.args[1], patterns)&lt;br /&gt;
	if formatNum==1 or formatNum==2 then&lt;br /&gt;
		vec = datevec;&lt;br /&gt;
		if tonumber(datevec[1])&amp;gt;12 then&lt;br /&gt;
			frame.args[1] = string.format('%04i-%02i-%02i', datevec[3], datevec[2], datevec[1] )&lt;br /&gt;
			category = '[[Category:Date in DD/MM/YYYY format]]'&lt;br /&gt;
			return mw.text.trim( p.ISOdate(frame) .. tail);&lt;br /&gt;
		elseif tonumber(datevec[2])&amp;gt;12 then&lt;br /&gt;
			frame.args[1] = string.format('%04i-%02i-%02i', datevec[3], datevec[1], datevec[2] )&lt;br /&gt;
			category = '[[Category:Date in MM/DD/YYYY format]]'&lt;br /&gt;
			return mw.text.trim( p.ISOdate(frame) .. tail);&lt;br /&gt;
		end&lt;br /&gt;
	elseif (formatNum==3 or formatNum==4) and (datevec[3]=='' or datevec[3]~=nil) then&lt;br /&gt;
		local str = mw.getCurrentFrame():callParserFunction( &amp;quot;#time&amp;quot;, { 'Y-m-d', datestr} )&lt;br /&gt;
		local vec = {str:match( &amp;quot;^(%d%d?%d?%d?)-(%d%d?)-(%d%d?)$&amp;quot; )}&lt;br /&gt;
		if vec and vec[1]~=nil then&lt;br /&gt;
			frame.args[1] = string.format('%04i-%02i-%02i', vec[1], vec[2], vec[3] )&lt;br /&gt;
			category = '[[Category:Date in word format]]'&lt;br /&gt;
			return p.ISOdate(frame);&lt;br /&gt;
		end&lt;br /&gt;
	end	&lt;br /&gt;
	return datestr&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.test_date_formats(datestr, patterns)&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;
&lt;br /&gt;
	local datevec = {'','','','','',''}&lt;br /&gt;
	local tail = ''&lt;br /&gt;
	local vec, pat&lt;br /&gt;
	local formatNum = 0&lt;br /&gt;
	for i, pat in ipairs( patterns ) do&lt;br /&gt;
		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(' ' .. vec[pat.tail], ' +', ' ')&lt;br /&gt;
			end&lt;br /&gt;
			formatNum = i&lt;br /&gt;
			break&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return datevec, tail, formatNum&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>en&gt;Jarekt</name></author>
	</entry>
</feed>