Module:Dating

local p = {}
	function p.Dates (frame)
		local input = mw.text.trim(frame.args[1]) or 0
		if input ~= 0 then
			input = " " .. input .. " "
		end
		local xformat = frame.args.format or 0
		local xsuffix = frame.args.suffix or 0
		local sSuffix = 0
		local valid
		if input ~= 0 then valid = 1 else valid = 0 end
		local mnths = {}
		local yrs = {}
		local dts = {}
		local i = 1 
		local j = 1
		local k = 1
		local valid = 1
		local ly = 0
		local txt = ""
		local nums = {}
		local m = 1
		local Months = {
						"January",
						"February",
						"March",
						"April",
						"May",
						"June",
						"July",
						"August",
						"September",
						"October",
						"November",
						"December"
			           }
		for data in string.gmatch (input, "%w+") do
			data = " " .. data .. " "
			if data:find ("%s%d%a%a%s") then
				if tonumber(string.sub(data, 2, 2)) < 32 then
					dts[i] = tonumber(string.sub(data, 2, 2))
					i = i + 1
				end
			end
			if data:find ("%s%d%d%a%a%s") then
				if tonumber(string.sub(data, 2, 3)) < 32 then
					dts[i] = tonumber(string.sub(data, 2, 3))
					i = i + 1
				end
			end
		end
		if input:find ("%s%d%d%d%d%s") then
			yrs[k] = tonumber(string.sub(input, input:find ("%s%d%d%d%d%s")+1,  input:find ("%s%d%d%d%d%s")+4))
			k = k + 1
		end
		for l = 1, 12 do
			if input:find(string.sub(Months[l], 1, 3)) or input:find(string.lower(string.sub(Months[l], 1, 3))) then
				mnths[j] = l
				j = j + 1
			end
		end
		for data in string.gmatch (input, "%d+") do
			data = tonumber(data)
			if data > 31 then
				yrs[k] = data
				k = k + 1
			else
				if data > 12 then
					if #dts == 0 then
						dts[i] = data
						i = i + 1
					else
						nums[m] = data
						m = m + 1
					end
				else
					nums[m] = data
					m = m + 1
				end
			end
		end
		for l = 1, 3 do
			if nums[l] then
				if #dts == 0 then
					dts [i] = nums[l] 
					i = i + 1
				else 
					if #mnths == 0 then
						mnths [j] = nums[l]
						j = j + 1
					else
						if #yrs == 0 then
							yrs[k] = nums[l]
							k = k + 1
						end
					end
				end
			end
		end
		local date = dts[1] or 0
		local month = mnths[1] or 0
		local year = yrs[1] or 0
		if xformat == 0 then 
			if input:find ("/") or input:find ("-") then
				xformat = "iso"
			else
				if input:find (", ") then
					xformat = "mdy"
				else
					xformat = "dmy"
				end
			end
		end
		if date ~= 0 and year ~= 0 and month == 0 then
				xformat = "year"
		end
		if date == 0 and year ~= 0 and month == 0 then
				xformat = "year"
		end
		if input:find ("uncertain") or input:find("around") or input:find("sometime") then
			if input:find ("uncertain who") then
				sSuffix = 2
			else
				sSuffix = 1
			end
		end
		if xsuffix == 0 then 
			if input:find ("year") and input:find ("lord") then	xsuffix = "AD" 	end
			if input:find ("AD") then xsuffix = "AD" end
			if input:find ("BC") then xsuffix = "BC" end
			if input:find ("CE") then xsuffix = "CE" end
			if input:find ("BCE") then xsuffix = "BCE" end
		end
		if xsuffix ~= 0 then
			if year == 0 then
				if date ~= 0 and month ~= 0 then else
					if date ~= 0 then 
						year = date
						xformat = "year"
						date = 0
					end
					if month ~= 0 then
						year = month
						xforamt = "year"
						month = 0
					end
				end
			end
		end
		if date ~= 0 and year == 0 and month == 0 then valid = 0 end
		if month == 4 or month == 6 or month == 9 or month == 11 then 
			if date > 30 then
				valid = 0
			end
		end
		if year % 100 ~= 0 and year % 4 == 0 then
			ly = 1
		else
			if year % 400 == 0 then
				ly = 1
			end
		end
		if month == 2 then
			if ly == 1 then
				if date > 29 then
					valid = 0
				end
			else
				if date > 28 then
					valid = 0 
				end
			end
		end
		if date == 0 and month == 0 and year == 0 then valid = 0 end
		if year == 0 then
			for l = 1, 12 do
				if input:find(string.sub(Months[l], 1, 3)) or input:find(string.lower(string.sub(Months[l], 1, 3))) then
					valid = 1
					break
				else
					valid = 0
				end
			end
		end
		if valid == 0 then txt = "Invalid entry. "
		else
			if xformat == "iso" then
				if year ~= 0 then 
					txt = txt .. year
				end
				if month ~= 0 then
					if month > 10 then
						txt = txt .. "-" .. month
					else
						month = "0" .. month
						txt = txt .. "-" .. month
					end
				end
				if date ~= 0 then
					if date > 10 then
						txt = txt .. "-" .. date
					else
						date = "0" .. date
						txt = txt .. "-" .. date
					end
				end
			end
			if xformat == "dmy" then
				if date ~= 0 then
					txt = txt .. date
				end
				if month ~= 0 then
					txt = txt .. " " .. Months[month]
				end
				if year ~= 0 then 
					txt = txt .. " " .. year
				end
			end
			if xformat == "mdy" then
				if month ~= 0 then
					txt = txt .. Months[month]
				end
				if date ~= 0 then
					txt = txt .. " " .. date  
				end
				if year ~= 0 then 
					txt = txt .. ", " .. year
				end
			end
			if xformat == "year" then 
				if year ~= 0 then
					txt = txt .. year
				end
			end
			if xsuffix ~= 0 then
				txt = txt .. " " .. xsuffix
			end
			if sSuffix ~= 0 then
				if sSuffix == 1 then
					txt = "c. " .. txt
				end
				if sSuffix == 2 then
					txt = txt .. " (uncertain who was present)"
				end
			end
		end
		return txt .. " "
	end
return p

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.