Module:Navbox timeline: Difference between revisions
AZMindroma (talk | contribs) No edit summary Tag: Reverted |
AZMindroma (talk | contribs) No edit summary Tag: Reverted |
||
| Line 5: | Line 5: | ||
local getArgs = require('Module:Arguments').getArgs | local getArgs = require('Module:Arguments').getArgs | ||
local p = {} | local p = {} | ||
-- Round a number to the nearest integer | |||
local function round(num) | |||
return math.floor(num + 0.5) | |||
end | |||
-- Convert date string to fractional year for timeline positioning | -- Convert date string to fractional year for timeline positioning | ||
| Line 41: | Line 46: | ||
while date < current do | while date < current do | ||
local dur = math.min(1/12, current - date) -- 1 month duration in fractional years | local dur = math.min(1/12, current - date) -- 1 month duration in fractional years | ||
local colspanMonths = math.max(1, | local colspanMonths = math.max(1, round(dur * 12)) | ||
row:tag('td') | row:tag('td') | ||
| Line 55: | Line 60: | ||
:addClass('timeline-blank') | :addClass('timeline-blank') | ||
:cssText(args.blankstyle) | :cssText(args.blankstyle) | ||
:attr('colspan', math.max(1, | :attr('colspan', math.max(1, round(yearDiff))) | ||
end | end | ||
else | else | ||
| Line 327: | Line 332: | ||
if yesno(args.decades) == false and yesno(args.months) ~= false then | if yesno(args.decades) == false and yesno(args.months) ~= false then | ||
-- Adjust for months | -- Adjust for months | ||
adjustment = | adjustment = round(adjustment * 12) | ||
else | else | ||
adjustment = | adjustment = round(adjustment) | ||
end | end | ||
| Line 345: | Line 350: | ||
if yesno(args.decades) == false and yesno(args.months) ~= false then | if yesno(args.decades) == false and yesno(args.months) ~= false then | ||
-- Each month is one column | -- Each month is one column | ||
colspan = math.max(1, | colspan = math.max(1, round(colspan * 12)) | ||
else | else | ||
colspan = math.max(1, | colspan = math.max(1, round(colspan)) | ||
end | end | ||