Module:BENGALIDATE and Module:BENGALIDATE/sandbox: Difference between pages
(Difference between pages)
imported>R1F4T No edit summary |
imported>R1F4T No edit summary |
||
| Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
local data = mw.loadData('Module:BENGALIDATE/data') | |||
local lang = mw.language.getContentLanguage() | |||
local getArgs = require('Module:Arguments').getArgs | local getArgs = require('Module:Arguments').getArgs | ||
local | |||
local function | local now = os.time() | ||
return ((year | local cTime = now + (6 * 60 * 60) | ||
local currentDate = os.date("%d %B %Y", cTime)local cday = tonumber(os.date("%d", cTime)) | |||
local cmonth = tonumber(os.date("%m", cTime)) | |||
local function uc(value) | |||
return lang:ucfirst(value) | |||
end | |||
local function dmy(i) | |||
local date = i | |||
local day, month, year = date:match("(%d%d?) (%a+) (%d%d%d%d)") | |||
return tonumber(day), month , year | |||
end | end | ||
-- BN month | |||
local function getBNmonth (day, month) | |||
local day = tonumber(day) | |||
local bnMonth = { | |||
January = {15, "Magh", "Poush"}, | |||
February = {14, "Falgun", "Magh"}, | |||
March = {15, "Chaitra", "Falgun"}, | |||
April = {14, "Boishakh", "Chaitra"}, | |||
May = {15, "Joishtho", "Boishakh"}, | |||
June = {15, "Asharh", "Joishtho"}, | |||
July = {15, "Shrabon", "Asharh"}, | |||
August = {15, "Bhadro", "Shrabon"}, | |||
September = {15, "Ashwin", "Bhadro"}, | |||
October = {15, "Kartik", "Ashwin"}, | |||
November = {15, "Agrahayan", "Kartik"}, | |||
December = {15, "Poush", "Agrahayan"} | |||
} | |||
local dateLimit, bnMafter, bnMbefore = unpack(bnMonth[month]) | |||
if day >= dateLimit then | |||
return bnMafter | |||
else | |||
return bnMbefore | |||
end | |||
end | |||
-- BN Year | |||
local function getBNyear(day, month, year) | |||
local bn_year | |||
local cmonth = tonumber(month) | |||
local cday = tonumber(day) | |||
local aprilfourteen = cmonth*20+cday > 93 | |||
if aprilfourteen then | |||
bn_year = tonumber(year) - 593 | |||
else | |||
bn_year = tonumber(year) - 594 | |||
end | |||
return bn_year | |||
end | |||
-- BN day | |||
local function getBNday(day, month, year) | |||
local bn_year = getBNyear(day, lang:ucfirst(month), year) -- Call the year function here | |||
local day = tostring(day) | |||
local bn_day = data[month][day] | |||
local leapYear = tonumber(year) % 4 == 0 and (tonumber(year) % 100 ~= 0 or tonumber(year) % 400 == 0) | |||
if leapYear and uc(month) == "March" and day >= 1 and day <= 14 then | |||
bn_day = bn_day + 1 | |||
return bn_day | |||
end | |||
return bn_day | |||
end | |||
-- formatter | |||
local function format_date(day, month, year, format) | local function format_date(day, month, year, format) | ||
local components = { d = day, m = month, y = year } | local components = { d = day, m = month, y = year } | ||
| Line 20: | Line 85: | ||
return table.concat(result) | return table.concat(result) | ||
end | end | ||
-- Main Function | |||
function p.main(frame) | function p.main(frame) | ||
local args = getArgs(frame) | local args = getArgs(frame) | ||
local | local format = args[2] or args['format'] or 'm d y' | ||
if format == '' then | |||
format = 'm d y' | |||
end | |||
local input = args[1] or currentDate | |||
local gday, gmonth, gyear = dmy(input) | |||
if not gday then | |||
gday, gmonth, gyear = dmy(currentDate) | |||
format = args[1] | |||
if format == '' then format = 'm d y' | |||
end | |||
if | |||
end | end | ||
local byear = getBNyear(gday,gmonth,gyear) | |||
local bmonth = getBNmonth(gday, gmonth) | |||
local | local bday = getBNday(gday,gmonth,gyear) | ||
local | |||
local dmy = format_date(bday,bmonth,byear,format) | |||
return dmy | |||
local | |||
end | end | ||
return p | return p | ||