Module:Sandbox/R1F4T
Appearance
This module may meet Wikipedia's criteria for speedy deletion because: No need of this module anymore. For valid criteria, see CSD.
If this module does not meet the criteria for speedy deletion, or you intend to fix it, please remove this notice, but do not remove this notice from pages that you have created yourself. If you created this page and you disagree with the given reason for deletion, you can click the button below and leave a message explaining why you believe it should not be deleted. You can also visit the talk page to check if you have received a response to your message. Note that this module may be deleted at any time if it unquestionably meets the speedy deletion criteria, or if an explanation posted to the talk page is found to be insufficient. Note to page author: you have not edited the talk page yet. If you wish to contest this speedy deletion, clicking the button above will allow you to leave a talk page message explaining why you think this module should not be deleted. If you have already posted to the talk page but this message is still showing up, try purging the page cache. This page was last edited by R1F4T (contribs | logs) at 04:38, 28 April 2025 (UTC) (14 days ago) |
require('Module:Module wikitext')._addText([[{{db-reason|1=No need of this module anymore|help=off}}]]);
local p = {}
local getArgs = require('Module:Arguments').getArgs
local timestamp = require('Module:Bengali Unix Timestamp')._main
-- Return true if Bengali year is leap
local function isLeapYear(year)
return ((year - 594) % 4 == 0)
end
local function format_date(day, month, year, format)
local components = { d = day, m = month, y = year }
local result = {}
for i = 1, #format do
local char = format:sub(i, i)
if components[char] then
table.insert(result, components[char])
else
table.insert(result, char)
end
end
return table.concat(result)
end
local BN_MONTH = {
[1] = "Boisakh",
[2] = "Joishtho",
[3] = "Ashar",
[4] = "Shrabon",
[5] = "Bhadro",
[6] = "Ashshin",
[7] = "Kartik",
[8] = "Ogrohayon",
[9] = "Poush",
[10] = "Magh",
[11] = "Falgun",
[12] = "Chaitro"
}
function p.main(frame)
local args = getArgs(frame)
local ts = args[1] or tostring(timestamp())
local format = "m d, y"
local isdate = ts:match("^%d+%-%d+%-%d+$") or ts:match("^%d+%s+%a+%s+%d+$")
if isdate then
ts =tonumber(timestamp(ts))
else
ts = tonumber(timestamp(args[2]))
format = args[1] or "m d, y"
end
local second = 86400
local days = math.floor(ts / second)
local year = 1432 -- Adjust according to your epoch
if days >= 0 then
while true do
local leap = isLeapYear(year) and 366 or 365
if days < leap then break end
days = days - leap
year = year + 1
end
else
while true do
local leap = isLeapYear(year - 1) and 366 or 365
if -days <= leap then
year = year - 1
days = days + leap
break
end
days = days + leap
year = year - 1
end
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
month = BN_MONTH[month]
local day = days + 1
return format_date(day, month, year, format)
end
return p