Module:Today/GA: Difference between revisions

From TSP Encyclopedia
Jump to navigation Jump to search
(work?)
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 40: Line 40:
      
      
     -- Calculate custom calendar year and month
     -- Calculate custom calendar year and month
     local customYear = math.floor(totalDays / (10 * daysPerMonth)) + 1
     local customYear = math.floor(totalDays / (10 * daysPerMonth)) + 4749
     local customMonth = math.floor((totalDays - 1) % daysPerMonth) + 1
     local customMonth = math.floor((totalDays - 1) % daysPerMonth) + 1
      
      
     return string.format("Custom Calendar: Year %d, %s %d", customYear, monthNames[customMonth - 1], customMonth)
    local customMonthName = monthNames[customMonth]
   
     return customMonth .. customMonthName .. "\n" .. customYear
end
end


return CustomCalendar
return CustomCalendar

Latest revision as of 20:38, 11 August 2023

Documentation for this module may be created at Module:Today/GA/doc

------ IMPERIAL GALACTYAN CALENDAR ------

local CustomCalendar = {}

-- Define month names and days per month
local monthNames = {
    "Month 1", "Month 2", "Month 3", "Month 4", "Month 5",
    "Month 6", "Month 7", "Month 8", "Month 9", "Month 10"
}
local daysPerMonth = 59

-- Define days in each Gregorian month
local daysInMonth = {
    31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
}

-- Function to convert Gregorian date to custom calendar date
function CustomCalendar.convertToCustomCalendar(frame)
    local gregorianYear = tonumber(frame.args[1])
    local gregorianMonth = tonumber(frame.args[2])
    local gregorianDay = tonumber(frame.args[3])

    -- Validate input
    if not gregorianYear or not gregorianMonth or not gregorianDay then
        return "Invalid input"
    end
    
    -- Conversion logic
    
    -- Calculate total days passed in Gregorian calendar
    local totalDays = (gregorianYear - 1) * 365 + math.floor((gregorianYear - 1) / 4)  -- Basic leap year handling
    
    -- Add days of the months that have passed
    for i = 1, gregorianMonth - 1 do
        totalDays = totalDays + daysInMonth[i]
    end
    
    -- Add remaining days of the current month
    totalDays = totalDays + gregorianDay
    
    -- Calculate custom calendar year and month
    local customYear = math.floor(totalDays / (10 * daysPerMonth)) + 4749
    local customMonth = math.floor((totalDays - 1) % daysPerMonth) + 1
    
    local customMonthName = monthNames[customMonth]
    
    return customMonth .. customMonthName .. "\n" .. customYear
end

return CustomCalendar