Lompat ke isi

Modul:Start date and age: Perbedaan antara revisi

Dari Wikisporta, ensiklopedia olahraga
←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 =...'
Tanda: Suntingan perangkat seluler Suntingan peramban seluler
 
Tidak ada ringkasan suntingan
Tanda: Suntingan perangkat seluler Suntingan peramban seluler
 
(6 revisi perantara oleh pengguna yang sama tidak ditampilkan)
Baris 2: Baris 2:


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


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


Baris 31: Baris 31:
         day = tonumber(day)
         day = tonumber(day)
     else
     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)
         year = tonumber(args[1] or args.year)
         month = tonumber(args[2] or args.month)
         month = tonumber(args[2] or args.month)
Baris 39: Baris 38:
     -- Validasi Tanggal
     -- Validasi Tanggal
     if not year or not month or not day or month < 1 or month > 12 or day < 1 or day > 31 then
     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>'
         return '<span style="color:red; font-weight:bold;">[Format Tanggal Salah]</span>'
     end
     end


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


     -- Format Output: "20 Mei 2010 (umur 16 tahun)"
    -- Teks durasi
     return string.format('%d %s %d&#160;<span class="force-break">(umur&#160;%d&#160;tahun)</span>', day, monthName, year, age)
    local durationStr = string.format('%d tahun yang lalu', years)
 
     -- Format Output Rapi:
    -- Baris 1: 29 November 1899
    -- Baris 2: (126 tahun yang lalu) -> Tegak normal, tidak miring, ukuran 80%
     return string.format('%d %s %d<br /><small style="font-size: 80%%;">(%s)</small>', day, monthName, year, durationStr)
end
end


return p
return p

Revisi terkini sejak 17 Oktober 2026 20.53

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

local p = {}

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

-- Fungsi untuk menghitung selisih tahun secara presisi
local function calculateYears(bYear, bMonth, bDay)
    local today = os.date("*t")
    local years = today.year - bYear
    
    if today.month < bMonth or (today.month == bMonth and today.day < bDay) then
        years = years - 1
    end
    
    return years
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
        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 Salah]</span>'
    end

    local years = calculateYears(year, month, day)
    local monthName = monthsName[month] or ""

    -- Teks durasi
    local durationStr = string.format('%d tahun yang lalu', years)

    -- Format Output Rapi:
    -- Baris 1: 29 November 1899
    -- Baris 2: (126 tahun yang lalu) -> Tegak normal, tidak miring, ukuran 80%
    return string.format('%d %s %d<br /><small style="font-size: 80%%;">(%s)</small>', day, monthName, year, durationStr)
end

return p