/*
THIS INFRAGISTICS ULTIMATE SOFTWARE LICENSE  AGREEMENT ("AGREEMENT") LOCATED HERE:
https://www.infragistics.com/legal/license/igultimate-la
https://www.infragistics.com/legal/license/igultimate-eula
GOVERNS THE LICENSING, INSTALLATION AND USE OF INFRAGISTICS SOFTWARE. BY DOWNLOADING AND/OR INSTALLING AND USING INFRAGISTICS SOFTWARE:  you are indicating that you have read and understand this Agreement, and agree to be legally bound by it on behalf of the yourself and your company.
*/
import * as tslib_1 from "tslib";
import { BuiltInFunctionBase } from "./BuiltInFunctionBase";
import { ExcelCalcValue } from "./ExcelCalcValue";
import { ExcelCalcErrorValue } from "./ExcelCalcErrorValue";
import { ExcelCalcFunction } from "./ExcelCalcFunction";
import { markType } from "igniteui-angular-core";
import { truncate, intDivide } from "igniteui-angular-core";
import { daysInMonth, dateFromValues } from "igniteui-angular-core";
/**
 * @hidden
 */
var UltraCalcFunctionDate = /** @class */ (function (_super) {
    tslib_1.__extends(UltraCalcFunctionDate, _super);
    function UltraCalcFunctionDate() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    UltraCalcFunctionDate.prototype.evaluate = function (a, b) {
        var c = a.pop();
        var d = a.pop();
        var e = a.pop();
        if (e.isError) {
            return e;
        }
        var f;
        if (((function () { var g = e._toDouble1(f); f = g.p0; return g.ret; })()) == false) {
            return new ExcelCalcValue(new ExcelCalcErrorValue(1));
        }
        if (d.isError) {
            return d;
        }
        var g;
        if (((function () { var h = d._toDouble1(g); g = h.p0; return h.ret; })()) == false) {
            return new ExcelCalcValue(new ExcelCalcErrorValue(1));
        }
        if (c.isError) {
            return c;
        }
        var h;
        if (((function () { var i = c._toDouble1(h); h = i.p0; return i.ret; })()) == false) {
            return new ExcelCalcValue(new ExcelCalcErrorValue(1));
        }
        var i = truncate(Math.floor(f));
        var j = truncate(Math.floor(g));
        var k = truncate(Math.floor(h));
        if (true) {
            var l = 1900;
            if (i < l) {
                i += l;
            }
        }
        while (true) {
            var m = (j - 1);
            var n = intDivide(m, 12);
            if (n > 0) {
                i += n;
                j = (m % 12) + 1;
            }
            if (10000 <= i) {
                return new ExcelCalcValue(new ExcelCalcErrorValue(4));
            }
            var o = daysInMonth(i, j);
            if (k <= o) {
                break;
            }
            k -= o;
            j++;
        }
        if (true) {
            if (i < 1900) {
                return new ExcelCalcValue(new ExcelCalcErrorValue(4));
            }
            var p = ExcelCalcFunction._l(a);
            if (p != null && p.dateSystem == 1 && i < 1904) {
                return new ExcelCalcValue(new ExcelCalcErrorValue(4));
            }
            if (10000 <= i) {
                return new ExcelCalcValue(new ExcelCalcErrorValue(4));
            }
        }
        else {
            if (i < 0) {
                return new ExcelCalcValue(new ExcelCalcErrorValue(4));
            }
        }
        var q = dateFromValues(i, j, k, 0, 0, 0, 0);
        return new ExcelCalcValue(q);
    };
    UltraCalcFunctionDate.prototype.get_name = function () {
        return "date";
    };
    Object.defineProperty(UltraCalcFunctionDate.prototype, "name", {
        get: function () {
            return this.get_name();
        },
        enumerable: true,
        configurable: true
    });
    UltraCalcFunctionDate.prototype.get_minArgs = function () {
        return 3;
    };
    Object.defineProperty(UltraCalcFunctionDate.prototype, "minArgs", {
        get: function () {
            return this.get_minArgs();
        },
        enumerable: true,
        configurable: true
    });
    UltraCalcFunctionDate.prototype.get_maxArgs = function () {
        return 3;
    };
    Object.defineProperty(UltraCalcFunctionDate.prototype, "maxArgs", {
        get: function () {
            return this.get_maxArgs();
        },
        enumerable: true,
        configurable: true
    });
    UltraCalcFunctionDate.prototype.doesParameterAllowIntermediateResultArray = function (a, b) {
        return true;
    };
    UltraCalcFunctionDate.$t = markType(UltraCalcFunctionDate, 'UltraCalcFunctionDate', BuiltInFunctionBase.$);
    return UltraCalcFunctionDate;
}(BuiltInFunctionBase));
export { UltraCalcFunctionDate };
//# sourceMappingURL=UltraCalcFunctionDate.js.map