Module:Date Stuff: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 57: | Line 57: | ||
date = {month, day, year} | date = {month, day, year} | ||
--Takes the text month variable and adds it to the day and year variable with a comma | |||
date = date[1].." "..date[2]..", "..date[3] | |||
return date | return date | ||
Line 70: | Line 73: | ||
date = convertDate(date) | date = convertDate(date) | ||
return date | return date | ||
end | end |
Revision as of 12:16, 5 July 2021
Documentation for this module may be created at Module:Date Stuff/doc
local p = {}
local args = {}
--Takes a string and splits it based on a specified delimiter
function Split(s, delimiter)
result = {};
for match in (s..delimiter):gmatch("(.-)"..delimiter) do
table.insert(result, match);
end
return result;
end
function convertDate(date)
--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
date = {month, day, year}
--Takes the text month variable and adds it to the day and year variable with a comma
date = date[1].." "..date[2]..", "..date[3]
return date
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]
--Calls the convert date function to convert short date to long date
date = convertDate(date)
return date
end
--Calculates an age based on two given dates
function p.solandriaBirthDateAge(frame)
--Sets the date variables based on passed through arguments
birthDate = frame.args[1]
currentDate = frame.args[2]
--Converts the first given date to a long date
convertedDate = convertDate(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
elseif currentMonth < birthMonth then
age = math.floor(currentYear - birthYear - 1)
else
error("Something went wrong")
end
--Takes the first date and adds the age to the end
dateAge = convertedDate.." (age "..age..")"
return dateAge
end
return p
--print(solandria("1-2-3"))
--print(solandriaBirthDateAge("12-18-392", "11-22-400"))