Edge Rewrite
// HTMLRewriter · presentation

This page was redesigned at the edge.

Cloudflare fetched the original article and streamed it through HTMLRewriter to apply an entirely new visual system without rebuilding the source page.

// request.cf · coarse context

A page that knows where it met you.

Only coarse request metadata is shown. This demo does not display or persist visitor IP addresses.

Country
US
Cloudflare location
CMH
Connection
HTTP/2
Language
Not provided

Ray ID: a23d7dc67e1821ca

Jump to content

Module:Bengali Calendar Epoch Offset

From Wikipedia, the free encyclopedia

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
}

p.EPOCH = 1744610400  -- Unix time of 1 Boisakh 1432, midnight UTC+6

local function en_timestamp(date)
	if date then
		local day, month, year
		day, month, year = date:match("(%d+)%-(%d+)%-(%d+)")
		if not (day and month and year) then
			day, month, year = date:match("(%d+)%s+(%a+)%s+(%d+)")
			if month then
				month = month:sub(1,1):upper() .. month:sub(2):lower()
				month = MONTH[month]
			end
		end
		if not (day and month and year) then
			return nil, "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
		}
		return timestamp + 21600
	else
		return os.time() + 21600
	end
end

function p._main(date)
	local UNIX, err = en_timestamp(date)
	if not UNIX then
		return nil, err
	end
	return UNIX - p.EPOCH
end

function p.main(frame)
	local date = frame.args[1] or frame:getParent().args[1]
	local result, err = p._main(date)
	if result then
		return result
	else
		return err or "Invalid or missing date."
	end
end

return p