Module:Sandbox/Redlead07/Dates

.mw-parser-output .documentation,.mw-parser-output .documentation-metadata{border:1px solid var(--border-color-base,#a2a9b1);background-color:#ecfcf4;color:inhe

Module:Sandbox/Redlead07/Dates
local p = {}

function p.dmyformat(frame)
	local dmydate, format = frame.args.dmydate or "", frame.args.format or ""
	local a = string.match(dmydate, "(%d+) %w+ %d+") or 
	string.match(dmydate, "(%w+) %d+, %d+") or
	string.match(dmydate, "(%w+) %d+ %d+") or 
	string.match(dmydate, "(%d+)/%d+/%d+") or 
	string.match(dmydate, "(%d+)-%d+-%d+") or
	string.match(dmydate, "(%d+)%w+ %w+ %d+") or
	string.match(dmydate, "(%w+) %d+") or 
	string.match(dmydate, "(%d+) %w+") or 
	string.match(dmydate, "(%d+) %d+") or
	string.match(dmydate, "(%w+)") or 
	string.match(dmydate, "(%d+) %w+ %w+") or 
	string.match(dmydate, "(%d+)%w+ %u%w+ %d+") or ""
	local b = string.match(dmydate, "%d+ (%w+) %d+") or 
	string.match(dmydate, "%w+ (%d+), %d+") or
	string.match(dmydate, "%w+ (%d+) %d+") or 
	string.match(dmydate, "%d+/(%d+)/%d+") or 
	string.match(dmydate, "%d+-(%d+)-%d+") or
	string.match(dmydate, "%d+%w+ (%w+) %d+") or 
	string.match(dmydate, "%w+ (%d+)") or 
	string.match(dmydate, "%d+ (%w+)") or
	string.match(dmydate, "%d+ (%d+)") or
	string.match(dmydate, "%d+%w+ (%u)(%w+) %d+") or ""
	local c = string.match(dmydate, "%d+ %w+ (%d+)") or  
	string.match(dmydate, "%d+ %d+ (%d+)") or 
	string.match(dmydate, "%w+ %d+, (%d+)") or	
	string.match(dmydate, "%d+/%d+/(%d+)") or 
	string.match(dmydate, "%d+-%d+-(%d+)") or
	string.match(dmydate, "%w+ %d+ (%d+)") or
	string.match(dmydate, "%d+%w+ %w+ (%d+)") or 
	string.match(dmydate, "%d+%w+ %u%w+ (%d+)") or ""
	local d = string.match(dmydate, "%d+ %w+ %d+ (%a+)") or ""
	local e = string.match(dmydate, "(%d+)-(%d+)-(%d+)") or ""
	local f = string.match(dmydate, "(%w+) (%d+), (%d+)") or ""
	local g = string.match(dmydate, "(%d+)/(%d+)/(%d+)") or ""
	local h = string.match(dmydate, "(%d+) (%w+) (%d+)") or ""
	local i = string.match(dmydate, "(%d+)") or ""
	local j = string.match(dmydate, "(%d+) (%w+)") or ""
	local k = string.match(dmydate, "(%d+) (%d+)") or ""
	local l = string.match(dmydate, "(%d+)(%w+) (%w+) (%d+)") or ""
	local m = string.match(dmydate, "(%d+) (%w+) (%d+) (%w+)") or ""
	local n = string.match(dmydate, "(%w+) (%w+) (%w+) (%w+)") or ""
	local o = string.match(dmydate, "(%d+)%w+ (%u)(%w+) (%d+)") or ""
	local p = string.match(dmydate, "(%d+)%U+(%a+)%D+(%d+)") or ""
	local a2 = tonumber(a) or 0 
	local a3 = string.find(a, "%d+") or ""
	local a4 = string.find(a, "%d?") or ""
	local a5 = string.find(a, "%a+") or ""
	local b2 = tonumber(b) or 0
	local b3 = string.find(b, "%a+") or ""
	local c2 = tonumber(c) or 0
	local c3 = string.find(a, "%d+") or ""
	local day = ""
	local month = ""
	local year = ""
	
	if i ~= "" and a2>0 and a2>31 then year = a2 end
	if a2>0 and a4 ~= "" then day = a2 end
	if a5 == "" then a5 = "" else month = a end
	if c2>0 and c2>31 and c3 ~= "" then year = c end
	if year == c and a2>0 and a4 ~= "" then 
		day = a2
		month = b
		end
	if year == a2 then
		month = b 
		day = c 
		end
	if day == a2 then 
		month = b 
		year = c 
		end
	if month == a2 and c3 ~= "" then
		day = b 
		year = c 
		end
	if month == a2  and c == "" then
		year = b 
		end
	if day == a2 and c == "" and a3 ~= "" then
		year = b 
		end
	if e ~= "" then
		year = a2
		month = b
		day = c
		end
	if f ~= "" then
		month = a
		day = b
		year = c
		end
	if g ~= "" then
		day = a2
		month = b
		year = c
		end
	if k ~= "" then
		day = a
		year = b
		end
	if o ~= "" then
		day = a2
		month = b
		year = c
		end
	if a2 ~= day and b ~= day and c ~= day then day = "" end
	if a2 ~= year and b ~= year and c ~= year then year = "" end
	local years = string.match(dmydate, "BCE") or string.match(dmydate, "BC") or
	string.match(dmydate, "CE") or string.match(dmydate, "AD") or ""
	if j ~= "" and c == "" and d == "" and years ~= "" then
		year = a2
		years = b
		end
	local days = tonumber(day) or 0
	year = tonumber(year) or 0
	local mnthnumber = string.match(dmydate, "%d+/(%d+)/%d+") or string.match(dmydate, "%d+-(%d+)-%d+")
	mnthnumber = tonumber(mnthnumber) or 0
	if 	mnthnumber ~= 0 then
	mnthname = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}
	month = mnthname[mnthnumber]
	end
	
	month = month:gsub("^%l", string.upper)	
	local monthname = {Jan = "January", Feb = "February", Mar = "March", 
		Apr = "April", May = "May", Jun = "June", Jul = "July", Aug = "August", 
		Sep = "September", Oct = "October", Nov = "November", Dec = "December"} or ""
	local monthname2 = {January = "January", February = "February", March =
		"March", April = "April", May = "May", June = "June", July = "July",
		August = "August", September = "September", October = "October",
		November = "November", December = "December"} or ""
	local monthnum = {Jan = "01", Feb = "02", Mar = "03", Apr = "04", May = "05", Jun = "06", 
		Jul = "07", Aug = "08", Sep = "09", Oct = "10", Nov = "11", Dec = "12"}
	local monthnum2 = {January = "01", February = "02", March = "03", 
		April = "04", May = "05", June = "06", July = "07", August = "08", 
		September = "09", October = "10", November = "11", December = "12"} or ""
	monthnumber = monthnum[(month)] or monthnum2[(month)]
	months = monthname[(month)] or monthname2[(month)]
	if month == "feb" and (year % 4 == 0) and (year % 100 ~= 0) or (year % 400) == 0 then
		days_in_month = 29
	else
		days_in_month = 28
	end
	if month == "February" and (year % 4 == 0) and (year % 100 ~= 0) or (year % 400) == 0 then
		days_in_month = 29
	else
		days_in_month = 28
	end
	if months == "jan" or months == "January" then days_in_month = 31 end
	if months == "mar" or months == "March" then days_in_month = 31 end
	if months == "apr" or months == "April" then days_in_month = 30 end
	if months == "may" or months == "May" then days_in_month = 31 end
	if months == "jun" or months == "June" then days_in_month = 30 end
	if months == "jul" or months == "July" then days_in_month = 31 end	
	if months == "aug" or months == "August" then days_in_month = 31 end
	if months == "sep" or months == "September" then days_in_month = 30 end
	if months == "oct" or months == "October" then days_in_month = 31 end
	if months == "nov" or months == "November" then days_in_month = 30 end
	if months == "dec" or months == "December" then days_in_month = 31 end
	if format == "" and i ~= "" and j ~= "" and years ~= "" and m == "" then
	local no = string.format("%u %s", year, years)
	return no.."<br>"
	end
	if year ~= 0 and month ~= "" and days ~= 0 and years == "" and h ~= "" and j == ""
	and days<1 or days>days_in_month then
		return "Invalid entry".."<br>"
		end
	local circa = string.match(dmydate, "around") or string.match(dmydate, "sometime") or 
	string.match(dmydate, "uncertain") or ""
	if p ~= "" and years == "" and circa == "" and m == "" and h == "" then
		d, m, y = string.match(dmydate, "(%d+)%U+(%a+)%D+(%d+)")
		return d.." "..m.." "..y.."<br>"
		end
	if circa == "" and m == "" and n ~= "" then
	return "Invalid entry".."<br>"
	end
	if circa == "" and h ~= "" and format == "" and m ~= "" and years == "" and o == "" then
	return "Invalid entry".."<br>"
	end
	if circa ~= "" and format == "" and h ~= "" then
	local no = string.format("%u %s %u", day, months, year)
	return "circa".." "..no.."<br>"
	end
	if circa ~= "" and format == "mdy" then	
	local mdy = string.format("%s %u, %u", months, day, year) 
	return "circa".." "..mdy.."<br>"
	end
	if circa ~= "" and format == "year" and format ~= "" then
	local y = string.format("%u", year)
	return "circa".." "..y.."<br>"
	end
	if circa ~= "" and format == "" and i ~= "" and l == "" then
	local no = string.format("%u", year)
	return "circa".." "..no.."<br>"
	end
	if circa ~="" and format == "" and l ~= "" then
	local no = string.format("%u %s %u", day, months, year)
	return "circa".." "..no.."<br>"
	end

	if format == "iso" then 
	local iso = string.format("%u-%u-%u", year, monthnumber, day) 
	return iso.."<br>"
	end
	if format == "mdy" then
	local mdy = string.format("%s %u, %u", months, day, year)
	return mdy.."<br>"
	end
	if format == "dmy" then 	
	local dmy = string.format("%u %s %u", day, months, year)
	return dmy.."<br>"	
	end
	if format == "year" then
	local y = string.format("%u", year)
	return y.."<br>"
	end
	if format == "" and j ~= "" and c == "" and k == "" and a2<31 then
	local no = string.format("%u %s", day, months)
	return no.."<br>"
	end
	if format == "" and years ~= "" and m ~= "" then
	local no = string.format("%u %s %u %s", day, months, year, years) 
	return no.."<br>"
	end
	if format == "" and i ~= "" and b == "" and c == "" and a2<31 then
	local no = string.format("%u", day)
	return no.."<br>"
	end
	if format == "" and i ~= "" and c == "" and b2 == 0 and a2<31 then
	local no = string.format("%u", day)
	return no.."<br>"
	end
	if format == "" and h ~= "" then
	local no = string.format("%u %s %u", day, months, year)
	return no.."<br>"
	end
	if format == "" and k ~= "" and c == "" then
	local no = string.format("%u", year)
	return no.."<br>"
	end
	if format == "" and a2>31 and i ~= "" and j~= "" then
	local no = string.format("%u", year)
	return no.."<br>"
	end
	if format == "" and c == "" and b == "" and a2>0 and a2>31 then
	local no = string.format("%u", year)
	return no.."<br>"
	end
	if format == "" and g ~= "" then
	local no = string.format("%u-%u-%u", year, monthnumber, day)
	return no.."<br>"
	end
	if format == "mdy" and e ~= "" then
	local mdy = string.format("%s %u, %u", months, day, year)
	return mdy.."<br>"
	end
	if format == "" and e ~= "" then
	local no = string.format("%u-%u-%u", year, monthnumber, day)
	return no.."<br>"
	end
	if format == "" and o ~= "" then
	local no = string.format("%u %s %u", day, months, year)
	return no.."<br>"
	end
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.