Modulo:RaDec: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
m Ha protetto "Modulo:RaDec": Template o modulo usato in maniera estensiva ([Modifica=Consentito solo agli amministratori] (infinito) [Spostamento=Consentito solo agli amministratori] (infinito))
m modulo no globals obsoleto
 
(3 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 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;')