<commit_before>import Peg = require('../models/peg');

class PegStoreService {
  pegs: Array<Peg>;

  constructor() {
    this.pegs = [
      { peg: false, date: '2015-01-09', value: 750, note: 'カレー' },
      { peg: false, date: '2015-01-07', value: 800, note: 'きつねうどんていしょく' },
      { peg: false, date: '2015-01-06', value: 700, note: 'ぎょうざていしょく' },
      { peg: true, date: '2015-01-05', value: 3500, unknown: 5000, note: null },
      { peg: false, date: '2015-01-02', value: 1500, note: 'はつもうで' },
      { peg: true, date: '2015-01-01', value: 10000, unknown: 0, note: 'おとしだま直後' }
    ];
  }

  insert(index: number, peg: Peg): void {
    var sum = (array: Array<{ value: number }>): number => {
      return array.reduce(((r, i) => r + i.value), 0);
    };
<commit_msg>add date validation<commit_after>/// <reference path="../../../typings/moment/moment.d.ts" />

import Peg = require('../models/peg');

class PegStoreService {
  pegs: Array<Peg>;

  constructor() {
    this.pegs = [
      { peg: false, date: '2015-01-09', value: 750, note: 'カレー' },
      { peg: false, date: '2015-01-07', value: 800, note: 'きつねうどんていしょく' },
      { peg: false, date: '2015-01-06', value: 700, note: 'ぎょうざていしょく' },
      { peg: true, date: '2015-01-05', value: 3500, unknown: 5000, note: null },
      { peg: false, date: '2015-01-02', value: 1500, note: 'はつもうで' },
      { peg: true, date: '2015-01-01', value: 10000, unknown: 0, note: 'おとしだま直後' }
    ];
  }

  insert(index: number, peg: Peg): void {
    var sum = (array: Array<{ value: number }>): number => {
      return array.reduce(((r, i) => r + i.value), 0);
    };

    if (index < 0 || this.pegs.length < index) return;

    var date = moment(peg.date);
    var dateIsValid = (
      date.isSame(this.pegs[index - 1].date, 'days') ||
      date.isBefore(this.pegs[index - 1].date, 'days')
    ) && (
      index === this.pegs.length ||
      date.isSame(this.pegs[index].date, 'days') ||
      date.isAfter(this.pegs[index].date, 'days')
    );
    if (!dateIsValid) return;

{'fraction_non_alphanumeric': 0.20769610261470153, 'fraction_numerical': 0.07646768623581648, 'mean_word_length': 2.8264150943396227, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 12, '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': '2637377', 'n_tokens_mistral': 913, 'n_tokens_neox': 780, 'n_words': 189}