<commit_before>'use strict';

angular.module('ddsApp').directive('dateNaissanceMaxAge', function() {
    return {
        require: 'ngModel',
        link: function(scope, elm, attrs, ctrl) {
            ctrl.$parsers.unshift(function(viewValue) {
                var date = moment(viewValue, 'DD/MM/YYYY', true);
                if (date.isValid()) {
                    var maxAge = scope.$eval(attrs.dateNaissanceMaxAge);
                    if (angular.isDefined(maxAge)) {
                        var years = moment().diff(date, 'years');
                        if (years > maxAge) {
                            ctrl.$setValidity('dateNaissanceMaxAge', false);

                            return viewValue;
                        }
                    }
                }

                ctrl.$setValidity('dateNaissanceMaxAge', true);

                return viewValue;
            });
        }
    };
});

angular.module('ddsApp').directive('dateNaissanceMinAge', function() {
    return {
        require: 'ngModel',
        link: function(scope, elm, attrs, ctrl) {
            ctrl.$parsers.unshift(function(viewValue) {
                var date = moment(viewValue, 'DD/MM/YYYY', true);
                if (date.isValid()) {
                    var minAge = scope.$eval(attrs.dateNaissanceMinAge);
                    if (angular.isDefined(minAge)) {
                        var years = moment().diff(date, 'years');
                        if (years < minAge) {
                            ctrl.$setValidity('dateNaissanceMinAge', false);

                            return viewValue;
                        }
                    }
                }

                ctrl.$setValidity('dateNaissanceMinAge', true);

                return viewValue;
            });
        }
    };
});<commit_msg>fix duplication dateNaissanceMaxAge.js<commit_after>'use strict';

var dateNaissanceValidator = function(scope, ctrl, attrs, attr, isValid) {
  ctrl.$parsers.unshift(function(viewValue) {
      var date = moment(viewValue, 'DD/MM/YYYY', true);
      if (date.isValid()) {
          var ageCond = scope.$eval(attrs[attr]);
          if (angular.isDefined(ageCond)) {
              var years = moment().diff(date, 'years');
              if (!isValid(years, ageCond)) {
                  ctrl.$setValidity(attr, false);

                  return viewValue;
              }
          }
      }

      ctrl.$setValidity(attr, true);

      return viewValue;
  });
};

angular.module('ddsApp').directive('dateNaissanceMaxAge', function() {
    return {
        require: 'ngModel',
        link: function(scope, elm, attrs, ctrl) {
            dateNaissanceValidator(scope, ctrl, attrs, 'dateNaissanceMaxAge', function(years, ageCond) {
              return years <= ageCond;
            });
        }
    };
});

angular.module('ddsApp').directive('dateNaissanceMinAge', function() {
    return {
        require: 'ngModel',
        link: function(scope, elm, attrs, ctrl) {
            dateNaissanceValidator(scope, ctrl, attrs, 'dateNaissanceMinAge', function(years, ageCond) {
              return years >= ageCond;
            });
        }
    };
});
{'fraction_non_alphanumeric': 0.12728995578016425, 'fraction_numerical': 0.0, 'mean_word_length': 1.6238608119304059, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3940243', 'n_tokens_mistral': 891, 'n_tokens_neox': 840, 'n_words': 155}