Bước tới nội dung

Mô đun:Countdown

Bách khoa toàn thư mở Wikipedia
-- Mô đun này quyền hạn {{countdown}}.local p = {}-- Constantslocal lang = mw.language.getContentLanguage()local getArgs = require('Mô đun:Arguments').getArgsfunction formatMessage(secondsLeft, event, color, refreshLink)    local timeLeft = lang:formatDuration(secondsLeft, {'years', 'weeks', 'days', 'hours', 'minutes', 'seconds'})    -- Color and bold the numbers, makes them look important.    local timeLeft = mw.ustring.gsub(timeLeft, '(%d+)', '<span style="color: ' .. (color or '#F00') .. '; font-weight: bold;">%1</span>')    -- Make the refresh link and join it all together.    return mw.ustring.format('Còn %s cho đến khi %s.%s', timeLeft, event, refreshLink)endfunction p.main(frame)    local args = getArgs(frame)    if not (args.year and args.month and args.day) then        return  '<strong class="error">Lỗi: năm, tháng, và ngày phải được quy định</strong>'    end    local eventTime = os.time{year=args.year, month=args.month, day=args.day, hour=args.hour, min=args.minute, sec=args.second}    local timeToStart = os.difftime(eventTime, os.time()) -- (future time - current time)    local refreshLink = mw.title.getCurrentTitle():fullUrl{action = 'purge'}    refreshLink = mw.ustring.format(' <small><span class="plainlinks">([%s làm mới])</span></small>', refreshLink)    if timeToStart > 0 then        -- Event has not begun yet        return formatMessage(timeToStart, args.event or 'sự kiện bắt đầu', args.color, refreshLink)    elseif args.duration then        local timeToEnd        if args['duration unit'] then            -- Duration is in unit other than seconds, use formatDate to add            timeToEnd = tonumber(lang:formatDate('U', '@' .. tostring(timeToStart) .. ' +' .. tostring(args.duration) .. ' ' .. args['duration unit']))        else            timeToEnd = timeToStart + tonumber(args.duration)        end        if timeToEnd > 0 then            -- Event is in progress            return args.eventstart .. refreshLink or formatMessage(timeToEnd, (args.event or 'sự kiện') .. ' kết thúc', args.color, refreshLink)        else            -- Event had a duration and has now ended            return ((args.eventend or ((lang:ucfirst(args.event) or 'The event') .. ' đã kết thúc.')) .. refreshLink)        end    else        -- Event had no duration and has begun        return ((args.eventstart or ((lang:ucfirst(args.event) or 'The event') .. '.')) .. refreshLink)    endendreturn p