ماڈیول:Citation/CS1/dates
شکل و صورت
< ماڈیول:Citation | CS1
Documentation for this module may be created at ماڈیول:Citation/CS1/dates/doc
local p = {}
match_tab = {
--["^[1-9]%d? +%a+ +[1-9]%d%d%d%a?$"] ="(%d%d*)%s*(%a+)%s*((%d%d%d%d)%a?)",
["^%d %a+ %d%d%d%d$"] ="(%d) (%a+) (%d%d%d%d)",
["^%d%d %a+ %d%d%d%d$"] ="(%d%d) (%a+) (%d%d%d%d)",
['^%d %d %d%d%d%d$']= '(%d) (%d) (%d%d%d%d)',
['^%d %d%d %d%d%d%d$']= '(%d) (%d%d) (%d%d%d%d)',
['^%d%d %d %d%d%d%d$']= '(%d%d) (%d) (%d%d%d%d)',
['^%d%d %d%d %d%d%d%d$']= '(%d%d) (%d%d) (%d%d%d%d)',
['^%d%-%d%-%d%d%d%d$']= '(%d)%-(%d)%-(%d%d%d%d)',
['^%d%-%d%d%-%d%d%d%d$']= '(%d)%-(%d%d)%-(%d%d%d%d)',
['^%d%d%-%d%-%d%d%d%d$']= '(%d%d)%-(%d)%-(%d%d%d%d)',
['^%d%d%-%d%d%-%d%d%d%d$']= '(%d%d)%-(%d%d)%-(%d%d%d%d)',
}
--[[
tato = {"%d" , "%d%d"}
spaces = {" " , "%-"}
for _p, space in pairs(spaces) do
for o, k1 in ipairs(tato) do
for _, k2 in ipairs(tato) do
s_k = "^" .. k1 .. space .. k2 .. space .. "%d%d%d%d$"
s_v = "(" .. k1 .. ")".. space .. "(" .. k2 .. ")".. space .. "(" .. "%d%d%d%d)"
match_tab[s_k] = s_v
mw.log("['" .. s_k .. "']= '" .. s_v .. "'")
end
end
end
]]
local function get_month_number(month)
month2 = month:lower()
local long_months = {['january']=1, ['february']=2, ['march']=3, ['april']=4, ['may']=5, ['june']=6, ['july']=7, ['august']=8, ['september']=9, ['october']=10, ['november']=11, ['december']=12,
['جنوری']=1, ['فروری']=2, ['مارچ']=3, ['اپریل']=4, ['مئی']=5, ['جون']=6, ['جولائی']=7, ['اگست']=8, ['ستمبر']=9, ['اکتوبر']=10, ['نومبر']=11, ['دسمبر']=12 };
local short_months = {['jan']=1, ['feb']=2, ['mar']=3, ['apr']=4, ['may']=5, ['jun']=6, ['jul']=7, ['aug']=8, ['sep']=9, ['oct']=10, ['nov']=11, ['dec']=12};
return long_months[month2] or -- if month is the long-form name
short_months[month2] or -- if month is the short-form name
0; -- misspelled, improper case, or not a month name
end
function p.check_date (date_string)
local year;
local month=0;
local day=0;
local faild = true;
local date_string2 = date_string
if string.find(date_string,"[ا|أ|ب|ت|ث|ج|ح|خ|د|ذ|ر|ز|س|ش|ص|ض|ط|ظ|ع|غ|ف|ق|ك|ل|م|ن|ه|و|ي]")
then date_string2 = date_string
else
for key, v in pairs(match_tab) do
if date_string:match( key ) then
faild = false
day, month, year = string.match(date_string, v );
if month:match("%a+") then
month = get_month_number(month)
end
date_string2 = day .. "-" .. month .. "-" .. year
mw.log("day" .. day .. ", month" .. month .. ", year" .. year)
if 12 < tonumber(month) or 31 < tonumber(month) or 1 > tonumber(month) or 1582 > tonumber(year) or 0 == tonumber(day)
then
mw.log(date_string .. " false")
return false
end
end
end
end
fa = date_string2
if faild then
mw.log(date_string .. " faild")
else
--fa = '{{#time:d F Y|' .. date_string .. '}}'
fa = mw.getCurrentFrame():callParserFunction( '#time:d F Y', '' .. date_string2 .. '' )
end
--cp = "* " .. date_string .. " : \n**" .. fa
return fa
end
function p.check (frame)
return p.check_date(frame.args[1])
end
return p