判断是否在活动时间内

 GetDayTimeInfo参考这边:获取今日时间信息:零点时间戳,已过秒数等

function GetStatus(startWeeks, endWeeks, startDaySec, endDaySec)
    local zeroTimestamp, dayElapseTime, wday = GetZeroTimeStamp()
    for i=1,#startWeeks do
        local startWday = startWeeks[i]
        if wday == startWday then
            local startLeftTime = startDaySec - dayElapseTime
            if startLeftTime > 0 then
                return "not_started", startLeftTime --今天还未开始
            end
        end

        local endWday = endWeeks[i]
        if wday == endWday then
            local endLeftTime = endDaySec - dayElapseTime
            if endLeftTime > 0 then
                return "ing", endLeftTime
            end
            return "ended", 0 --今天已结束
        end

        if wday >= startWday and wday < endWday then
            local deltaDays = endWday - wday
            local endLeftTime = (24 * 3600 - dayElapseTime) + (deltaDays - 1) * 24 * 3600 + endDaySec
            return "ing", endLeftTime
        end
    end

    return "not_in_time", 0 --不在时间范围
end

 

posted @ 2024-08-18 22:51  yanghui01  阅读(9)  评论(0编辑  收藏  举报