<commit_before>'use strict';

import React, { Component, View } from 'react-native';
import WheelView from 'react-native-wheel';
import makeRange from '../utils/make-range';

const MILLIS_DAY = 86400000;
const MINDATE = new Date(1999, 11, 31, 0, 0, 0, 0);
const MAXDATE = new Date(new Date().getFullYear() + 25, 11, 31, 0, 0, 0, 0);

const dateRange = () => {
  let dates = [];
  let start = MINDATE.getTime();
  let end = MAXDATE.getTime();

  for (start; start <= end; start += MILLIS_DAY) {
    dates.push(new Date(start));
  }

  return dates;
};

const renderDates = (dates) => {
  const today = new Date();
  const thisYear = today.getFullYear();
  const thisMonth = today.getMonth();
  const thisDay = today.getDate();
  const todayStart = new Date(thisYear, thisMonth, thisDay, 0, 0, 0 ,0);
  const todayEnd = new Date(thisYear, thisMonth, thisDay, 23, 59, 59, 999);
  let year;
  return dates.map((date) => {
    if (todayStart <= date && todayEnd > date) {
      return "Today";
    } else {
      return date.toDateString().replace(/\s\d*?$/, "");
    }
  });
};

var dates = [];
var dateStrings = [];
const hours = makeRange(1, 12);
var minutes = [];
const ampm = ['AM', 'PM'];

export default class DateTimePicker extends Component {
  constructor(props) {
    super(props);
    const { minuteInterval, date } = props;
    let dateIndices = this.getDateIndices(date);
    minutes = makeRange(0, 59, minuteInterval, true);
    dates = dateRange(props);
    dateStrings = renderDates(dates);

    this.state = dateIndices;
  }

  getDateIndices(date) {
    const { minuteInterval } = this.props;
    let dateIndex = date.getTime() - MINDATE.getTime();
    dateIndex = Math.floor(dateIndex / MILLIS_DAY);
    let hourIndex = date.getHours() % 12;
    const ampmIndex = hourIndex === date.getHours() ? 0 : 1;
    hourIndex = hourIndex === 0 ? 11 : hourIndex - 1;
    const minuteIndex = Math.floor(date.getMinutes() / minuteInterval);

    return {
      dateIndex,
      hourIndex,
      minuteIndex,
      ampmIndex
    };
  }

  setDateState(date) {
    const { onDateChange } = this.props;
    const minimumDate = this.props.minimumDate || MINDATE;
    const maximumDate = this.props.maximumDate || MAXDATE;

<commit_msg>allow min and max displayDate to be specified<commit_after>'use strict';

import React, { Component, View } from 'react-native';
import WheelView from 'react-native-wheel';
import makeRange from '../utils/make-range';

const MILLIS_DAY = 86400000;
const MINDATE = new Date(1999, 11, 31, 0, 0, 0, 0);
const MAXDATE = new Date(new Date().getFullYear() + 25, 11, 31, 0, 0, 0, 0);

const dateRange = ({ minDisplayDate, maxDisplayDate }) => {
  let dates = [];
  let start = minDisplayDate ? minDisplayDate.getTime() : MINDATE.getTime();
  let end = maxDisplayDate ? maxDisplayDate.getTime() : MAXDATE.getTime();

  for (start; start <= end; start += MILLIS_DAY) {
    dates.push(new Date(start));
  }

  return dates;
};

const renderDates = (dates) => {
  const today = new Date();
  const thisYear = today.getFullYear();
  const thisMonth = today.getMonth();
  const thisDay = today.getDate();
  const todayStart = new Date(thisYear, thisMonth, thisDay, 0, 0, 0 ,0);
  const todayEnd = new Date(thisYear, thisMonth, thisDay, 23, 59, 59, 999);
  let year;
  return dates.map((date) => {
    if (todayStart <= date && todayEnd > date) {
      return "Today";
    } else {
      return date.toDateString().replace(/\s\d*?$/, "");
    }
  });
};

var dates = [];
var dateStrings = [];
const hours = makeRange(1, 12);
var minutes = [];
const ampm = ['AM', 'PM'];

export default class DateTimePicker extends Component {
  constructor(props) {
    super(props);
    const { minuteInterval, date } = props;
    let dateIndices = this.getDateIndices(date);
    minutes = makeRange(0, 59, minuteInterval, true);
    dates = dateRange(props);
    dateStrings = renderDates(dates);

    this.state = dateIndices;
  }

  getDateIndices(date) {
    const { minuteInterval, minDisplayDate } = this.props;
    const minDate = minDisplayDate || MINDATE;

    let dateIndex = date.getTime() - minDate.getTime();
    dateIndex = Math.floor(dateIndex / MILLIS_DAY);
    let hourIndex = date.getHours() % 12;
    const ampmIndex = hourIndex === date.getHours() ? 0 : 1;
    hourIndex = hourIndex === 0 ? 11 : hourIndex - 1;
    const minuteIndex = Math.floor(date.getMinutes() / minuteInterval);

    return {
      dateIndex,
      hourIndex,
      minuteIndex,
      ampmIndex
    };
  }

  setDateState(date) {
    const { minDisplayDate, maxDisplayDate, onDateChange } = this.props;
    const minimumDate = this.props.minimumDate || minDisplayDate || MINDATE;
    const maximumDate = this.props.maximumDate || maxDisplayDate || MAXDATE;


{'fraction_non_alphanumeric': 0.1430374421539756, 'fraction_numerical': 0.023979806478754733, 'mean_word_length': 3.4731890874882407, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, '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': '792608', 'n_tokens_mistral': 1649, 'n_tokens_neox': 1532, 'n_words': 420}