Repository: hashicorp/vault
File: ui/app/components/clients/date-range.ts (TypeScript)

Code before:
    this.endDate = '';
  }

  @action updateDate(evt: HTMLElementEvent<HTMLInputElement>) {
    const { name, value } = evt.target;
    if (name === 'end') {
      this.modalEnd = value;
    } else {
      this.modalStart = value;
    }
  }

  // used for CE date picker
  @action handleSave() {
    if (this.validationError) return;
    const params: OnChangeParams = {
      start_time: undefined,
      end_time: undefined,
    };
    this.startDate = this.modalStart;
    this.endDate = this.modalEnd;

    let year, month;
    [year, month] = this.startDate.split('-');
    if (year && month) {
      params.start_time = formatDateObject({ monthIdx: parseInt(month) - 1, year: parseInt(year) }, false);
    }
    [year, month] = this.endDate.split('-');
    if (year && month) {
      params.end_time = formatDateObject({ monthIdx: parseInt(month) - 1, year: parseInt(year) }, true);
    }

    this.args.onChange(params);
    this.onClose();
  }

  @action
  updateEnterpriseDateRange(start: string) {
    const params: OnChangeParams = {
      start_time: undefined,
      end_time: undefined,
    };

    const [year, month] = start.split('-');
    if (year && month) {
      // pass true for isEnd even for start because we want to go off last day of month here, otherwise we risk
      // setting it to a start_time that is for the previous billing period
      params.start_time = formatDateObject({ monthIdx: parseInt(month) - 1, year: parseInt(year) }, true);
    }

    this.args.onChange(params);

Review comment (suggestion):
Ensuring that `parseInt` uses base 10. If you don't supply the second param (the radix) the method infers it from the first value, which can potentially lead to unexpected results ex: if we allowed `0x` as the string this would be considered hex and thus 16 would be the radix deferred value. It's for sure on the cautious side, but easy to account for.
```suggestion
      params.start_time = formatDateObject({ monthIdx: parseInt(month, 10) - 1, year: parseInt(year, 10) }, false);
```

Code after:
    this.endDate = '';
  }

  @action updateDate(evt: HTMLElementEvent<HTMLInputElement>) {
    const { name, value } = evt.target;
    if (name === 'end') {
      this.modalEnd = value;
    } else {
      this.modalStart = value;
    }
  }

  // used for CE date picker
  @action handleSave() {
    if (this.validationError) return;
    const params: OnChangeParams = {
      start_time: undefined,
      end_time: undefined,
    };
    this.startDate = this.modalStart;
    this.endDate = this.modalEnd;

    let year, month;
    [year, month] = this.startDate.split('-');
    if (year && month) {
      params.start_time = formatDateObject({ monthIdx: Number(month) - 1, year: Number(year) }, false);
    }
    [year, month] = this.endDate.split('-');
    if (year && month) {
      params.end_time = formatDateObject({ monthIdx: Number(month) - 1, year: Number(year) }, true);
    }

    this.args.onChange(params);
    this.onClose();
  }

  @action
  updateEnterpriseDateRange(start: string) {
    const params: OnChangeParams = {
      start_time: undefined,
      end_time: undefined,
    };

    const [year, month] = start.split('-');
    if (year && month) {
      // pass true for isEnd even for start because we want to go off last day of month here, otherwise we risk
      // setting it to a start_time that is for the previous billing period
      params.start_time = formatDateObject({ monthIdx: parseInt(month) - 1, year: parseInt(year) }, true);
    }

    this.args.onChange(params);