Module:Protection banner: Difference between revisions

Content added Content deleted
Enwikipedia>Mr. Stradivarius
(validate expiry and protection dates)
Enwikipedia>Mr. Stradivarius
(format date output in the Blurb class)
Line 183: Line 183:
url = tostring(url)
url = tostring(url)
return string.format('[%s %s]', url, display)
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)
-- The %e option replaces leading zeroes with spaces, but we don't want
-- spaces.
date = date:gsub('^ ', '')
return date
end
end


Line 301: Line 310:
local protectionDate = self._protectionStatusObj:getProtectionDate()
local protectionDate = self._protectionStatusObj:getProtectionDate()
if type(protectionDate) == 'number' then
if type(protectionDate) == 'number' then
local date = os.date('%e %B %Y', protectionDate)
return Blurb.formatDate(protectionDate)
date = date:gsub('^ ', '') -- The %e option replaces leading zeroes with spaces, but we don't want spaces.
return date
else
else
return protectionDate
return protectionDate
Line 344: Line 351:
-- @TODO: Check to see if the expiry is valid.
-- @TODO: Check to see if the expiry is valid.
local expiry = self._protectionStatusObj:getExpiry()
local expiry = self._protectionStatusObj:getExpiry()
if expiry then
if expiry == 'indef' then
return ' until ' .. expiry
return nil
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
end
end