4,595
edits
No edit summary |
No edit summary |
||
Line 4: | Line 4: | ||
--Takes a string and splits it based on a specified delimiter | --Takes a string and splits it based on a specified delimiter | ||
function Split(s, delimiter) | function Split(s, delimiter) | ||
result = {}; | |||
for match in (s..delimiter):gmatch("(.-)"..delimiter) do | |||
table.insert(result, match); | |||
end | |||
return result; | |||
end | |||
--Takes a short date and converts it to a long date (12-18-392 to Tymust 18, 392) | |||
function p.solandria(frame) | |||
--Sets date variable to the first frame argument | |||
date = frame.args[1] | |||
--Splits the date | |||
date = Split(date, "-") | |||
--Saves the parts of the date into month day year variables | |||
month = tonumber(date[1]) | |||
day = date[2] | |||
year = date[3] | |||
--Takes the month variable and converts it to its text counterpart | |||
if month == 1 then | |||
month = "Miry" | |||
elseif month == 2 then | |||
month = "Ozdary" | |||
elseif month == 3 then | |||
month = "Rydust" | |||
elseif month == 4 then | |||
month = "Iptust" | |||
elseif month == 5 then | |||
month = "Tosey" | |||
elseif month == 6 then | |||
month = "Iverly" | |||
elseif month == 7 then | |||
month = "Eohe" | |||
elseif month == 8 then | |||
month = "Kasgust" | |||
elseif month == 9 then | |||
month = "Andust" | |||
elseif month == 10 then | |||
month = "Bepry" | |||
elseif month == 11 then | |||
month = "Nindust" | |||
elseif month == 12 then | |||
month = "Tymust" | |||
elseif month == 13 then | |||
month = "Ekage" | |||
elseif month == 14 then | |||
month = "Aphly" | |||
elseif month == 15 then | |||
month = "Asust" | |||
elseif month == 16 then | |||
month = "Syranust" | |||
else | |||
error("invalid opperation") | |||
end | |||
--Takes the text month variable and adds it to the day and year variable with a comma | |||
date = month.." "..day..", "..year | |||
return date | |||
end | |||
--Calculates an age based on two given dates | |||
function p.solandriaBirthDateAge(birthDate, currentDate) | |||
--Converts the first given date to a long date | |||
convertedDate = solandria(birthDate) | |||
--Splits the first date given | |||
birthDate = Split(birthDate, "-") | |||
--Saves the parts of the first date given into seperate month day year variables | |||
birthMonth = birthDate[1] | |||
birthDay = birthDate[2] | |||
birthYear = birthDate[3] | |||
--Splits the second date given | |||
currentDate = Split(currentDate, "-") | |||
--Saves the parts of the second date given into seperate month day year variables | |||
currentMonth = currentDate[1] | |||
currentDay = currentDate[2] | |||
currentYear = currentDate[3] | |||
--Compares the second and first date month to determine which age calculation to use | |||
if currentMonth > birthMonth then | |||
age = math.floor(currentYear - birthYear) | |||
elseif currentMonth == birthMonth then | |||
if currentDay >= birthDay then | |||
age = math.floor(currentYear - birthYear) | |||
elseif currentDay < birthDay then | |||
age = math.floor(currentYear - birthYear - 1) | |||
else | |||
error("Something went wrong") | |||
end | end | ||
elseif currentMonth < birthMonth then | |||
end | age = math.floor(currentYear - birthYear - 1) | ||
else | |||
error("Something went wrong") | |||
end | |||
--Takes the first date and adds the age to the end | |||
return | dateAge = convertedDate.." (age "..age..")" | ||
return dateAge | |||
end | end | ||
return p | return p | ||
--print(solandria("1-2-3")) | |||
--print(solandriaBirthDateAge("12-18-392", "11-22-400")) |