app.directive('asDate', function () {
  return {
    require: '^ngModel',
    restrict: 'A',
    link: function (scope, element, attrs, ctrl) {
      ctrl.$formatters.splice(0, ctrl.$formatters.length);
      ctrl.$parsers.splice(0, ctrl.$parsers.length);
      ctrl.$formatters.push(function (modelValue) {
        if (!modelValue) {
          return;
        }
        return new Date(modelValue).toISOString().slice(0,10);
      });
      ctrl.$parsers.push(function (modelValue) {
        return modelValue;
      });
    }
  };
});
