Module:Bengali Unix Timestamp: Difference between revisions

Content deleted Content added
No edit summary
Tags: Mobile edit Mobile web edit Advanced mobile edit
No edit summary
Tags: Mobile edit Mobile web edit Advanced mobile edit
 
(32 intermediate revisions by the same user not shown)
Line 1:
local p = {}
 
local UNIX = os.time() + 21600
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 date then
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: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 UNIXtimestamp = os.time() + 21600{
year = tonumber(year),
month = tonumber(month),
day = tonumber(day),
hour = 0
}
 
-- Add 6 hours to convert to UTC+6 (Bangladesh Time)
return timestamp + 21600
else
return os.time() + 21600 -- fallback to current time (UTC+6)
end
end
 
function p._main(date)
local UNIX, err = en_timestamp(date)
if not UNIX then
return BN_UNIXnil, err
else
return UNIX - 1744610400
end
end
 
function p.main(frame)
local BN_UNIXdate = UNIXframe.args[1] -or 1744643600frame:getParent().args[1]
local result, err = p._main(date)
return BN_UNIX
if result then
return result
else
return err or "Invalid or missing date."
end
end
 
return p