Mine sisu juurde

Moodul:EnDigitConverter

Vikipedii-späi

Selle mooduli dokumentatsiooni saab kirjutada asukohta Moodul:EnDigitConverter/doc.

local p = {}

-- Veps month names mapped to month numbers
local veps_months = {
    ['01'] = 'viluku',    -- January
    ['02'] = 'uhoku',     -- February
    ['03'] = 'keväz’ku',  -- March
    ['04'] = 'sulaku',    -- April
    ['05'] = 'semendku',  -- May
    ['06'] = 'kezaku',    -- June
    ['07'] = 'heinku',    -- July
    ['08'] = 'eloku',     -- August
    ['09'] = 'sügüz’ku',  -- September
    ['10'] = 'reduku',    -- October
    ['11'] = 'kül’mku',   -- November
    ['12'] = 'tal’vku',   -- December
}

-- English month names for fallback or alternative parsing
local english_months = {
    ['january'] = 'viluku',
    ['february'] = 'uhoku',
    ['march'] = 'keväz’ku',
    ['april'] = 'sulaku',
    ['may'] = 'semendku',
    ['june'] = 'kezaku',
    ['july'] = 'heinku',
    ['august'] = 'eloku',
    ['september'] = 'sügüz’ku',
    ['october'] = 'reduku',
    ['november'] = 'kül’mku',
    ['december'] = 'tal’vku',
}

function p._main(date)
    if not date or date == '' then
        return date
    end

    -- Trim whitespace
    date = mw.text.trim(date)

    -- Check for YYYY-MM-DD format
    local year, month, day = date:match('^(%d%d%d%d)%-(%d%d)%-(%d%d)$')
    if year and month and day then
        local veps_month = veps_months[month]
        if veps_month then
            -- Return in DMY format with period: DD. Month YYYY
            return day .. '. ' .. veps_month .. ' ' .. year
        else
            -- Invalid month, return original date
            return date
        end
    end

    -- Check for English month name format (e.g., "March 15, 2024")
    local eng_month, eng_day, eng_year = date:match('^([A-Za-z]+)%s+(%d%d?),?%s+(%d%d%d%d)$')
    if eng_month and eng_day and eng_year then
        local veps_month = english_months[eng_month:lower()]
        if veps_month then
            -- Return in DMY format with period: DD. Month YYYY
            return eng_day .. '. ' .. veps_month .. ' ' .. eng_year
        end
    end

    -- If date format is unrecognized, return original date
    return date
end

return p