Lompat ke isi

Modul:Start date and age

Dari Wikisporta, ensiklopedia olahraga
Revisi sejak 17 Oktober 2026 20.32 oleh Wikisporta (bicara | kontrib) (←Membuat halaman berisi 'local p = {} -- Nama bulan dalam bahasa Indonesia local months = { "Januari", "Februari", "Maret", "April", "Mei", "Juni", "Juli", "Agustus", "September", "Oktober", "November", "Desember" } -- Fungsi untuk menghitung umur / durasi berjalan local function calculateAge(bYear, bMonth, bDay) local today = os.date("*t") local age = today.year - bYear if today.month < bMonth or (today.month == bMonth and today.day < bDay) then age =...')
(beda) ← Revisi sebelumnya | Revisi terkini (beda) | Revisi selanjutnya → (beda)

Dokumentasi untuk modul ini dapat dibuat di Modul:Start date and age/doc

local p = {}

-- Nama bulan dalam bahasa Indonesia
local months = {
    "Januari", "Februari", "Maret", "April", "Mei", "Juni",
    "Juli", "Agustus", "September", "Oktober", "November", "Desember"
}

-- Fungsi untuk menghitung umur / durasi berjalan
local function calculateAge(bYear, bMonth, bDay)
    local today = os.date("*t")
    local age = today.year - bYear
    
    if today.month < bMonth or (today.month == bMonth and today.day < bDay) then
        age = age - 1
    end
    
    return age
end

function p.main(frame)
    local args = frame:getParent().args
    local year, month, day

    -- Cek jika input menggunakan format YYYY-MM-DD atau YYYY/MM/DD
    local inputStr = args[1] or ""
    if inputStr:find("^%d%d%d%d%-%d%d%-%d%d$") or inputStr:find("^%d%d%d%d/%d%d/%d%d$") then
        year, month, day = inputStr:match("(%d%d%d%d)[%-/](%d%d)[%-/](%d%d)")
        year = tonumber(year)
        month = tonumber(month)
        day = tonumber(day)
    else
        -- Jika menggunakan parameter terpisah: {{Start date and age|2010|5|20}} atau {{Start date and age|year=2010|month=5|day=20}}
        year = tonumber(args[1] or args.year)
        month = tonumber(args[2] or args.month)
        day = tonumber(args[3] or args.day)
    end

    -- Validasi Tanggal
    if not year or not month or not day or month < 1 or month > 12 or day < 1 or day > 31 then
        return '<span style="color:red; font-weight:bold;">[Format Tanggal Mulai Salah]</span>'
    end

    local age = calculateAge(year, month, day)
    local monthName = months[month] or ""

    -- Format Output: "20 Mei 2010 (umur 16 tahun)"
    return string.format('%d %s %d&#160;<span class="force-break">(umur&#160;%d&#160;tahun)</span>', day, monthName, year, age)
end

return p