Module:SBI date

-- (don't remove this; it prevents this module --     from being categorized unintentionally into --      wrong categories)

-- formats dates measured from the time of the steel bar incident

-- for month formatting local monthname = require("module:month name");

local m = {};

-- formats a date -- excepts numbers function m.format(day, month, year, with_link) local yearformat = ""; if year then yearformat = math.abs(year) .. " "            .. (with_link and "" or "")             .. (year < 0 and "BSBI" or "ASBI")             .. (with_link and "" or ""); end local daymonthformat = ""; if month then daymonthformat = monthname.getmonth(month); if day then daymonthformat = daymonthformat .. " " .. day .. ", ";       else daymonthformat = daymonthformat .. " ";       end elseif day then daymonthformat = "? " .. day .. ", ";   end return daymonthformat .. yearformat; end

-- tests if the value is nil, false or "" local function isempty(x) return not x or x == ""; end

local function num_value(x) if isempty(x) then return nil; end local val = tonumber(x); return val, val == nil; end

function m.format_template(frame) local args = frame.args; local year, err1 = num_value(args[1]); local month, err2 = num_value(args[2]); local day, err3 = num_value(args[3]); local put_link = args[4] ~= "no" and args[4] ~= "false"; if err1 or err2 or err3 then return ' Date error '; end return m.format(day, month, year, put_link); end

return m;