• Share this text:
Report Abuse
Untitled - posted by guest on 14th January 2020 09:20:05 PM

local time_patternts = {L" одна", L" две"}

function format_timeto(timeto)

    local hour, min

    if type(timeto) == "wstring" then

        local hour_ = wstring.sub(timeto,1,-4)

        local min_  = wstring.sub(timeto,-2,-1)

        hour = tonumber(hour_)

        min = tonumber(min_)

    else

        local _, _, hour_, min_ = wstring.find(Format_Timespan(timeto, ETimespanFormat.HrMinRounded), L"(%d+):(%d+)")

        hour, min = tonumber(hour_), tonumber(min_)

    end


    local function time_to_phrase(number, hm)

        local sentence = L""

        if number ~= 0 then

            local number_10 = number % 10

            if number_10 == 1 and number ~= 11 then

                sentence = hm == "h" and L" час " or L" минута "

            elseif number_10 > 4 or number_10 == 0 or (number > 10 and number < 20) then

                sentence = hm == "h" and L" часов " or L" минут "

            else

                sentence = hm == "h" and L" часа " or L" минуты "

            end


            sentence = (((hm=="m")

                        and(number_10 == 1 or number_10 == 2)

                        and number ~= 11 and number ~= 12)

                        and((number - number_10)

                        and format_numbers2text(number - number_10) or L"") .. time_patternts[number_10]

                        or format_numbers2text(number)) .. sentence

        end

        return sentence

    end


    local time_text = time_to_phrase(hour, "h") .. time_to_phrase(min, "m")

    if time_text == L"" then

        time_text = L"меньше одной минуты"

    end

    return time_text

end

Report Abuse

Login or Register to edit or copy and save this text. It's free.