<commit_before>import {
  Injectable,
} from '@angular/core';

/** Whether the browser supports the Intl API. */
const SUPPORTS_INTL_API = !!Intl;

/** Creates an array and fills it with values. */
function range<T>(length: number, valueFunction: (index: number) => T): T[] {
  return Array.apply(null, Array(length)).map((v: undefined, i: number) => valueFunction(i));
}

/** Date locale info. TODO(mmalerba): Integrate with i18n solution once we know what we're doing. */
@Injectable()
export class DateLocale {
  formatDate: (date: Date) => string;
  parseDate(value: any) {
    if (value instanceof Date) {
      return value;
    }
    let timestamp = typeof value == 'number' ? value : Date.parse(value);
    return isNaN(timestamp) ? null : new Date(timestamp);
  }
  dates = [null].concat(
    SUPPORTS_INTL_API ? this._createDatesArray('numeric') : range(31, i => String(i + 1)));
  private _createDatesArray(format: string) {
    let dtf = new Intl.DateTimeFormat(undefined, { day: format });
    return range(31, i => dtf.format(new Date(2017, 0, i + 1)));
  }
  getCalendarMonthHeaderLabel = this._createFormatFunction({ month: 'long', year: 'numeric' }) ||
  ((date: Date) => this.shortMonths[date.getMonth()] + ' ' + date.getFullYear());

  getCalendarYearHeaderLabel = this._createFormatFunction({ year: 'numeric' }) ||
  ((date: Date) => String(date.getFullYear()));

  private _createFormatFunction(options: Object): (date: Date) => string {
    if (SUPPORTS_INTL_API) {
      let dtf = new Intl.DateTimeFormat(undefined, options);
      return (date: Date) => dtf.format(date);
    }
    return null;
  }

  firstDayOfWeek = 0;

  months = [
    { full: 'January', short: 'Jan' },
    { full: 'February', short: 'Feb' },
    { full: 'March', short: 'Mar' },
    { full: 'April', short: 'Apr' },
    { full: 'May', short: 'May' },
    { full: 'June', short: 'Jun' },
    { full: 'July', short: 'Jul' },
    { full: 'August', short: 'Aug' },
    { full: 'September', short: 'Sep' },
    { full: 'October', short: 'Oct' },
    { full: 'November', short: 'Nov' },
    { full: 'December', short: 'Dec' },
  ];

  fullMonths = SUPPORTS_INTL_API ? this._createMonthsArray('long') :
    [
      'January',
      'February',
      'March',
      'April',
      'May',
      'June',
      'July',
      'August',
      'September',
      'October',
      'November',
      'December'
    ];

  shortMonths = SUPPORTS_INTL_API ? this._createMonthsArray('short') :
    ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];

  narrowMonths = SUPPORTS_INTL_API ? this._createMonthsArray('narrow') :
    ['J', 'F', 'M', 'A', 'M', 'J', 'J', 'A', 'S', 'O', 'N', 'D'];

  days = [
    { full: 'Sunday', short: 'Sun', xshort: 'S' },
    { full: 'Monday', short: 'Mon', xshort: 'M' },
    { full: 'Tuesday', short: 'Tue', xshort: 'T' },
    { full: 'Wednesday', short: 'Wed', xshort: 'W' },
    { full: 'Thursday', short: 'Thu', xshort: 'T' },
    { full: 'Friday', short: 'Fri', xshort: 'F' },
    { full: 'Saturday', short: 'Sat', xshort: 'S' },
  ];

  fullDays = SUPPORTS_INTL_API ? this._createDaysArray('long') :
    ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];

  shortDays = SUPPORTS_INTL_API ? this._createDaysArray('short') :
    ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];

  narrowDays = SUPPORTS_INTL_API ? this._createDaysArray('narrow') :
    ['S', 'M', 'T', 'W', 'T', 'F', 'S'];

  getDays() {
    return this.days.slice(this.firstDayOfWeek, this.days.length)
      .concat(this.days.slice(0, this.firstDayOfWeek));
  }

  getDayLabel(d: number) { return `${d}`; }

  getDateLabel(d: Date) {
    return `${this.days[d.getDay()].short}, ${this.months[d.getMonth()].short} ${d.getDate()}`;
  }

  getMonthLabel(m: number, y: number) { return `${this.months[m].full} ${y}`; }

  getYearLabel(y: number) { return `${y}`; }

  private _createMonthsArray(format: string) {
    let dtf = new Intl.DateTimeFormat(undefined, { month: format });
    return range(12, i => dtf.format(new Date(2017, i, 1)));
  }

  private _createDaysArray(format: string) {
    let dtf = new Intl.DateTimeFormat(undefined, { weekday: format });
    return range(7, i => dtf.format(new Date(2017, 0, i + 1)));
  }

}
<commit_msg>fix: usage of dynamic i18n arrays<commit_after>import {
  Injectable,
} from '@angular/core';

