Module:Sandbox/trappist the monk/dualdate explained

require('strict');local getArgs = require ('Module:Arguments').getArgs; -- get parameters from frame

local months = ;

local islamic_months = ;

local formats =

--

local function get_dates (args, dates, m1, m2) if not (args[1] and args[4]) then -- must have year1 and year2 return '

error: both years are required'; elseif args[2] and args[5] then -- both months ... if (args[3] and not args[6]) or -- ... and first day but not second day (not args[3] and args[6]) then -- ... and second day but not first day return 'error: both days are required'; end if not ('0' < args[2] and '13' > args[2]) and ('0' < args[5] and '13' > args[5]) then return 'error: invalid month'; end elseif (args[2] and not args[5]) or -- first month but not second month (not args[2] and args[5]) then -- second month but not first month return 'error: both months are required'; end

dates =

return nil, dates;end

----------------------------< _ R E N D E R _ D A T E S >----------------------------------------------------

renders both dates according to which date parts are present and which are not equal

local function _render_dates (dates, prefix, suffix) local prefix = '(' .. prefix .. ': '; local postfix = ')'; if not suffix then suffix = ; -- for concatenation end

if dates.year1 and dates.month1 and dates.day1 then -- year, month, and day dates if dates.year1 ~= dates.year2 then -- annotation wraps second date if dates.dmy then return string.format (formats['dmyspdmyp'], dates.day1, dates.month1, dates.year1, suffix, prefix, dates.day2, dates.month2, dates.year2, postfix); else return string.format (formats['mdyspmdyp'], dates.month1, dates.day1, dates.year1, suffix, prefix, dates.month2, dates.day2, dates.year2, postfix); end elseif dates.month1 ~= dates.month2 then -- annotation wraps second month and day if dates.dmy then return string.format (formats['dmpdmpy'], dates.day1, dates.month1, prefix, dates.day2, dates.month2, postfix, dates.year2); else return string.format (formats['mdpmdpy'], dates.month1, dates.day1, prefix, dates.month2, dates.day2, postfix, dates.year2); end elseif dates.day1 ~= dates.day2 then -- annotation wraps second day if dates.dmy then return string.format (formats['dpdpmy'], dates.day1, prefix, dates.day2, postfix, dates.month2, dates.year2); else return string.format (formats['mdpdpy'], dates.month1, dates.day1, prefix, dates.day2, postfix, dates.year2); end else return '

error: identical YMD dates'; end elseif dates.year1 and dates.month1 then -- year and month dates if dates.year1 ~= dates.year2 then -- annotation wraps second month year return string.format (formats['mypmyp'], dates.month1, dates.year1, prefix, dates.month2, dates.year2, postfix); elseif dates.month1 ~= dates.month2 then -- annotation wraps second month return string.format (formats['mpmpy'], dates.month1, prefix, dates.month2, postfix, dates.year2); else return 'error: identical YM dates'; end else -- year dates if dates.year1 ~= dates.year2 then -- annotation wraps second year return string.format (formats['ypyp'], dates.year1, prefix, dates.year2, postfix); else return 'error: identical Y dates'; end endend

--nsos_date|||||||df=[dmy|mdy]|alt=|link=no}}

ns date listed first followed by os date; os date has os annotation

local function nsos_date (frame) local args = getArgs(frame); -- get parameters local dates = ; local msg;

msg, dates = get_dates (args, dates, months, months); if msg then return message; -- date check failed show a message end

local prefix = (args.alt and args.alt) or ('no'

args.link and 'O.S.' or 'O.S.'); return _render_dates (dates, prefix)end

--osns_date|||||||df=[dmy|mdy]|alt=|link=no}}

os date listed first followed by ns date; ns date has ns annotation

local function osns_date (frame) local args = getArgs(frame); -- get parameters local dates = ; local msg;

msg, dates = get_dates (args, dates, months, months); if msg then return message; -- date check failed show a message end

local prefix = (args.alt and args.alt) or ('no'

args.link and 'N.S.' or 'N.S.'); return _render_dates (dates, prefix)end

--ceah_date|||||||link=no}}

ce date listed first followed by ah date; ah date has ah annotation

local function ceah_date (frame) local args = getArgs(frame); -- get parameters local dates = ; local msg;

msg, dates = get_dates (args, dates, months, islamic_months); if msg then return message; -- date check failed show a message end

local prefix = 'no'

args.link and 'A.H.' or 'A.H.'; return _render_dates (dates, prefix)end

--ahce_date|||||||link=no}}

ah date listed first followed by ce date; ce date has ce annotation

local function ahce_date (frame) local args = getArgs(frame); -- get parameters local dates = ; local msg; local prefix, suffix;

msg, dates = get_dates (args, dates, islamic_months, months); if msg then return message; -- date check failed show a message end

prefix = 'no'

args.link and 'CE' or 'CE'; suffix = ' ' .. ('no'

args.link and 'A.H.' or 'A.H.'); -- leading space required return _render_dates (dates, prefix, suffix);end

----------------------------< E X P O R T E D F U N C T I O N S >------------------------------------------

return