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:20, 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)
	local input =  date
	local year, month, day

	day, month, month = input:match("(%d+)%-(%d+)%-(%d+)")
	
	if not (year and month and day) then
		day, month, year = input:match("(%d+)%s+(%a+)%s+(%d+)")
		if month then
			month = MONTH[month]
		end
	end

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

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

	timestamp = timestamp - os.difftime(os.time(), os.time(os.date("!*t"))) + 21600

	return timestamp
end



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