Modifications

Sauter à la navigation Sauter à la recherche

Module:AdDéc

2 331 octets ajoutés, 15 décembre 2017 à 15:06
+needed by attribution in https://creativecommons.org/licenses/by-sa/3.0/
--[[
* 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+)<sup>h</sup>&nbsp;(%d+)<sup>m</sup>&nbsp;([%d%.]+)<sup>s</sup>$')
if not h then
h, m = text:match('^(%d+)<sup>h</sup>&nbsp;(%d+)<sup>m</sup>&nbsp;:$')
s = 0
end
if not h then
h = text:match('^(%d+)<sup>h</sup>&nbsp;:$')
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+)&deg;&nbsp;(%d+)&prime;&nbsp;([%d%.]+)&Prime;$')
if not d then
d, m = text:match('^([+-]?%d+)&deg;&nbsp;(%d+)&prime;&nbsp;:$')
s = 0
end
if not d then
d = text:match('^([+-]?%d+)&deg;&nbsp;:$')
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 {{RA}}
function p.RA(frame)
local args = getArgs(frame, { parentOnly = true })
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>')
return h .. m .. (m == ':' and '' or s)
end

-- Entry-point per il template {{DEC}}
function p.DEC(frame)
local args = getArgs(frame, { parentOnly = true })
local d, m, s = args[1] and (args[1] .. '&deg;&nbsp;') or '', args[2] or ':', args[3] or ':'
m = m .. (m == ':' and '' or '&prime;&nbsp;')
s = s .. (s == ':' and '' or '&Prime;')
return d .. m .. (m == ':' and '' or s)
end

return p
Utilisateur anonyme

Menu de navigation