select()

in src/date-picker/date-popup.tsx [114:188]


  select(changes: DatePickerChange) {
    const {range, withTime} = this.props;
    const prevActive = this.state.active;

    if (!range && !withTime) {
      this.setState({
        text: null,
        scrollDate: null,
      });
      const adjustedDate =
        changes.date &&
        set(new Date(), {
          year: changes.date.getFullYear(),
          month: changes.date.getMonth(),
          date: changes.date.getDate(),
        });
      this.props.onChange(adjustedDate);
      this.props.onComplete();
    } else if (!range && withTime) {
      const date = this.parse(this.props.date, 'date');
      const time = this.parse(this.props.time, 'time');
      const changeToSubmit = {
        date: changes.date || date,
        time: changes.time || time,
      };

      this.setState({
        active: changes.date ? 'time' : 'date',
        text: null,
        scrollDate: null,
      });

      this.props.onChange(changeToSubmit);
      if (!changes.date && prevActive === 'time' && changeToSubmit.date && changeToSubmit.time) {
        this.props.onComplete();
      }
    } else {
      let {from, to} = {
        ...this.props,
        ...changes,
      };
      from = this.parse(from, 'from');
      to = this.parse(to, 'to');

      // proceed to setting the end by default
      let active: Field = 'to';
      let complete = false;

      // end is before beginning
      if (from && to && isAfter(startOfDay(from), startOfDay(to))) {
        // ignore the old end when beginning is changed
        if (changes.from) {
          to = null;

          // treat range as reverse when end is changed
        } else if (changes.to) {
          to = from;
          from = changes.to;
        }
      } else if (changes.to) {
        active = 'from';
        complete = !!from;
      }

      this.setState({
        active,
        hoverDate: null,
        text: null,
      });
      this.props.onChange({from, to});
      if (complete) {
        this.props.onComplete();
      }
    }
  }