Module:Date Stuff: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 85: Line 85:
--Calculates a persons age using the specified calendar
--Calculates a persons age using the specified calendar
function p._age(args)
function p._age(args)
   firstDate = args[1]
   birthDate = args[1]
   secondDate = args[2]
   secondDate = args[2]
   status = args[3]
   status = args[3]
   calendar = args[4]
   calendar = args[4]
   --checks if firstDate is not nil, and if it is returns the second date
   --checks if birthDate is not nil, and if it is returns the second date
   if firstDate ~= nil then
   if birthDate ~= nil then
     firstDate = convertShortDate(firstDate, calendar)
     birthDate = convertShortDate(birthDate, calendar)
     secondDate = convertShortDate(secondDate, calendar)
     secondDate = convertShortDate(secondDate, calendar)
   elseif firstDate == nil then
   elseif birthDate == nil then
     return writeDate(convertShortDate(secondDate))
     return writeDate(convertShortDate(secondDate))
   end
   end
    
    
   --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 firstDate[4] == "year" or secondDate[4] == "year" or firstDate[4] == "month-year" or secondDate[4] == "month-year" or firstDate[2] <= secondDate[2] then
   if birthDate[4] == "year" or secondDate[4] == "year" then
     age = math.floor(secondDate[3] - firstDate[3])
    age = math.floor(secondDate[3] - birthDate[3])
  elseif firstDate[2] >= secondDate[2] then
  elseif birthDate[4] == "month-year" or secondDate[4] == "month-year" then
    age = math.floor(secondDate[3] - firstDate[3] - 1)
    if birthDate[2] < secondDate[2] then
      age = math.floor(secondDate[3] - birthDate[3])
    elseif birthDate[2] >= secondDate[2] then
      age = math.floor(secondDate[3] - birthDate[3] - 1)
    end
  elseif birthDate[4] == "month-day-year" or secondDate[4] == "month-day-year" then
     if birthDate[2] < secondDate[2] then
      age = math.floor(secondDate[3] - birthDate[3])
    elseif birthDate[2] >= secondDate[2] then
      if birthDate[1] <= secondDate[1] then
        age = math.floor(secondDate[3] - birthDate[3])
      elseif birthDate[1] > secondDate[1] then
        age = math.floor(secondDate[3] - birthDate[3] - 1)
      end
    end
   end
   end
    
    
   --Determines if age or aged is required
   --Determines if age or aged is required
   if status == "alive" then
   if status == "alive" then
     return writeDate(firstDate).." (age "..age..")"
     return writeDate(birthDate).." (age "..age..")"
   elseif status == "dead" then
   elseif status == "dead" then
     return writeDate(secondDate).." (aged "..age..")"
     return writeDate(secondDate).." (aged "..age..")"