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
 
(3 intermediate revisions by the same user not shown)
Line 6:
}
 
local function en_timestamp(date)
if not date then
local day, month, year
return os.time() + 21600 -- fallback to current time (UTC+6)
end
 
-- Format: DD Month -MM-YYYY
local day, month, year
day, month, year = date:match("(%d+)%s+-(%ad+)%s+-(%d+)")
 
-- Format: DD-MM- Month YYYY
if not (day, and month, and year) = date:match("(%d+)%-(%d+)%-(%d+)")then
day, month, year = date:match("(%d+)%s+(%a+)%s+(%d+)")
if month then
-- Format: DD Month YYYY
month = month:sub(1,1):upper() .. month:sub(2):lower()
if not (day and month and year) then
month = MONTH[month]
day, month, year = date:match("(%d+)%s+(%a+)%s+(%d+)")
end
if month then
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
}
 
-- 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
 
-- Main function to get BN UNIX timestampp._main(date)
local UNIX, err = en_timestamp(date)
function p.main(date)
if not UNIX then
local UNIX = en_timestamp(date)
return UNIXnil, - 1744610400err
else
return UNIX - 1744610400
end
end
 
function p.main(dateframe)
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