-- For GCI Lua Task 10local p =
function p.reign(frame) -- **** Taking in all parameters' value **** -- local startDate = frame.args[1] or "" -- Start date, string and/or number, optional local endDate = frame.args[2] or "" -- End date, string and/or number, optional local startDate2 = frame.args[3] or "" -- 2nd Start date, string and/or number, optional local endDate2 = frame.args[4] or "" -- 2nd End date, string and/or number, optional local single = frame.args.single or "" -- Single date, string and/or number, optional local show = frame.args.show or frame.args.link or frame.args.lk or "" -- Formats "r.", "none", "link", "word", "colon", "lword", "lcolon", "blank", optional local cap = frame.args.cap or "" -- Capitalizes the r./reigned/reign text, "yes" or any other values, optional local preDate = frame.args['pre-date'] or "" -- Single date before date range, string and/or number, optional local postDate = frame.args['post-date'] or "" -- Single date after date range, string and/or number, optional local midDate = frame.args['mid-date'] or "" -- Single date between 2 date range, string and/or number, optional local era = frame.args.era or "" -- Adds era at the end, string and/or number (posibly link), optional local wrap = frame.args.wrap or "" -- Adds era at the end, "yes" or any other values, optional local sortable = frame.args.sortable -- local sortDate = frame.args.sort_date -- local label = frame.args.label or "" -- Phrase replacing "r.", string and/or number, optional if startDate ~= "" and endDate
"" and endDate2
"" and postDate
"" then single = startDate startDate = "" end -- **** Cleaning dates (remove head and tail space) **** -- local dateList = for dateListCount = 1, 7 do if string.sub(dateList[dateListCount], 1, 1)
' ' then dateList[dateListCount] = string.sub(dateList[dateListCount], 1, -2) end end startDate, endDate, startDate2, endDate2, preDate, postDate, midDate = unpack(dateList) -- **** Initial output **** -- local result = 'r. ' if show
'word' and cap ~= then result = 'Reigned ' end if show
'colon' and cap ~= then result = 'Reign: ' end if show
'lword' and cap ~= then result = 'Reigned ' end if show
'lcolon' and cap ~= then result = 'Reign: ' end if show
'c.' and string.sub(dateList[dateListCount], 1, 3) ~= 'c. ' then dateList[dateListCount] = 'c. ' .. string.sub(dateList[dateListCount], 3, -1) end end startDate, endDate, startDate2, endDate2 = unpack(dateList) -- **** Adding space before and after dash **** -- local isComplexDate1 = false local isComplexDate2 = false if string.find(startDate, ' ') ~= nil then isStartDateComplex = true end -- Check for space in middle of startDate if string.find(endDate, ' ') ~= nil then isEndDateComplex = true end -- Check for space in middle of endDate if string.find(startDate2, ' ') ~= nil then isStartDate2Complex = true end -- Check for space in middle of startDate2 if string.find(endDate2, ' ') ~= nil then isEndDate2Complex = true end -- Check for space in middle of endDate2 if string.sub(endDate, -4)
nil then isEndDateComplex = false end end if isStartDateComplex
true then isComplexDate1 = true -- true = there is at least 1 complex date end if isStartDate2Complex
true then isComplexDate2 = true -- true = there is at least 1 complex date end local dash1 = '–' local dash2 = '–' if startDate2
then dash2 = end if isComplexDate1 then dash1 = ' – ' end if isComplexDate2 then dash2 = ' – ' end if era ~= then era = ' ' .. era end if preDate ~= then preDate = preDate .. ', ' end if postDate ~= then postDate = ', ' .. postDate end if midDate ~= then midDate = ', ' .. midDate .. ', ' end -- **** Producing output **** -- if startDate
"" and preDate
"" and single
"" and endDate
"" and endDate
"" and endDate ~= "" then startDate = '?' end if endDate
"" and startDate2 ~= "" then endDate2 = " " end local commaBetweenDates = if startDate ~= "" and endDate ~= "" and startDate2 ~= "" and endDate2 ~= "" and midDate
return p