/*
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 { __extends } from "tslib";
import { Base, markType } from "igniteui-angular-core";
import { MathUtilities } from "./MathUtilities";
import { truncate } from "igniteui-angular-core";
import { dateGetMonth, dateGetDate } from "igniteui-angular-core";
import { timeSpanTotalDays } from "igniteui-angular-core";
/**
 * @hidden
 */
var CalcDateUtilities = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(CalcDateUtilities, _super);
    function CalcDateUtilities() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    CalcDateUtilities.c = function (a, b, c) {
        switch (c) {
            default:
            case 0:
            case 2:
            case 4: return 360;
            case 3: return 365;
            case 1:
                {
                    var d = a.getDate();
                    var e = dateGetMonth(a);
                    var f = a.getFullYear();
                    var g = b.getDate();
                    var h = dateGetMonth(b);
                    var i = b.getFullYear();
                    if (f == i) {
                        return CalcDateUtilities.b(f) ? 366 : 365;
                    }
                    else if (((i - 1) == f) && ((e > h) || ((e == h) && d >= g))) {
                        if (CalcDateUtilities.b(f)) {
                            return (e < 2 || (e == 2 && d <= 29)) ? 366 : 365;
                        }
                        else if (CalcDateUtilities.b(i)) {
                            return (h > 2 || (h == 2 && g == 29)) ? 366 : 365;
                        }
                        else {
                            return 365;
                        }
                    }
                    else {
                        var j = 0;
                        for (var k = f; k <= i; k++) {
                            j += CalcDateUtilities.b(k) ? 366 : 365;
                        }
                        return j / (i - f + 1);
                    }
                }
        }
    };
    CalcDateUtilities.e = function (a, b, c, d, e, f) {
        return ((b - a) * 360) + ((d - c) * 30) + (f - e);
    };
    CalcDateUtilities.f = function (a, b, c) {
        a = dateGetDate(a);
        b = dateGetDate(b);
        switch (c) {
            case 0: return CalcDateUtilities.h(a, b);
            case 4: return CalcDateUtilities.g(a, b);
            default: return truncate(MathUtilities.f(timeSpanTotalDays((+(dateGetDate(b)) - +(dateGetDate(a))))));
        }
    };
    CalcDateUtilities.g = function (a, b) {
        var c = a.getDate();
        var d = dateGetMonth(a);
        var e = a.getFullYear();
        var f = b.getDate();
        var g = dateGetMonth(b);
        var h = b.getFullYear();
        if (c == 31) {
            c = 30;
        }
        if (f == 31) {
            f = 30;
        }
        return CalcDateUtilities.e(e, h, d, g, c, f);
    };
    CalcDateUtilities.h = function (a, b) {
        var c = a.getDate();
        var d = dateGetMonth(a);
        var e = a.getFullYear();
        var f = b.getDate();
        var g = dateGetMonth(b);
        var h = b.getFullYear();
        if ((g == 2 && CalcDateUtilities.a(f, g, h)) && (d == 2 && CalcDateUtilities.a(c, d, e))) {
            f = 30;
        }
        if (f == 31 && c >= 30) {
            f = 30;
        }
        if (c == 31) {
            c = 30;
        }
        if (d == 2 && CalcDateUtilities.a(c, d, e)) {
            c = 30;
        }
        return CalcDateUtilities.e(e, h, d, g, c, f);
    };
    CalcDateUtilities.a = function (a, b, c) {
        switch (b) {
            case 2: return CalcDateUtilities.b(c) ? a == 29 : a == 28;
            case 4:
            case 6:
            case 9:
            case 11: return a == 30;
            default: return a == 31;
        }
    };
    CalcDateUtilities.b = function (a) {
        return (a % 4) == 0 && ((a % 100) != 0 || (a % 400) == 0);
    };
    CalcDateUtilities.d = function (a, b, c) {
        if (a > b) {
            var d = b;
            b = a;
            a = d;
        }
        return CalcDateUtilities.f(a, b, c) / CalcDateUtilities.c(a, b, c);
    };
    CalcDateUtilities.$t = markType(CalcDateUtilities, 'CalcDateUtilities');
    return CalcDateUtilities;
}(Base));
export { CalcDateUtilities };
