Jump to content

Module:Bengali Unix Timestamp

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by R1F4T (talk | contribs) at 08:40, 23 April 2025. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local p = {}
local MONTH = {
	January = 1, February = 2, March = 3, April = 4, May = 5, June = 6,
	July = 7, August = 8, September = 9, October = 10, November = 11, December = 12
}

local function en_timestamp(date)
	if not date then
		return os.time() + 21600 -- fallback to current time (UTC+6)
	end

	local day, month, year

	-- Format: DD-MM-YYYY
	day, month, year = date:match("(%d+)%-(%d+)%-(%d+)")
	
	-- Format: DD Month YYYY
	if not (day and month and year) then
		day, month, year = date:match("(%d+)%s+(%a+)%s+(%d+)")
		if month then
			month = MONTH[month]
		end
	end

	if not (day and month and year) then
		return "Invalid date format. Use DD-MM-YYYY or DD Month YYYY."
	end

	local timestamp = os.time{
		year = tonumber(year),
		month = tonumber(month),
		day = tonumber(day),
		hour = 0
	}

	-- Add 6 hours to convert to UTC+6 (Bangladesh Time)
	return timestamp + 21600
end

function p.main(frame)
	local UNIX = tonumber(en_timestamp(frame.args[1]))
	local BN_UNIX = UNIX - 1744610400
	return BN_UNIX
end

return p