Z26632

{
    "Z1K1": "Z2",
    "Z2K1": {
        "Z1K1": "Z6",
        "Z6K1": "Z26632"
    },
    "Z2K2": {
        "Z1K1": "Z14",
        "Z14K1": "Z26629",
        "Z14K3": {
            "Z1K1": "Z16",
            "Z16K1": "Z600",
            "Z16K2": "function Z26629(Z26629K1) {\r\n\r\n    function convertBengaliNumerals(str) {\r\n        const bengaliNumerals = ['০', '১', '২', '৩', '৪', '৫', '৬', '৭', '৮', '৯'];\r\n        const arabicNumerals = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];\r\n        let newStr = str;\r\n        for (let i = 0; i \u003C 10; i++) {\r\n            newStr = newStr.replace(new RegExp(bengaliNumerals[i], 'g'), arabicNumerals[i]);\r\n        }\r\n        return newStr;\r\n    }\r\n\r\n    function handleBengaliPhrases(str) {\r\n        let processedStr = str;\r\n        processedStr = processedStr.replace(/দেড়টা/g, \"1 টা 30\");\r\n        processedStr = processedStr.replace(/আড়াইটা/g, \"2 টা 30\");\r\n        processedStr = processedStr.replace(/(সাড়ে)\\s*(\\d+)\\s*টা?/g, \"$2 টা 30\");\r\n        processedStr = processedStr.replace(/(সোয়া|সুয়া)\\s*(\\d+)\\s*টা?/g, \"$2 টা 15\");\r\n        processedStr = processedStr.replace(/(পোনে|পনে)\\s*(\\d+)\\s*টা?/g, (match, keyword, hourStr) =\u003E {\r\n            let hour = parseInt(hourStr);\r\n            let newHour = (hour === 1) ? 12 : hour - 1;\r\n            return `${newHour} টা 45`;\r\n        });\r\n        processedStr = processedStr.replace(/(\\d+)\\s*টা?\\s*(বাজতে)\\s*(\\d+)/g, (match, hourStr, keyword, minStr) =\u003E {\r\n            let hour = parseInt(hourStr);\r\n            let minute = parseInt(minStr);\r\n            let newHour = (hour === 1) ? 12 : hour - 1;\r\n            let newMin = 60 - minute;\r\n            return `${newHour} টা ${newMin}`;\r\n        });\r\n        return processedStr;\r\n    }\r\n\r\n    var input = convertBengaliNumerals(Z26629K1);\r\n    input = handleBengaliPhrases(input);\r\n\r\n    const separators = [\" \", \"\\t\", \"/\", \"\\\\\", \":\", \".\", \"|\"];\r\n    const prefOptions = [\"ahms\", \"hmsa\", \"hams\"];\r\n\r\n    function languageSpecificOptions() {\r\n        function handleNight(elements, iAtt) {\r\n            const nightWords = [\"রাত\", \"নিশি\", \"রাত্রি\"];\r\n            if (!nightWords.includes(elements[iAtt].toLowerCase())) {\r\n                return null;\r\n            }\r\n            let hour = null;\r\n            let steps = 1;\r\n            if (elements[iAtt + 1]) {\r\n                let num = extractNumber(elements[iAtt + 1]);\r\n                if (num !== null \u0026\u0026 num \u003E= 1 \u0026\u0026 num \u003C= 12) {\r\n                    hour = num;\r\n                    if (elements[iAtt + 2] \u0026\u0026 (elements[iAtt + 2] === \"টা\" || elements[iAtt + 2] === \"টায়\")) {\r\n                        steps = 3;\r\n                    } else {\r\n                        steps = 2;\r\n                    }\r\n                }\r\n            }\r\n            if (hour === null) {\r\n                return null;\r\n            }\r\n            let finalHour;\r\n            if (hour \u003E= 9 \u0026\u0026 hour \u003C= 11) {\r\n                finalHour = hour + 12;\r\n            } else if (hour === 12) {\r\n                finalHour = 0;\r\n            } else {\r\n                finalHour = hour;\r\n            }\r\n            return [finalHour, steps];\r\n        }\r\n        if (defineLiteralFunction(handleNight, HOUR, true)) {\r\n            return;\r\n        }\r\n        defineLiterals({\r\n            \"এএম\": AM,\r\n            \"এম\": AM,\r\n            \"পিএম\": PM,\r\n            \"পি এম\": PM\r\n        }, AMPM, NORMAL);\r\n        defineLiterals({\r\n            \"ভোর\": AM,\r\n            \"সকাল\": AM,\r\n            \"প্রভাত\": AM,\r\n            \"পূর্বাহ্ণ\": AM\r\n        }, AMPM, NORMAL);\r\n        defineLiterals({\r\n            \"দুপুর\": PM,\r\n            \"মধ্যাহ্ন\": PM,\r\n            \"অপরাহ্ণ\": PM,\r\n            \"বিকাল\": PM,\r\n            \"সন্ধ্যা\": PM,\r\n            \"গোধূলি\": PM\r\n        }, AMPM, NORMAL);\r\n        defineLiterals({\r\n            \"দুপুর\": 12,\r\n            \"মধ্যাহ্ন\": 12,\r\n            \"মধ্যরাত\": 0,\r\n        }, HOUR, NORMAL);\r\n        defineConstraint([\"টা\", \"টায়\", \"বেজে\"], HOUR, AFTER);\r\n        defineConstraint([\"মিনিট\"], MINUTE, AFTER);\r\n        defineConstraint([\"সেকেন্ড\"], SECOND, AFTER);\r\n    }\r\n\r\n    function formatOutput(o) {\r\n        let h = o[HOUR] ?? 0;\r\n        if (o[AMPM] == AM \u0026\u0026 h == 12) {\r\n            h = 0;\r\n        } else if (o[AMPM] == PM \u0026\u0026 h \u003C 12) {\r\n            h += 12;\r\n        }\r\n        if (h == 24) h = 12;\r\n        return {\r\n            K1: h,\r\n            K2: o[MINUTE] ?? 0,\r\n            K3: o[SECOND] ?? 0\r\n        };\r\n    }\r\n    const delete_chain = \"smah\";\r\n    const HOUR = 'h';\r\n    const MINUTE = 'm';\r\n    const SECOND = 's';\r\n    const AMPM = 'a';\r\n    const AM = Symbol();\r\n    const PM = Symbol();\r\n    const numericElements = \"hms\";\r\n    const numericElementMin = {\r\n        h: 0,\r\n        m: 0,\r\n        s: 0\r\n    };\r\n    const numericElementMax = {\r\n        h: 24,\r\n        m: 59,\r\n        s: 60\r\n    };\r\n    const BEFORE = 10;\r\n    const AFTER = 20;\r\n    const BEFORE_OR_AFTER = 30;\r\n    const LENIENT = true;\r\n    const NORMAL = false;\r\n    const LETTER_BY_LETTER = Symbol();\r\n\r\n    function defineLiterals(literals, meaning, compMode = LENIENT, forced = false) {\r\n        let bestGuess = null;\r\n        const compFunc = compMode == LENIENT ? lenientComp : lessLenientComp;\r\n        for (let m in literals) {\r\n            let target = m.split(\" \");\r\n            let ok = true;\r\n            for (let t = 0; t \u003C target.length; ++t) {\r\n                if (elements[iAtt + t] == undefined || !compFunc(elements[iAtt + t], target[t])) {\r\n                    ok = false;\r\n                    break;\r\n                }\r\n            }\r\n            if (ok) {\r\n                if (bestGuess == null || bestGuess[1] \u003C target.length) {\r\n                    bestGuess = [literals[m], target.length];\r\n                }\r\n            } else if (compMode == LETTER_BY_LETTER) {\r\n                let target = m.split(\"\");\r\n                target.filter((l) =\u003E l != \" \");\r\n                let ok = true;\r\n                for (let t = 0; t \u003C target.length; ++t) {\r\n                    if (elements[iAtt + t] == undefined || !compFunc(elements[iAtt + t], target[t])) {\r\n                        ok = false;\r\n                        break;\r\n                    }\r\n                }\r\n                if (ok) {\r\n                    if (bestGuess == null || bestGuess[1] \u003C target.length) {\r\n                        bestGuess = [literals[m], target.length];\r\n                    }\r\n                }\r\n            }\r\n        }\r\n        if (bestGuess == null) {\r\n            return false;\r\n        }\r\n        if (typeof(meaning) == \"string\") {\r\n            meaning = [meaning];\r\n        }\r\n        for (let m of meaning) {\r\n            _currGuess[m] = bestGuess[0];\r\n        }\r\n        _nSteps = bestGuess[1];\r\n        if (forced) {\r\n            _forced = meaning;\r\n        }\r\n        return true;\r\n    }\r\n\r\n    function defineLiteralFunction(f, meaning, forced = false) {\r\n        let bestGuess = f(elements, iAtt);\r\n        if (bestGuess == null) {\r\n            return false;\r\n        }\r\n        if (typeof(meaning) == \"string\") {\r\n            meaning = [meaning];\r\n        }\r\n        for (let m of meaning) {\r\n            _currGuess[m] = bestGuess[0];\r\n        }\r\n        _nSteps = bestGuess[1];\r\n        if (forced) {\r\n            _forced = meaning;\r\n        }\r\n        return true;\r\n    }\r\n\r\n    function defineConstraint(literals, meaning, position, compMode = NORMAL) {\r\n        let bestGuess = null;\r\n        const compFunc = compMode == LENIENT ? lenientComp : lessLenientComp;\r\n        for (let m of literals) {\r\n            let target = m.split(\" \");\r\n            let ok = true;\r\n            for (let t = 0; t \u003C target.length; ++t) {\r\n                if (elements[iAtt + t] == undefined || !compFunc(elements[iAtt + t], target[t])) {\r\n                    ok = false;\r\n                    break;\r\n                }\r\n            }\r\n            if (ok) {\r\n                if (bestGuess == null || bestGuess \u003C target.length) {\r\n                    bestGuess = target.length;\r\n                }\r\n            }\r\n        }\r\n        if (bestGuess == null) {\r\n            return false;\r\n        }\r\n        if (typeof(meaning) == \"string\") {\r\n            meaning = [meaning];\r\n        }\r\n        _constraintsList.push({\r\n            pos: possibilities.length,\r\n            meaning: meaning,\r\n            type: position\r\n        });\r\n        _nSteps = bestGuess;\r\n        _isToBeIgnored = true;\r\n        return true;\r\n    }\r\n\r\n    function defineConstraintFunction(f, meaning, position) {\r\n        let bestGuess = f(elements, iAtt);\r\n        if (bestGuess == null) {\r\n            return false;\r\n        }\r\n        if (typeof(meaning) == \"string\") {\r\n            meaning = [meaning];\r\n        }\r\n        _constraintsList.push({\r\n            pos: possibilities.length,\r\n            meaning: meaning,\r\n            type: position\r\n        });\r\n        _nSteps = bestGuess;\r\n        _isToBeIgnored = true;\r\n        return true;\r\n    }\r\n\r\n    function lenientComp(a, b) {\r\n        a = a.toLowerCase().replaceAll(/,|\\.|;|:/g, \"\");\r\n        b = b.toLowerCase();\r\n        if (a == \"\") return false;\r\n        return a == b.substring(0, a.length);\r\n    }\r\n\r\n    function lessLenientComp(a, b) {\r\n        a = a.toLowerCase().replaceAll(/,|\\.|;|:/g, \"\");\r\n        b = b.toLowerCase();\r\n        if (a == \"\") return false;\r\n        return a == b;\r\n    }\r\n\r\n    function extractNumber(s) {\r\n        let res = /-?[0-9]+/.exec(s);\r\n        if (res != null) {\r\n            return Number(res);\r\n        }\r\n        return null;\r\n    }\r\n    input = input.replaceAll(/-|—|‒|–|—|⸺|⸺/g, \"-\");\r\n    var isoRegex = /(\\d{4}-[01]\\d-[0-3]\\dT[0-2]\\d:[0-5]\\d:[0-5]\\d\\.\\d+)|(\\d{4}-[01]\\d-[0-3]\\dT[0-2]\\d:[0-5]\\d:[0-5]\\d)|(\\d{4}-[01]\\d-[0-3]\\dT[0-2]\\d:[0-5]\\d)/;\r\n    if (isoRegex.exec(input)) {\r\n        input = input.split(\"T\")[0];\r\n        var list = input.split(/(?\u003C=.)-(?=.)/);\r\n        return {\r\n            K1: BigInt(list[0]),\r\n            K2: list[1] - 1,\r\n            K3: list[2]\r\n        };\r\n    }\r\n    var elements = [\"\"];\r\n    for (let i = 0; i \u003C input.length;) {\r\n        let s = separators.find((v) =\u003E input.substring(i, i + v.length) == v);\r\n        if (s !== undefined) {\r\n            if (elements[elements.length - 1] != \"\")\r\n                elements.push(\"\");\r\n            i += s.length;\r\n            continue;\r\n        }\r\n        elements[elements.length - 1] += input[i++];\r\n    }\r\n    if (elements[elements.length - 1] == \"\") elements.pop();\r\n    let elSeparato = [];\r\n    for (let i = 0; i \u003C elements.length; ++i) {\r\n        for (let e of elements[i].matchAll(/((?:(?\u003C=^|\\s)[\\-\\+])?[0-9]+)?(?:\\-?([^0-9\\-]+))?/g)) {\r\n            elSeparato.push(e.splice(1))\r\n        }\r\n    }\r\n    elSeparato = elSeparato.flat();\r\n    elements = elSeparato.filter((v) =\u003E (v != null \u0026\u0026 v != \"\"));\r\n    var possibilities = [];\r\n    var _constraintsList = [];\r\n    var _nSteps = 1;\r\n    for (var iAtt = 0; iAtt \u003C elements.length; iAtt += _nSteps) {\r\n        _nSteps = 1;\r\n        let n = extractNumber(elements[iAtt]);\r\n        var _currGuess = {};\r\n        var _forced = null;\r\n        var _isToBeIgnored = false;\r\n        languageSpecificOptions();\r\n        for (let i of numericElements) {\r\n            if (n \u003E= numericElementMin[i] \u0026\u0026 n \u003C= numericElementMax[i]) {\r\n                _currGuess[i] ??= n;\r\n            }\r\n        }\r\n        if (_forced != null) {\r\n            for (let j in _currGuess) {\r\n                if (_forced.find((v) =\u003E (v == j)) == undefined) {\r\n                    _currGuess[j] = null;\r\n                }\r\n            }\r\n        }\r\n        if (!_isToBeIgnored)\r\n            possibilities.push(_currGuess);\r\n    }\r\n    if (_constraintsList.length \u003E 0) {\r\n        for (let pAtt = 0; pAtt \u003C possibilities.length; ++pAtt) {\r\n            for (let c of _constraintsList) {\r\n                if ((c.type == AFTER \u0026\u0026 pAtt != c.pos - 1) || (c.type == BEFORE \u0026\u0026 pAtt != c.pos) || (c.type == BEFORE_OR_AFTER \u0026\u0026 pAtt != c.pos - 1 \u0026\u0026 pAtt != c.pos)) {\r\n                    for (let m of c.meaning) {\r\n                        possibilities[pAtt][m] = null;\r\n                    }\r\n                } else if ((c.type == AFTER \u0026\u0026 pAtt == c.pos - 1) || (c.type == BEFORE \u0026\u0026 pAtt == c.pos)) {\r\n                    for (let m in possibilities[pAtt]) {\r\n                        if (c.meaning.find((x) =\u003E x == m) == undefined) {\r\n                            possibilities[pAtt][m] = null;\r\n                        }\r\n                    }\r\n                }\r\n            }\r\n        }\r\n    }\r\n    possibilities = possibilities.filter((v) =\u003E (Object.entries(v).filter((x) =\u003E x[1] != null).length \u003E 0));\r\n    let lettersToRemove = \"\";\r\n    if (delete_chain.length \u003E possibilities.length) {\r\n        for (let i of delete_chain) {\r\n            if (possibilities.find((p) =\u003E p[i] != null) == undefined) {\r\n                lettersToRemove += i;\r\n            }\r\n        }\r\n    }\r\n    let safeLetters = \"\";\r\n    if (delete_chain.length \u003E possibilities.length) {\r\n        for (let p of possibilities) {\r\n            if (Object.entries(p).filter((x) =\u003E x[1] != null).length == 1) {\r\n                safeLetters = Object.entries(p).filter((x) =\u003E x[1] != null)[0];\r\n            }\r\n        }\r\n    }\r\n    for (let i = 0; delete_chain.length - lettersToRemove.length \u003E possibilities.length \u0026\u0026 i \u003C delete_chain.length; ++i) {\r\n        if (lettersToRemove.indexOf(delete_chain[i]) == -1 \u0026\u0026 safeLetters.indexOf(delete_chain[i]) == -1) {\r\n            lettersToRemove += delete_chain[i];\r\n        }\r\n    }\r\n    for (let i = 0; i \u003C prefOptions.length; ++i) {\r\n        let actPref = prefOptions[i];\r\n        let elementsFound = {};\r\n        for (let l of lettersToRemove) {\r\n            actPref = actPref.replace(l, \"\");\r\n        }\r\n        let ok = true;\r\n        for (let j = 0; j \u003C actPref.length; ++j) {\r\n            elementsFound[actPref[j]] = possibilities[j]?.[actPref[j]];\r\n            if (elementsFound[actPref[j]] == null) {\r\n                ok = false;\r\n                break;\r\n            }\r\n        }\r\n        if (ok) {\r\n            return formatOutput(elementsFound);\r\n        }\r\n    }\r\n}"
        }
    },
    "Z2K3": {
        "Z1K1": "Z12",
        "Z12K1": [
            "Z11",
            {
                "Z1K1": "Z11",
                "Z11K1": "Z1002",
                "Z11K2": "read Time of day, Bangla (JS)"
            }
        ]
    },
    "Z2K4": {
        "Z1K1": "Z32",
        "Z32K1": [
            "Z31"
        ]
    },
    "Z2K5": {
        "Z1K1": "Z12",
        "Z12K1": [
            "Z11"
        ]
    }
}