/* global angular, moment */

angular.module("app").filter('momentweekday', function () {
    return function (item) {
        moment.locale('es');
        var aux = moment(item, "YYYY-MM-DD");
        var fecha = aux.format("ddd");
        return fecha;
    };
});
angular.module("app").filter('momentmindate', function () {
    return function (item) {
        moment.locale('es');
        var aux = moment(item, "YYYY-MM-DD");
        var fecha = aux.format("ddd D/MM/YY");
        return fecha;
    };
});
angular.module("app").filter('momentdate', function () {
    return function (item) {
        moment.locale('es');
        var aux = moment(item, "YYYY-MM-DD");
        var fecha = aux.format("ddd D/MM/YYYY");
        return fecha;
    };
});
angular.module("app").filter('momentminimaldate', function () {
    return function (item) {
        moment.locale('es');
        var aux = moment(item, "YYYY-MM-DD");
        var fecha = aux.format("DD/MM/YYYY");
        return fecha;
    };
});
angular.module("app").filter('momentminimaldatetime', function () {
    return function (item) {
        moment.locale('es');
        var aux = moment(item, "YYYY-MM-DD");
        var fecha = aux.format("DD/MM/YYYY HH:mm");
        return fecha;
    };
});
angular.module("app").filter('momentdatetime', function () {
    return function (item) {
        moment.locale('es');
        var aux = moment(item, "YYYY-MM-DD HH:mm");
        return aux.format("ddd, D/MMM/YYYY, HH:mm");
    };
});
angular.module("app").filter('momentstringfulldate', function () {
    return function (item) {
        moment.locale('es');
        var aux = moment(item, "YYYY-MM-DD");
        return aux.format("ddd, D [ de ] MMMM [ del ] YYYY");
    };
});
angular.module("app").filter('momentfulldatetime', function () {
    return function (item) {
        moment.locale('es');
        var aux = moment(item, "YYYY-MM-DD HH:mm");
        return aux.format("LLLL");
    };
});
angular.module("app").filter('momenttime', function () {
    return function (item) {
        moment.locale('es');
        var aux = moment(item, "HH:mm");
        return aux.format("HH:mm");
    };
});
angular.module("app").filter('momenttimefromdatetime', function () {
    return function (item) {
        moment.locale('es');
        var aux = moment(item, "YYYY-MM-DD HH:mm");
        return aux.format("HH:mm");
    };
});
angular.module("app").filter('momentrelativetime', function () {
    return function (item) {
        moment.locale('es');
        var aux = moment(item, "YYYY-MM-DD HH:mm");
        return aux.fromNow();
    };
});
angular.module("app").filter('momentseniority', function () {
    return function (item) {
        moment.locale('es');
        var today = moment.utc();
        var aux = moment.utc(item);
        var diff_years = today.diff(aux, 'years');
        if (aux.isSameOrBefore(today)) {
            if (diff_years === 0) {
                var diff_months = today.diff(aux, 'months');
                if (diff_months === 0) {
                    var diff_days = today.diff(aux, 'days');
                    return diff_days + (diff_days === 1 ? " d\u00EDa" : " d\u00EDas");
                } else {
                    return diff_months + (diff_months === 1 ? " mes" : " meses");
                }
            } else {
                return diff_years + (diff_years === 1 ? " a\u00F1o" : " a\u00F1os");
            }
        } else {
            return 'fecha invalida';
        }
    };
});