Изменения

Перейти к навигации Перейти к поиску
уже отладил, не выкидывать же
Строка 183: Строка 183:  
     local args = getArgs(frame, { frameOnly = true })
 
     local args = getArgs(frame, { frameOnly = true })
 
     local datein = args[1]
 
     local datein = args[1]
     if not not string.match(datein, "%-") then
+
     local nums = {}
    -- парсинг входящей даты по шаблону ГГГГ-ММ-ДД
+
    local date = {}
        local pattern = "(%d+)%-(%d+)%-(%d+)"
+
     for num in string.gmatch(datein,"(%d+)") do
        local yearin, monthin, dayin = datein:match(pattern)
+
         table.insert(nums,tonumber(num))
     elseif not not string.match(datein, "%.") then
  −
    -- парсинг входящей даты по шаблону ДД.ММ.ГГГГ
  −
        local pattern = "(%d+)%.(%d+)%.(%d+)"
  −
         local dayin, monthin, yearin  = datein:match(pattern)
  −
    elseif not not string.match(datein, "%/") then
  −
    -- парсинг входящей даты по шаблону ДД/ММ/ГГГГ
  −
        local pattern = "(%d+)%/(%d+)%/(%d+)"
  −
        local dayin, monthin, yearin  = datein:match(pattern)
  −
    else return datein -- пока предполагаем так
   
     end
 
     end
     local year = tonumber(math.floor(yearin))
+
     if #nums > 3 then error("Wrong format: 3 numbers expected")
     local month = tonumber(math.floor(monthin))
+
    elseif (nums[2] >= 12) then error("Wrong month")
    local day = tonumber(math.floor(dayin))
+
     elseif nums[1] <= 31 then
     local datetext = year .. "-" .. month .. "-" .. day
+
        date.year = nums[3]
     error(datetext)
+
        date.month = nums[2]
     local timedate = os.time{year=year, month=month, day=day}
+
        date.day = nums[1]
     local date = lang:formatDate( 'j xg Y', timedate, true )
+
     elseif nums[3] <= 31 then
    return date
+
        date.year = nums[1]
 +
        date.month = nums[2]
 +
        date.day = nums[3]
 +
    else
 +
        return datein
 +
     end
 +
     local timedate = os.time(date)
 +
     return os.date("%Y-%m-%d", timedate)
 
end
 
end
    
return p
 
return p
Анонимный участник

Реклама:

Навигация