Module:Sandbox/Hellknowz/Test

This is an old revision of this page, as edited by Hellknowz (talk | contribs) at 13:08, 27 August 2013 (so zero based now?). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
local main = {};

local monthIndices = {
    ['january'] = 1,
    ['february'] = 2,
    ['march'] = 3,
    ['april'] = 4,
    ['may'] = 5,
    ['june'] = 6,
    ['july'] = 7,
    ['august'] = 8,
    ['september'] = 9,
    ['october'] = 10,
    ['november'] = 11,
    ['december'] = 12
}

function main.hello(frame)

    --[[
    local args = frame.args
    local arg1 = args[1]
    local arg2 = args[2]
    local arg3 = args[3]
    local argNamed = args['named']

    local s = 'Params: '
    if (arg1 ~= nil) then s = s .. '1 = ' .. arg1 end
    if (arg2 ~= nil) then s = s .. '; 2 = ' .. arg2 end
    if (arg3 ~= nil) then s = s .. '; 3 = ' .. arg3 end
    if (argNamed~= nil) then s = s .. '; named = ' .. argNamed end
    return s
    ]]

    local args = frame.args
    local input = args[1]

    local match = string.match(input, '^([0-9][0-9]?) ([A-Za-z]+) ([0-9][0-9][0-9][0-9])$')

    if (match == nil) then return input .. ' -> is not a recognized pattern match' end

    return match[0] .. ' - ' .. match[1] .. ' - ' .. match[2]

    --[[
    local month = monthIndices[string.lower(match[2])]

    if (month == nil) then return input .. ' -> does not have a recognized month name'  end

    local day = tonumber(match[1])
    local year = tonumber(match[3])

    return input .. ' -> parsed to ' .. year .. '-' .. month .. '-' .. day; -- won't add 0s
    ]]

end
 
return main