Modulo:RaDec: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
Nuovo modulo
 
m modulo no globals obsoleto
 
(5 versioni intermedie di 2 utenti non mostrate)
Riga 4:
]]--
 
require('Modulo:No globalsstrict')
 
local getArgs = require('Modulo:Arguments').getArgs
Riga 33:
-- Funzione di utilità per altri moduli:
-- parsifica il testo generato dal Template:DEC (declinazione) e
-- restituisce una table con chiavi 'sign', 'd', 'm' e 's' di tipo number.
function p.parseDEC(text)
local sign, d, m, s
 
text = mw.text.trim(mw.text.unstrip(text)):gsub('+', '+'):gsub('-', '-'):gsub('−', '-'):gsub(',', '.')
d, m, s = text:match('^([+-]?%d+)° (%d+)′ ([%d%.]+)″$')
if not d then
Riga 49:
 
d, m, s = tonumber(d), tonumber(m), tonumber(s)
if d then
sign = (d < 0 or tostring(d) == '-0') and -1 or 1
d = math.abs(d)
end
 
return (sign and d and m and s) and { sign = sign, d = d, m = m, s = s } or nil
end
 
Line 58 ⟶ 62:
local h, m, s = args[1] and (args[1] .. '<sup>h</sup>&nbsp;') or '', args[2] or ':', args[3] or ':'
m = m .. (m == ':' and '' or '<sup>m</sup>&nbsp;')
s = s .. (s == ':' and '' or '<sup>s</sup>&nbsp;')
return h .. m .. (m == ':' and '' or s)
end
Line 66 ⟶ 70:
local args = getArgs(frame, { parentOnly = true })
local d, m, s = args[1] and (args[1] .. '&deg;&nbsp;') or '', args[2] or ':', args[3] or ':'
d = mw.text.encode(d, '+-')
m = m .. (m == ':' and '' or '&prime;&nbsp;')
s = s .. (s == ':' and '' or '&Prime;&nbsp;')
return d .. m .. (m == ':' and '' or s)
end