g_CurrentTime = os.time()
local TIME_MIN = 60
local TIME_HOUR = TIME_MIN * 60
local TIME_DAY = TIME_HOUR * 24
local TIME_WEEK = TIME_DAY * 7
--!< 시간 확인
function GetTargetDay(tmTime, standHour, standMinute)
return os.date("%Y%m%d", tmTime - (standHour * TIME_HOUR) - (standMinute * TIME_MIN))
end
--!< 경과 일
function BetweenDay(baseTime, targetTime)
local outputDay = math.floor((targetTime - baseTime) / TIME_DAY)
return outputDay
end
--!< 날짜 변환 (yyyymmdd)
function ConvertTime(targetDate)
local targetValue = targetDate
local targetYear = math.floor(targetValue / (100 * 100))
targetValue = math.floor(targetValue % (100 * 100))
local targetMonth = math.floor(targetValue / 100)
targetValue = math.floor(targetValue % 100)
local targetDay = targetValue
local targetTime = os.time{
year = targetYear,
month = targetMonth,
day = targetDay,
hour = 0,
min = 0,
sec = 0,
}
return tonumber(targetTime)
end
--!< 매주 초기화 시간 계산 -다음 종료 시간
function GetNextWeekTime(nTargetDay)
local targetTime = ConvertTime(nTargetDay) --!< YYYYMMDD -> time (EX : 20250626 -> 1750863600)
local currentWeek = tonumber(os.date("%w", targetTime)) --!< 0:일, ~ 6:토
local everyWeek = 2 --!< 매주 초기화 대상 요일
local MaxWeek = 6 + 1
--!< 다음 초기화 날짜 계산
local addDay = 0
if (currentWeek > everyWeek) then --!< 현재가 요일보다 초과 시
addDay = MaxWeek - currentWeek + everyWeek
elseif (currentWeek < everyWeek) then --!< 현재가 요일보다 미만 시
addDay = everyWeek - currentWeek
else
addDay = MaxWeek --!< 동일하면 일주일 가산 +7
end
return targetTime + (addDay * TIME_DAY)
end
--!< Main ...
--!< YYYYMMDD (EX : 20250626)
local strTargetDay = GetTargetDay(g_CurrTime, 6, 0)
local nTargetDay = tonumber(strTargetDay)
--!< 매주 초기화 시간 계산
local nextTime = GetNextTime(nTargetDay)
local nextDate = tonumber(os.date("%Y%m%d", nextTime))
--!< 경과 일일 계산 (현재일 - 시작일)
local nStartTime = ConvertTime(20250530)
local nPassDay = BetweenDay(nStartTime, ConvertTime(nTargetDay))
'[ Programing ] > Lua Scirpt' 카테고리의 다른 글
[Lua] os date / os time (0) | 2025.06.26 |
---|---|
[Lua] 문자 합치기. (0) | 2024.07.10 |
[LUA] Bit Flag (0) | 2023.05.02 |
[Lua] Bit Flag (0) | 2023.02.28 |
[Lua] os Time (0) | 2023.02.28 |