Module:Protection banner: Difference between revisions

format date output in the Blurb class
(validate expiry and protection dates)
(format date output in the Blurb class)
Line 183:
url = tostring(url)
return string.format('[%s %s]', url, display)
end
 
function Blurb.formatDate(num)
-- Formats a Unix timestamp into dd M, YYYY format.
local date = os.date('%e %B %Y', num)
date = date:gsub('^ ', '') -- The %e option replaces leading zeroes with spaces, but we don't want spaces.
-- spaces.
date = date:gsub('^ ', '')
return date
end
 
Line 301 ⟶ 310:
local protectionDate = self._protectionStatusObj:getProtectionDate()
if type(protectionDate) == 'number' then
localreturn date = osBlurb.dateformatDate('%e %B %Y', protectionDate)
date = date:gsub('^ ', '') -- The %e option replaces leading zeroes with spaces, but we don't want spaces.
return date
else
return protectionDate
Line 344 ⟶ 351:
-- @TODO: Check to see if the expiry is valid.
local expiry = self._protectionStatusObj:getExpiry()
if expiry == 'indef' then
return ' until ' .. expirynil
elseif type(expiry) == 'number' then
else
local formatted = Blurb.formatDate(expiry)
return ''
return ' until ' .. formatted
elseif expiry then
-- Expiry is an error string.
return ''expiry
end
end