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
 
(14 intermediate revisions by the same user not shown)
Line 1:
local p = {}
 
local MONTH = {
January = 1, February = 2, March = 3, April = 4, May = 5, June = 6,
Line 6 ⟶ 7:
 
local function en_timestamp(date)
if date then
local input = date
local yearday, month, dayyear
 
-- Format: DD-MM-YYYY
day, month, monthyear = inputdate:match("(%d+)%-(%d+)%-(%d+)")
 
if not (year and month and day) then
-- Format: DD Month YYYY
day, month, year = input:match("(%d+)%s+(%a+)%s+(%d+)")
if not (day and month and year) then
day, month, year = inputdate:match("(%d+)%s+(%a+)%s+(%d+)")
month = MONTH[month]
if month then
month = month:sub(1,1):upper() .. month:sub(2):lower()
month = MONTH[month]
end
end
end
 
if not (yearday and month and dayyear) then
return nil, "Invalid date format. Use DD-YYYY-MM-YYYY or DD Month YYYY."
end
 
local timestamp = os.time{
year = tonumber(year),
month = tonumber(month),
day = tonumber(day),
hour = 0
}
 
if not timestamp
-- Add 6 hours to convert to UTC+6 (Bangladesh Time)
then return timestamp =+ os.time21600
else
return os.time() + 21600 -- fallback to current time (UTC+6)
end
end
 
function p._main(date)
timestamp = timestamp - os.difftime(os.time(), os.time(os.date("!*t"))) + 21600
local UNIX, err = en_timestamp(date)
 
if not timestampUNIX then
return timestamp
return BN_UNIXnil, err
else
return UNIX - 1744610400
end
end
 
 
 
function p.main(frame)
local UNIXdate = tonumber(en_timestamp(frame.args[1] or frame:getParent()).args[1]
local BN_UNIXresult, err = UNIX - 1744610400p._main(date)
if result then
return BN_UNIX
return result
else
return err or "Invalid or missing date."
end
end
 
return p