/*
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 { markType } from "igniteui-angular-core";
import { dateFromValues, dateGetMonth } from "igniteui-angular-core";
/**
 * @hidden
 */
var UltraCalcFunctionDays360 = /** @class */ (function (_super) {
    tslib_1.__extends(UltraCalcFunctionDays360, _super);
    function UltraCalcFunctionDays360() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    UltraCalcFunctionDays360.prototype.evaluate = function (a, b) {
        var c = false;
        if (b > 2) {
            if (a.peek().isError) {
                return new ExcelCalcValue(a.pop().toErrorValue());
            }
            c = a.pop()._toBoolean1();
        }
        var d = a.pop()._toDateTime1();
        var e = a.pop()._toDateTime1();
        return UltraCalcFunctionDays360._ak(e, d, c);
    };
    UltraCalcFunctionDays360._ak = function (a, b, c) {
        if (a.getDate() == 31) {
            a = dateFromValues(a.getFullYear(), dateGetMonth(a), 30, 0, 0, 0, 0);
        }
        if (b.getDate() == 31) {
            if (!c) {
                if (a.getDate() < 30) {
                    b = dateFromValues(dateGetMonth(b) < 12 ? b.getFullYear() : b.getFullYear() + 1, dateGetMonth(b) < 12 ? dateGetMonth(b) + 1 : 1, 1, 0, 0, 0, 0);
                }
                else {
                    b = dateFromValues(b.getFullYear(), dateGetMonth(b), 30, 0, 0, 0, 0);
                }
            }
            else {
                b = dateFromValues(b.getFullYear(), dateGetMonth(b), 30, 0, 0, 0, 0);
            }
        }
        return new ExcelCalcValue((b.getFullYear() * 360 + dateGetMonth(b) * 30 + b.getDate()) - (a.getFullYear() * 360 + dateGetMonth(a) * 30 + a.getDate()));
    };
    UltraCalcFunctionDays360.prototype.get_name = function () {
        return "days360";
    };
    Object.defineProperty(UltraCalcFunctionDays360.prototype, "name", {
        get: function () {
            return this.get_name();
        },
        enumerable: true,
        configurable: true
    });
    UltraCalcFunctionDays360.prototype.get_minArgs = function () {
        return 2;
    };
    Object.defineProperty(UltraCalcFunctionDays360.prototype, "minArgs", {
        get: function () {
            return this.get_minArgs();
        },
        enumerable: true,
        configurable: true
    });
    UltraCalcFunctionDays360.prototype.get_maxArgs = function () {
        return 3;
    };
    Object.defineProperty(UltraCalcFunctionDays360.prototype, "maxArgs", {
        get: function () {
            return this.get_maxArgs();
        },
        enumerable: true,
        configurable: true
    });
    UltraCalcFunctionDays360.$t = markType(UltraCalcFunctionDays360, 'UltraCalcFunctionDays360', BuiltInFunctionBase.$);
    return UltraCalcFunctionDays360;
}(BuiltInFunctionBase));
export { UltraCalcFunctionDays360 };
//# sourceMappingURL=UltraCalcFunctionDays360.js.map