4,599
edits
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 = {monthNames[tonumber(date[1])], tonumber(date[1]), nil, tonumber(date[2]), "month-year"} | ||
else | else | ||
date = {monthNames[tonumber(date[1])] | 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[ | if date[5] == "year" then | ||
return date[ | return date[4] | ||
elseif date[ | elseif date[5] == "month-year" then | ||
return date[1].." "..date[ | 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[ | 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[ | if birthDate[5] == "year" or secondDate == "year" then | ||
age = math.floor(secondDate[ | age = math.floor(secondDate[4] - birthDate[4]) | ||
elseif birthDate[ | 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[ | age = math.floor(secondDate[4] - birthDate[4]) | ||
elseif birthDate[2] > | elseif birthDate[2] > secondDate[2] then | ||
age = math.floor(secondDate[ | age = math.floor(secondDate[4] - birthDate[4] - 1) | ||
end | end | ||
elseif birthDate[ | 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[ | age = math.floor(secondDate[4] - birthDate[4]) | ||
elseif birthDate[2] | elseif birthDate[2] == secondDate[2] then | ||
if | if birtDate[3] <= secondDate[3] then | ||
age = math.floor(secondDate[ | age = math.floor(secondDate[4] - birthDate[4]) | ||
elseif | elseif birtDate[3] > secondDate[3] then | ||
age = math.floor(secondDate[ | 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 |