Module:Date Stuff: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 56: Line 56:
    
    
   if date[2] == nil then
   if date[2] == nil then
     date = {nil, nil, date[1], "year"}
     date = {nil, nil, nil, tonumber(date[1]), "year"}
   elseif date[3] == nil then
   elseif date[3] == nil then
     date = {monthNames[tonumber(date[1])].." ("..date[1]..")", nil, date[2], "month-year"}
     date = {monthNames[tonumber(date[1])], tonumber(date[1]), nil, tonumber(date[2]), "month-year"}
   else
   else
     date = {monthNames[tonumber(date[1])].." ("..date[1]..")", date[2], date[3], "month-day-year"}
     date = {monthNames[tonumber(date[1])], tonumber(date[1]), tonumber(date[2]), tonumber(date[3]), "month-day-year"}
   end
   end
   return date
   return date
end
end
Line 68: Line 67:
--Writes that date based on what is given.
--Writes that date based on what is given.
function writeDate(date)
function writeDate(date)
   if date[4] == "year" then
   if date[5] == "year" then
     return date[3]
     return date[4]
   elseif date[4] == "month-year" then
   elseif date[5] == "month-year" then
     return date[1].." "..date[3]
     return date[1].." ("..date[2]..") "..date[4]
   elseif date[4] == "month-day-year" then
   elseif date[4] == "month-day-year" then
     return date[1].." "..date[2]..", "..date[3]
     return date[1].." ("..date[2]..") "..date[3]..", "..date[4]
   end
   end
end
end
Line 98: Line 97:
    
    
   --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.
   if birthDate[4] == "year" or secondDate[4] == "year" then
   if birthDate[5] == "year" or secondDate == "year" then
     age = math.floor(secondDate[3] - birthDate[3])
     age = math.floor(secondDate[4] - birthDate[4])
   elseif birthDate[4] == "month-year" or secondDate[4] == "month-year" then
   elseif birthDate[5] == "month-year" or secondDate == "month-year" then
     if birthDate[2] < secondDate[2] then
     if birthDate[2] <= secondDate[2] then
       age = math.floor(secondDate[3] - birthDate[3])
       age = math.floor(secondDate[4] - birthDate[4])
     elseif birthDate[2] >= secondDate[2] then
     elseif birthDate[2] > secondDate[2] then
       age = math.floor(secondDate[3] - birthDate[3] - 1)
       age = math.floor(secondDate[4] - birthDate[4] - 1)
     end
     end
   elseif birthDate[4] == "month-day-year" or secondDate[4] == "month-day-year" then
   elseif birthDate[5] == "month-day-year" or secondDate == "month-day-year" then
     if birthDate[2] < secondDate[2] then
     if birthDate[2] < secondDate[2] then
       age = math.floor(secondDate[3] - birthDate[3] - 1)
       age = math.floor(secondDate[4] - birthDate[4])
     elseif birthDate[2] >= secondDate[2] then
     elseif birthDate[2] == secondDate[2] then
       if birthDate[1] <= secondDate[1] then
       if birtDate[3] <= secondDate[3] then
         age = math.floor(secondDate[3] - birthDate[3])
         age = math.floor(secondDate[4] - birthDate[4])
       elseif birthDate[1] > secondDate[1] then
       elseif birtDate[3] > secondDate[3] then
         age = math.floor(secondDate[3] - birthDate[3] - 1)
         age = math.floor(secondDate[4] - birthDate[4] - 1)
       end
       end
    elseif birthDate[2] > secondDate[2] then
      age = math.floor(secondDate[4] - birthDate[4] - 1)
     end
     end
   end
   end