မော်ဂျူး:ConvertTime

ဝီကီပီးဒီးယား မှ
Documentation icon မော်ဂျူးမှတ်တမ်းလက်စွဲ[ကြည့်ရှု] [တည်းဖြတ်] [ရာဇဝင်] [ရှင်းသန့်]

နမူနာ[ပြင်ဆင်ရန်]

{{#invoke:ConvertTime|main|<!-- your text here -->}}
နမူနာအားဖြင့် {{#invoke:ConvertTime|main|၀၄:၄၅, ၉ ဖေဖော်ဝါရီ ၂၀၁၆}} ဟုရေးလျှင် "04:45, 9 February 2016" ဟု ရမည်။

ဆက်စပ်ကြည့်ရှုရန်[ပြင်ဆင်ရန်]

-- First, define a table of text to search for, and what to convert it to.

local conversionTable = {
   ['ဇန်နဝါရီ'] = 'January',
   ['ဖေဖော်ဝါရီ'] = 'February',
   ['မတ်'] = 'March',
   ['ဧပြီ'] = 'April',
   ['မေ'] = 'May',
   ['ဇွန်'] = 'June',
   ['ဇူလိုင်'] = 'July',
   ['ဩဂုတ်'] = 'August',
   ['စက်တင်ဘာ'] = 'September',
   ['အောက်တိုဘာ'] = 'October',
   ['နိုဝင်ဘာ'] = 'November',
   ['ဒီဇင်ဘာ'] = 'December',
   ['၀'] = '0',
   ['၁'] = '1',
   ['၂'] = '2',
   ['၃'] = '3',
   ['၄'] = '4',
   ['၅'] = '5',
   ['၆'] = '6',
   ['၇'] = '7',
   ['၈'] = '8',
   ['၉'] = '9',
}

-- Then we define a table to hold our function
local p = {}

-- Then we define a function that converts strings using conversionTable.
function p.main(frame)
    local s = frame.args[1] -- This gets the first positional argument.
    for bn, en in pairs(conversionTable) do -- This converts every string found in the table.
        s = mw.ustring.gsub(s, bn, en)
    end
    return s -- Get the result of the function.
end

return p -- Pass our table containing our function back to Lua.
-- Now we can call our function using {{#invoke:ConvertTime|main|<!-- your text here -->}}.