Module:Date Stuff: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
No edit summary
Line 38: Line 38:


--Takes a short form date and converts it to a long form, and marks if it is only a year, or a month and year
--Takes a short form date and converts it to a long form, and marks if it is only a year, or a month and year
function convertShortDate(date, calendar)
function convertShortDate(shortDate, calendar)
   --In place of a long if elseif, I've put all the months into a single variable, with each in its numerical place.
   --In place of a long if elseif, I've put all the months into a single variable, with each in its numerical place.
   --This also allows us to add other calendars here
   --This also allows us to add other calendars here
   if calendar == "Solandria" then
   if calendar == "Solandria" then
     monthNames = {"Miry", "Ozdary", "Rydust", "Iptust", "Tosey", "Iverly", "Eohe", "Kasgust", "Andust", "Bepry", "Nindust", "Tymust", "Ekage", "Aphly", "Asust", "Syranust"}
     local monthNames = {"Miry", "Ozdary", "Rydust", "Iptust", "Tosey", "Iverly", "Eohe", "Kasgust", "Andust", "Bepry", "Nindust", "Tymust", "Ekage", "Aphly", "Asust", "Syranust"}
   elseif calendar == "Eberron" then
   elseif calendar == "Eberron" then
   monthNames = {"Zarantyr", "Olarune", "Therendor", "Eyre", "Dravago", "Nymm", "Lharvion", "Barrakas", "Rhann", "Sypheros", "Aryth", "Vult"}
   local monthNames = {"Zarantyr", "Olarune", "Therendor", "Eyre", "Dravago", "Nymm", "Lharvion", "Barrakas", "Rhann", "Sypheros", "Aryth", "Vult"}
   elseif calendar == "Forgotten Realms" then
   elseif calendar == "Forgotten Realms" then
   monthNames = {"Hammer", "Alturiak", "Ches", "Tarsakh", "Mirtul", "Kythorn", "Flamerule", "Eleasis", "Eleint", "Marpenoth", "Uktar", "Nightal"}
   local monthNames = {"Hammer", "Alturiak", "Ches", "Tarsakh", "Mirtul", "Kythorn", "Flamerule", "Eleasis", "Eleint", "Marpenoth", "Uktar", "Nightal"}
   elseif calendar == "IRL" then
   elseif calendar == "IRL" then
   monthNames = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}
   local monthNames = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}
   end
   end


   --Takes the provided variable and seperates it out into a table
   --Takes the provided variable and seperates it out into a table
   --Also marks if it is only a year or a month and year
   --Also marks if it is only a year or a month and year
   date = Split(date, "-")
   local shortDate = Split(shortDate, "-")
    
    
   if date[2] == nil then
   if shortDate[2] == nil then
     date = {nil, nil, nil, tonumber(date[1]), "year"}
     local dateTable = {nil, nil, nil, tonumber(shortDate[1]), "year"}
   elseif date[3] == nil then
   elseif shortDate[3] == nil then
     date = {monthNames[tonumber(date[1])], tonumber(date[1]), nil, tonumber(date[2]), "month-year"}
     local dateTable = {monthNames[tonumber(shortDate[1])], tonumber(shortDate[1]), nil, tonumber(shortDate[2]), "month-year"}
   else
   else
     date = {monthNames[tonumber(date[1])], tonumber(date[1]), tonumber(date[2]), tonumber(date[3]), "month-day-year"}
     local dateTable = {monthNames[tonumber(shortDate[1])], tonumber(shortDate[1]), tonumber(shortDate[2]), tonumber(shortDate[3]), "month-day-year"}
   end
   end
   return date
   return dateTable
end
end


Line 84: Line 84:
--Calculates a persons age using the specified calendar
--Calculates a persons age using the specified calendar
function p._age(args)
function p._age(args)
   birthDate = convertShortDate(args[1], args[4])
   local birthDate = convertShortDate(args[1], args[4])
   secondDate = convertShortDate(args[2], args[4])
   local secondDate = convertShortDate(args[2], args[4])
   status = args[3]
   local status = args[3]
    
    
   --Checks which math formula to use, based on how much of the date there is.
   --Checks which math formula to use, based on how much of the date there is.
Line 114: Line 114:
   if status == "alive" then
   if status == "alive" then
--    return writeDate(birthDate).." (age "..age..")"
--    return writeDate(birthDate).." (age "..age..")"
     return birthDate[1]..birthDate[2]..birthDate[3]..birthDate[4]..birthDate[5]
     return writeDate(birthDate).." (age "..age..")"
   elseif status == "dead" then
   elseif status == "dead" then
     return writeDate(secondDate).." (aged "..age..")"
     return writeDate(secondDate).." (aged "..age..")"

Navigation menu