/** Whether the browser supports the Intl API. */
const SUPPORTS_INTL_API = !!Intl;

/** Creates an array and fills it with values. */
function range<T>(length: number, valueFunction: (index: number) => T): T[] {
  return Array.apply(null, Array(length)).map((v: undefined, i: number) => valueFunction(i));
}

/** Date locale info. TODO(mmalerba): Integrate with i18n solution once we know what we're doing. */
@Injectable()
export class DateLocale {
  formatDate: (date: Date) => string;
  parseDate(value: any) {
    if (value instanceof Date) {
      return value;
    }
    let timestamp = typeof value == 'number' ? value : Date.parse(value);
    return isNaN(timestamp) ? null : new Date(timestamp);
  }
  dates = [null].concat(
    SUPPORTS_INTL_API ? this._createDatesArray('numeric') : range(31, i => String(i + 1)));
  private _createDatesArray(format: string) {
    let dtf = new Intl.DateTimeFormat(undefined, { day: format });
    return range(31, i => dtf.format(new Date(2017, 0, i + 1)));
  }
  getCalendarMonthHeaderLabel = this._createFormatFunction({ month: 'long', year: 'numeric' }) ||
  ((date: Date) => this.shortMonths[date.getMonth()] + ' ' + date.getFullYear());

  getCalendarYearHeaderLabel = this._createFormatFunction({ year: 'numeric' }) ||
  ((date: Date) => String(date.getFullYear()));

  private _createFormatFunction(options: Object): (date: Date) => string {
    if (SUPPORTS_INTL_API) {
      let dtf = new Intl.DateTimeFormat(undefined, options);
      return (date: Date) => dtf.format(date);
    }
    return null;
  }

  firstDayOfWeek = 0;

  fullMonths = SUPPORTS_INTL_API ? this._createMonthsArray('long') :
    [
      'January',
      'February',
      'March',
      'April',
      'May',
      'June',
      'July',
      'August',
      'September',
      'October',
      'November',
      'December'
    ];

  shortMonths = SUPPORTS_INTL_API ? this._createMonthsArray('short') :
    ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];

  narrowMonths = SUPPORTS_INTL_API ? this._createMonthsArray('narrow') :
    ['J', 'F', 'M', 'A', 'M', 'J', 'J', 'A', 'S', 'O', 'N', 'D'];

  months = this.fullMonths.map((val, index) => {
      return { full: val, short: this.shortMonths[index], xshort: this.narrowMonths[index]  };
    });


  fullDays = SUPPORTS_INTL_API ? this._createDaysArray('long') :
    ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];

  shortDays = SUPPORTS_INTL_API ? this._createDaysArray('short') :
    ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];

  narrowDays = SUPPORTS_INTL_API ? this._createDaysArray('narrow') :
    ['S', 'M', 'T', 'W', 'T', 'F', 'S'];

  days = this.fullDays.map((val, index) => {
        return { full: val, short: this.shortDays[index], xshort: this.narrowDays[index] };
      });


  getDays() {
    return this.days.slice(this.firstDayOfWeek, this.days.length)
      .concat(this.days.slice(0, this.firstDayOfWeek));
  }

  getDayLabel(d: number) { return `${d}`; }

  getDateLabel(d: Date) {
    return `${this.days[d.getDay()].short}, ${this.months[d.getMonth()].short} ${d.getDate()}`;
  }

  getMonthLabel(m: number, y: number) { return `${this.months[m].full} ${y}`; }

  getYearLabel(y: number) { return `${y}`; }

  private _createMonthsArray(format: string) {
    let dtf = new Intl.DateTimeFormat(undefined, { month: format });
    return range(12, i => dtf.format(new Date(2017, i, 1)));
  }

  private _createDaysArray(format: string) {
    let dtf = new Intl.DateTimeFormat(undefined, { weekday: format });
    return range(7, i => dtf.format(new Date(2017, 0, i + 1)));
  }

}

{'fraction_non_alphanumeric': 0.19460333250435216, 'fraction_numerical': 0.0074608306391444916, 'mean_word_length': 3.706260971328262, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2470977', 'n_tokens_mistral': 2990, 'n_tokens_neox': 2818, 'n_words': 671}