Modul:Start date and age: Perbedaan antara revisi
Tampilan
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 =...' Tanda: Suntingan perangkat seluler Suntingan peramban seluler |
Wikisporta (bicara | kontrib) 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 | 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 | -- Fungsi untuk menghitung selisih tahun secara presisi | ||
local function | local function calculateYears(bYear, bMonth, bDay) | ||
local today = os.date("*t") | local today = os.date("*t") | ||
local | 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 | ||
years = years - 1 | |||
end | end | ||
return | return years | ||
end | end | ||
| Baris 31: | Baris 31: | ||
day = tonumber(day) | day = tonumber(day) | ||
else | else | ||
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 | return '<span style="color:red; font-weight:bold;">[Format Tanggal Salah]</span>' | ||
end | end | ||
local | local years = calculateYears(year, month, day) | ||
local monthName = | local monthName = monthsName[month] or "" | ||
-- Format Output: | -- Teks durasi | ||
return string.format('%d %s %d | 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