/*
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 { 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
 */
export class CalcDateUtilities extends Base {
    static c(a, b, c) {
        switch (c) {
            default:
            case 0:
            case 2:
            case 4: return 360;
            case 3: return 365;
            case 1:
                {
                    let d = a.getDate();
                    let e = dateGetMonth(a);
                    let f = a.getFullYear();
                    let g = b.getDate();
                    let h = dateGetMonth(b);
                    let 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 {
                        let j = 0;
                        for (let k = f; k <= i; k++) {
                            j += CalcDateUtilities.b(k) ? 366 : 365;
                        }
                        return j / (i - f + 1);
                    }
                }
        }
    }
    static e(a, b, c, d, e, f) {
        return ((b - a) * 360) + ((d - c) * 30) + (f - e);
    }
    static f(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))))));
        }
    }
    static g(a, b) {
        let c = a.getDate();
        let d = dateGetMonth(a);
        let e = a.getFullYear();
        let f = b.getDate();
        let g = dateGetMonth(b);
        let h = b.getFullYear();
        if (c == 31) {
            c = 30;
        }
        if (f == 31) {
            f = 30;
        }
        return CalcDateUtilities.e(e, h, d, g, c, f);
    }
    static h(a, b) {
        let c = a.getDate();
        let d = dateGetMonth(a);
        let e = a.getFullYear();
        let f = b.getDate();
        let g = dateGetMonth(b);
        let 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);
    }
    static a(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;
        }
    }
    static b(a) {
        return (a % 4) == 0 && ((a % 100) != 0 || (a % 400) == 0);
    }
    static d(a, b, c) {
        if (a > b) {
            let d = b;
            b = a;
            a = d;
        }
        return CalcDateUtilities.f(a, b, c) / CalcDateUtilities.c(a, b, c);
    }
}
CalcDateUtilities.$t = markType(CalcDateUtilities, 'CalcDateUtilities');
//# sourceMappingURL=CalcDateUtilities.js.map