Module:Time/sandbox: Difference between revisions

Content deleted Content added
No edit summary
Looks good
Line 262:
end
 
 
--[[
local function get_full_utc_offset (utc_offset, format) -- for below [] = required, () = not required
local minoff;
local houroff;
local sign;
local no_sign;
local minzero;
local hourzero;
if mw.ustring.match (utc_offset, 'u?t?c?[%+%-±−]?%d+%.%d+') == utc_offset then -- if rendering for a utc offset with (utc)(sign)(number)[number][.](number)[number]
houroff = mw.ustring.match (utc_offset, '%d+')
no_sign = mw.ustring.match (utc_offset, '%d+%.%d+')
minoff = ((no_sign*100)-(houroff*100))*0.6
sign = mw.ustring.match (utc_offset,'[%+%-±−]?')
if is_set(sign) == false then
sign = '+'
end
local hourplus = table.concat ({'n',houroff})
local hournum = {n9 = true,n8 = true,n7 = true,n6 = true,
n5 = true,n4 = true,n3 = true,n2 = true,n1 = true,n0 = true}
if true == hournum[hourplus] then
hourzero = '0'
else
hourzero = ''
end
if tonumber(minoff) < 10 then
minzero = '0'
else
minzero = ''
end
utc_offset = table.concat ({'utc',sign,hourzero,houroff,':',minzero,minoff})
if is_set(format) == false then
format = 'dmy'
end
elseif mw.ustring.match (utc_offset, 'u?t?c?[%+%-±−]?%d+.?:?') == utc_offset then -- if rendering for a utc offset with (utc)(sign)(number)[number](.or:)
sign = mw.ustring.match (utc_offset, '[%+%-±−]?')
utc_offset = mw.ustring.match (utc_offset, '%d+')
if is_set(sign) == false then
sign = '+'
end
if utc_offset == mw.ustring.match (utc_offset, '%d') then
utc_offset = table.concat ({'utc',sign,0,utc_offset,':00'})
else
utc_offset = table.concat ({'utc',sign,utc_offset,':00'})
end
if is_set(format) == false then
format = 'dmy'
end
elseif mw.ustring.match (utc_offset,'u?t?c?[%+%-±−]?%d+:%d%d') == utc_offset then -- if rendering for a utc offset with (utc)(sign)(number)[number][:][number][number]
sign = mw.ustring.match (utc_offset, '[%+%-±−]?')
utc_offset = mw.ustring.match (utc_offset, '%d+:%d%d')
if is_set(sign) == false then
sign = '+'
end
if utc_offset == mw.ustring.match (utc_offset, '%d:%d%d') then
utc_offset = table.concat ({'utc',sign,0,utc_offset})
else
utc_offset = table.concat ({'utc',sign,utc_offset})
end
if is_set(format) == false then
format = 'dmy'
end
end
return utc_offset, format
end
]]
--[=[-------------------------< T I M E >----------------------------------------------------------------------
 
Line 380 ⟶ 311:
args[1] = 'utc'; -- default to utc
end
-- args[1], args[2] = get_full_utc_offset (args[1],args[2]) -- call get_full_utc_offset to convert a improper utc offset to a proprt utc offset
-- if mw.ustring.match (args[1], '±') and not mw.ustring.match (args[1], '0:') then
-- return '<span style="font-size:100%" class="error">{{time}} – invalid usage of ± ([[Template:Time#Error messages|help]])</span>';
-- end
-- if mw.ustring.match (args[1], '%.%d+') then
-- return '<span style="font-size:100%" class="error">{{time}} – input produces invalid minute offset ([[Template:Time#Error messages|help]])</span>';
-- end
 
if mw.ustring.match (args[1], 'utc[%+%-±−]%d%d:%d%d') then -- if rendering time for a UTC offset timezone