모듈:Dday

S.T.E.L.L.A.-WIKI

이 모듈에 대한 설명문서는 모듈:Dday/설명문서에서 만들 수 있습니다

local p = {}

function p.daycount(frame)
    local startDate = frame.args[1] or "2024-01-01"  -- 기본값으로 시작 날짜 설정

    -- 현재 UTC 시간
    local currentUtcTime = os.time(os.date("!*t"))

    -- 한국 시간으로 변환 (UTC+9)
    local offsetSeconds = 9 * 60 * 60
    local koreanTime = currentUtcTime + offsetSeconds
    local currentKoreanDate = os.date("*t", koreanTime)

    -- 시작 날짜 시간 테이블 생성
    local year, month, day = startDate:match("(%d+)-(%d+)-(%d+)")
    if not year or not month or not day then
        return "Invalid date format. Please use YYYY-MM-DD."
    end
    
    local startTime = os.time({
        year = tonumber(year),
        month = tonumber(month),
        day = tonumber(day),
        hour = 0,
        min = 0,
        sec = 0
    }) - offsetSeconds  -- 한국 시간으로 변환된 것에 대한 보정

    -- 경과 일수 계산
    local diffSeconds = koreanTime - startTime
    local dayCount = math.floor(diffSeconds / (24 * 60 * 60)) + 1  -- 1일째부터 시작하기 위해 +1

    return tostring(dayCount)
end

return p