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: | 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 | ||
return Blurb.formatDate(protectionDate) | |||
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 | |||
return | local formatted = Blurb.formatDate(expiry) | ||
return ' until ' .. formatted | |||
elseif expiry then | |||
-- Expiry is an error string. | |||
return expiry | |||
end | end | ||
end | end |