<commit_before>import { computed } from '@ember/object';
import TextField from '@ember/component/text-field';
import InputDefaultsMixin from 'ember-form-builder/mixins/input-defaults';

function pad(number, length = 2) {
  let result = number.toString();
  length = length - result.length;
  if (length > 0) {
    return Array(length + 1).join('0') + result;
  }
  return result;
}

function formatDate(date) {
  if (date && date.getFullYear && date.getMonth && date.getDate) {
    return pad(date.getFullYear(), 4) +
        '-' + pad(date.getMonth() + 1) +
        '-' + pad(date.getDate());
  } else {
    return null;
  }
}

export default TextField.extend(InputDefaultsMixin, {
  type: 'date',

  value: computed('modelValue', {
    get() {
      var date = this.get('modelValue');
      return formatDate(date);
    },
    set(key, value) {
      if (value.length === 0) {
        this.set('modelValue', undefined);
      } else {
        var timestamp = Date.parse(value + 'T00:00');
        if (isNaN(timestamp)) {
          return value;
        } else {
          var date = new Date(timestamp);
          this.set('modelValue', date);
          return formatDate(date);
        }
      }
    }
  })
});<commit_msg>Fixed intepreting dates<commit_after>import { computed } from '@ember/object';
import TextField from '@ember/component/text-field';
import InputDefaultsMixin from 'ember-form-builder/mixins/input-defaults';

function pad(number, length = 2) {
  let result = number.toString();
  length = length - result.length;
  if (length > 0) {
    return Array(length + 1).join('0') + result;
  }
  return result;
}

function formatDate(date) {
  if (date && date.getFullYear && date.getMonth && date.getDate) {
    return pad(date.getFullYear(), 4) +
        '-' + pad(date.getMonth() + 1) +
        '-' + pad(date.getDate());
  } else {
    return null;
  }
}

export default TextField.extend(InputDefaultsMixin, {
  type: 'date',

  value: computed('modelValue', {
    get() {
      var date = this.get('modelValue');
      return formatDate(date);
    },
    set(key, value) {
      if (value.length === 0) {
        this.set('modelValue', undefined);
      } else {
        var timestamp = Date.parse(value + 'T00:00Z');
        if (isNaN(timestamp)) {
          return value;
        } else {
          var date = new Date(timestamp);
          this.set('modelValue', date);
          return formatDate(date);
        }
      }
    }
  })
});
{'fraction_non_alphanumeric': 0.15603413246647704, 'fraction_numerical': 0.008939455505891914, 'mean_word_length': 2.5941605839416058, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2216538', 'n_tokens_mistral': 796, 'n_tokens_neox': 773, 'n_words': 172}