var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import { autoinject } from 'aurelia-framework';
import { Config } from '../config';
import moment from 'moment';
export var DateUtils = (function () {
    function DateUtils(config) {
        this.config = config;
    }
    DateUtils.prototype.format = function (date, format) {
        if (date == null) {
            return null;
        }
        if (isDate(date)) {
            date = moment(date);
        }
        return date.format(format);
    };
    DateUtils.prototype.toDate = function (date) {
        if (date == null) {
            return null;
        }
        if (isString(date)) {
            date = moment(date);
        }
        return date.toDate();
    };
    DateUtils.prototype.getNumOfWeek = function (date, locale) {
        if (locale === void 0) { locale = null; }
        if (date == null) {
            return null;
        }
        if (isDate(date)) {
            date = moment(date);
        }
        if (locale == null) {
            locale = this.config.globalConfig.defaultLocale;
        }
        return date.locale(locale).week();
    };
    DateUtils.prototype.isValid = function (date) {
        if (isDate(date)) {
            date = moment(date);
        }
        return date === null || date === void 0 ? void 0 : date.isValid();
    };
    DateUtils.prototype.isBefore = function (date, dateToCompare) {
        if (date == null || dateToCompare == null) {
            return false;
        }
        if (isDate(date)) {
            date = moment(date);
        }
        if (isDate(dateToCompare)) {
            dateToCompare = moment(dateToCompare);
        }
        return date.isBefore(dateToCompare);
    };
    DateUtils.prototype.isBeforeYear = function (date, dateToCompare) {
        if (date == null || dateToCompare == null) {
            return false;
        }
        if (isDate(date)) {
            date = moment(date);
        }
        if (isDate(dateToCompare)) {
            dateToCompare = moment(dateToCompare);
        }
        return date.get("year") < dateToCompare.get("year");
    };
    DateUtils.prototype.isAfter = function (date, dateToCompare) {
        if (date == null || dateToCompare == null) {
            return false;
        }
        if (isDate(date)) {
            date = moment(date);
        }
        if (isDate(dateToCompare)) {
            dateToCompare = moment(dateToCompare);
        }
        return date.isAfter(dateToCompare);
    };
    DateUtils.prototype.isAfterYear = function (date, dateToCompare) {
        if (date == null || dateToCompare == null) {
            return false;
        }
        if (isDate(date)) {
            date = moment(date);
        }
        if (isDate(dateToCompare)) {
            dateToCompare = moment(dateToCompare);
        }
        return date.get("year") > dateToCompare.get("year");
    };
    DateUtils.prototype.isSame = function (date, dateToCompare) {
        if (date == null || dateToCompare == null) {
            return false;
        }
        if (isDate(date)) {
            date = moment(date);
        }
        if (isDate(dateToCompare)) {
            dateToCompare = moment(dateToCompare);
        }
        return date.isSame(dateToCompare);
    };
    DateUtils.prototype.isSameOrAfter = function (date, dateToCompare) {
        if (date == null || dateToCompare == null) {
            return false;
        }
        if (isDate(date)) {
            date = moment(date);
        }
        if (isDate(dateToCompare)) {
            dateToCompare = moment(dateToCompare);
        }
        return date.isSameOrAfter(dateToCompare);
    };
    DateUtils.prototype.isSameOrBefore = function (date, dateToCompare) {
        if (date == null || dateToCompare == null) {
            return false;
        }
        if (isDate(date)) {
            date = moment(date);
        }
        if (isDate(dateToCompare)) {
            dateToCompare = moment(dateToCompare);
        }
        return date.isSameOrBefore(dateToCompare);
    };
    DateUtils.prototype.isSameDay = function (date, dateToCompare) {
        if (date == null || dateToCompare == null) {
            return false;
        }
        if (isDate(date)) {
            date = moment(date);
        }
        if (isDate(dateToCompare)) {
            dateToCompare = moment(dateToCompare);
        }
        return date.isSame(dateToCompare, "day");
    };
    DateUtils.prototype.isSameMonth = function (date, dateToCompare) {
        if (date == null || dateToCompare == null) {
            return false;
        }
        if (isDate(date)) {
            date = moment(date);
        }
        if (isDate(dateToCompare)) {
            dateToCompare = moment(dateToCompare);
        }
        return date.isSame(dateToCompare, "month");
    };
    DateUtils.prototype.isSameYear = function (date, dateToCompare) {
        if (date == null || dateToCompare == null) {
            return false;
        }
        if (isDate(date)) {
            date = moment(date);
        }
        if (isDate(dateToCompare)) {
            dateToCompare = moment(dateToCompare);
        }
        return date.isSame(dateToCompare, "year");
    };
    DateUtils.prototype.isWeekend = function (date) {
        if (isDate(date)) {
            date = moment(date);
        }
        return date.isoWeekday() == 6 || date.isoWeekday() == 7;
    };
    DateUtils.prototype.isStartOfMonth = function (date) {
        if (date == null) {
            return false;
        }
        var startOfMonth = this.getStartOfMonth(date);
        if (isDate(startOfMonth)) {
            startOfMonth = moment(startOfMonth);
        }
        return startOfMonth.isSame(date, "day");
    };
    DateUtils.prototype.addHours = function (date, nbHours) {
        if (date == null) {
            return null;
        }
        if (isDate(date)) {
            date = moment(date);
        }
        return date.add(nbHours, "hour").toDate();
    };
    DateUtils.prototype.addDays = function (date, nbDays) {
        if (date == null) {
            return null;
        }
        if (isDate(date)) {
            date = moment(date);
        }
        return date.add(nbDays, "day").toDate();
    };
    DateUtils.prototype.addMonths = function (date, nbMonths) {
        if (date == null) {
            return null;
        }
        if (isDate(date)) {
            date = moment(date);
        }
        return date.add(nbMonths, "month").toDate();
    };
    DateUtils.prototype.addWeeks = function (date, nbWeeks) {
        if (date == null) {
            return null;
        }
        if (isDate(date)) {
            date = moment(date);
        }
        return date.add(nbWeeks, "week").toDate();
    };
    DateUtils.prototype.addYears = function (date, nbYears) {
        if (date == null) {
            return null;
        }
        if (isDate(date)) {
            date = moment(date);
        }
        return date.add(nbYears, "year").toDate();
    };
    DateUtils.prototype.subtractHours = function (date, nbHours) {
        if (date == null) {
            return null;
        }
        if (isDate(date)) {
            date = moment(date);
        }
        return date.subtract(nbHours, "hour").toDate();
    };
    DateUtils.prototype.subtractDays = function (date, nbDays) {
        if (date == null) {
            return null;
        }
        if (isDate(date)) {
            date = moment(date);
        }
        return date.subtract(nbDays, "day").toDate();
    };
    DateUtils.prototype.subtractMonths = function (date, nbMonths) {
        if (date == null) {
            return null;
        }
        if (isDate(date)) {
            date = moment(date);
        }
        return date.subtract(nbMonths, "month").toDate();
    };
    DateUtils.prototype.subtractYears = function (date, nbYears) {
        if (date == null) {
            return null;
        }
        if (isDate(date)) {
            date = moment(date);
        }
        return date.subtract(nbYears, "year").toDate();
    };
    DateUtils.prototype.getStartOfMinute = function (date) {
        if (date == null) {
            return null;
        }
        if (isDate(date)) {
            date = moment(date);
        }
        return date.startOf("minute").toDate();
    };
    DateUtils.prototype.getStartOfDay = function (date) {
        if (date == null) {
            return null;
        }
        if (isDate(date)) {
            date = moment(date);
        }
        return date.startOf("day").toDate();
    };
    DateUtils.prototype.getStartOfWeek = function (date) {
        if (date == null) {
            return null;
        }
        if (isDate(date)) {
            date = moment(date);
        }
        return date.startOf("isoWeek").toDate();
    };
    DateUtils.prototype.getStartOfMonth = function (date) {
        if (date == null) {
            return null;
        }
        if (isDate(date)) {
            date = moment(date);
        }
        return date.startOf("month").toDate();
    };
    DateUtils.prototype.getStartOfYear = function (date) {
        if (date == null) {
            return null;
        }
        if (isDate(date)) {
            date = moment(date);
        }
        return date.startOf("year").toDate();
    };
    DateUtils.prototype.getStartOfDecade = function (date) {
        if (date == null) {
            return null;
        }
        if (isDate(date)) {
            date = moment(date);
        }
        date = date.startOf("year");
        return date.subtract(parseInt(date.get("year").toString().substring(3)), "year").toDate();
    };
    DateUtils.prototype.getEndOfMinute = function (date) {
        if (date == null) {
            return null;
        }
        if (isDate(date)) {
            date = moment(date);
        }
        return date.endOf("minute").toDate();
    };
    DateUtils.prototype.getEndOfDay = function (date) {
        if (date == null) {
            return null;
        }
        if (isDate(date)) {
            date = moment(date);
        }
        return date.endOf("day").toDate();
    };
    DateUtils.prototype.getEndOfWeek = function (date) {
        if (date == null) {
            return null;
        }
        if (isDate(date)) {
            date = moment(date);
        }
        return date.endOf("isoWeek").toDate();
    };
    DateUtils.prototype.getEndOfMonth = function (date) {
        if (date == null) {
            return null;
        }
        if (isDate(date)) {
            date = moment(date);
        }
        return date.endOf("month").toDate();
    };
    DateUtils.prototype.getEndOfYear = function (date) {
        if (date == null) {
            return null;
        }
        if (isDate(date)) {
            date = moment(date);
        }
        return date.endOf("year").toDate();
    };
    DateUtils.prototype.getEndOfDecade = function (date) {
        if (date == null) {
            return null;
        }
        if (isDate(date)) {
            date = moment(date);
        }
        date = date.endOf("year");
        return date.add(9 - parseInt(date.get("year").toString().substring(3)), "year").toDate();
    };
    DateUtils.prototype.setMonths = function (date, nbMonths) {
        if (date == null) {
            return null;
        }
        if (isDate(date)) {
            date = moment(date);
        }
        return date.set("month", nbMonths).toDate();
    };
    DateUtils.prototype.setHours = function (date, nbHours) {
        if (date == null) {
            return null;
        }
        if (isDate(date)) {
            date = moment(date);
        }
        return date.set("hour", nbHours).toDate();
    };
    DateUtils.prototype.setMinutes = function (date, nbMinutes) {
        if (date == null) {
            return null;
        }
        if (isDate(date)) {
            date = moment(date);
        }
        return date.set("minute", nbMinutes).toDate();
    };
    DateUtils = __decorate([
        autoinject,
        __metadata("design:paramtypes", [Config])
    ], DateUtils);
    return DateUtils;
}());

//# sourceMappingURL=date-utils.js.map
