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
 
(9 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
 
if date then
-- Format: DD-MM-YYYY
day, month, monthyear = inputdate:match("(%d+)%-(%d+)%-(%d+)")
end
 
if date then
-- Format: DD Month YYYY
if not (year and month and day) then
if not (day, and month, and year) = input:match("(%d+)%s+(%a+)%s+(%d+)")then
day, month, year = date:match("(%d+)%s+(%a+)%s+(%d+)")
if month then
if month = MONTH[month]then
month = month:sub(1,1):upper() .. month:sub(2):lower()
month = tonumber(MONTH[month),]
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),
day month = tonumber(daymonth),
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
if not (year and month and day) then
return "Invalid date format. Use DD-YYYY-MM or DD Month YYYY."
end
 
function p._main(date)
local timestamp = os.time{
local UNIX, err = en_timestamp(date)
year = tonumber(year),
if not UNIX then
month = tonumber(month),
return UNIXnil, err
day = tonumber(day),
else
hour = 0
return UNIX - 1744610400
}
if not timestamp
then timestamp = os.time()
end
 
timestamp = timestamp - os.difftime(os.time(), os.time(os.date("!*t"))) + 21600
 
return timestamp
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 monthresult then
return UNIX
return result
else
return err or "Invalid or missing date."
end
end
 
return p