Module:AdDéc : Différence entre versions
(+needed by attribution in https://creativecommons.org/licenses/by-sa/3.0/) |
m (1 révision importée) |
(Aucune différence)
| |
Version actuelle datée du 8 février 2019 à 10:40
--[[
- Module permettant le parsing d'un point d'ascension droite ou de déclinaison
- Imported from https://it.wikipedia.org/w/index.php?title=Modulo:RaDec&oldid=83380991
]]--
require('Module:No globals')
local getArgs = require('Module:Arguments').getArgs local p = {}
-- Funzione di utilità per altri moduli: -- parsifica il testo generato dal Template:RA (ascensione retta) e -- restituisce una table con chiavi 'h', 'm' e 's' di tipo number. function p.parseRA(text) local h, m, s
text = mw.text.trim(mw.text.unstrip(text)):gsub('−', '-'):gsub(',', '.') h, m, s = text:match('^(%d+)h (%d+)m ([%d%.]+)s$') if not h then h, m = text:match('^(%d+)h (%d+)m :$') s = 0 end if not h then h = text:match('^(%d+)h :$') m, s = 0, 0 end
h, m, s = tonumber(h), tonumber(m), tonumber(s)
return (h and m and s) and { h = h, m = m, s = s } or nil end
-- Funzione di utilità per altri moduli: -- parsifica il testo generato dal Template:DEC (declinazione) e -- restituisce una table con chiavi 'd', 'm' e 's' di tipo number. function p.parseDEC(text) local d, m, s
text = mw.text.trim(mw.text.unstrip(text)):gsub('−', '-'):gsub(',', '.') d, m, s = text:match('^([+-]?%d+)° (%d+)′ ([%d%.]+)″$') if not d then d, m = text:match('^([+-]?%d+)° (%d+)′ :$') s = 0 end if not d then d = text:match('^([+-]?%d+)° :$') m, s = 0, 0 end
d, m, s = tonumber(d), tonumber(m), tonumber(s)
return (d and m and s) and { d = d, m = m, s = s } or nil end
-- Entry-point per il template Modèle:RA function p.RA(frame) local args = getArgs(frame, { parentOnly = true }) local h, m, s = args[1] and (args[1] .. 'h ') or , args[2] or ':', args[3] or ':' m = m .. (m == ':' and or 'm ') s = s .. (s == ':' and or 's') return h .. m .. (m == ':' and or s) end
-- Entry-point per il template Modèle:DEC function p.DEC(frame) local args = getArgs(frame, { parentOnly = true }) local d, m, s = args[1] and (args[1] .. '° ') or , args[2] or ':', args[3] or ':' m = m .. (m == ':' and or '′ ') s = s .. (s == ':' and or '″') return d .. m .. (m == ':' and or s) end
return p