Module:Sandbox/R1F4T
Appearance
local p = {}
local function isLeapYear(y)
return ((y - 594) % 4 == 0) -- Simple Bengali leap year rule
end
local function toBengaliNumber(num)
local bnDigits = {'০','১','২','৩','৪','৫','৬','৭','৮','৯'}
return tostring(num):gsub("%d", function(d) return bnDigits[tonumber(d)+1] end)
end
function p.unixToBengaliDate(frame)
local timestamp = tonumber(frame.args[1])
local second = 86400
local days = math.floor(timestamp / second)
local year = 1432 -- Start from 1 Boishakh 1432
while true do
local leap = isLeapYear(year) and 366 or 365
if days < leap then break end
days = days - leap
year = year + 1
end
local isLeap = isLeapYear(year)
local monthLengths = {31,31,31,31,31,31,30,30,30,30,30, isLeap and 30 or 29}
local month = 1
while days >= monthLengths[month] do
days = days - monthLengths[month]
month = month + 1
end
local day = days + 1
return string.format("%s-%s-%s", toBengaliNumber(day), toBengaliNumber(month), toBengaliNumber(year))
end
return p