Repository: ionic-team/ionic-framework
File: core/src/components/datetime/datetime.tsx (TypeScript)

Code before:
      this.closeParentOverlay();
    }
  }

  private closeParentOverlay = () => {
    const popoverOrModal = this.el.closest('ion-modal, ion-popover') as
      | HTMLIonModalElement
      | HTMLIonPopoverElement
      | null;
    if (popoverOrModal) {
      popoverOrModal.dismiss();
    }
  };

  private setWorkingParts = (parts: DatetimeParts) => {
    this.workingParts = {
      ...parts,
    };
  };

  private setActiveParts = (parts: DatetimeParts, removeDate = false) => {
    const { multiple, activePartsClone, highlightActiveParts } = this;

    /**
     * When setting the active parts, it is possible
     * to set the invalid data. For example,
     * when updating January 31 to February,
     * February 31 does not exist. As a result
     * we need to validate the active parts and
     * ensure that we are only setting valid dates.
     * Additionally, we need to update the working parts
     * too in the event that the validated parts are different.
     */
    const validatedParts = validateParts(parts);
    this.setWorkingParts(validatedParts);

    if (multiple) {
      /**
       * We read from activePartsClone here because valueChanged() only updates that,
       * so it's the more reliable source of truth. If we read from activeParts, then
       * if you click July 1, manually set the value to July 2, and then click July 3,
       * the new value would be [July 1, July 3], ignoring the value set.
       *
       * We can then pass the new value to activeParts (rather than activePartsClone)
       * since the clone will be updated automatically by activePartsChanged().
       */
      const activePartsArray = Array.isArray(activePartsClone) ? activePartsClone : [activePartsClone];
      if (removeDate) {
        this.activeParts = activePartsArray.filter((p) => !isSameDay(p, validatedParts));
      } else if (highlightActiveParts) {
        this.activeParts = [...activePartsArray, validatedParts];

Review comment (suggestion):
```suggestion
     * to set invalid data. For example,
```

Code after:
      this.closeParentOverlay();
    }
  }

  private closeParentOverlay = () => {
    const popoverOrModal = this.el.closest('ion-modal, ion-popover') as
      | HTMLIonModalElement
      | HTMLIonPopoverElement
      | null;
    if (popoverOrModal) {
      popoverOrModal.dismiss();
    }
  };

  private setWorkingParts = (parts: DatetimeParts) => {
    this.workingParts = {
      ...parts,
    };
  };

  private setActiveParts = (parts: DatetimeParts, removeDate = false) => {
    const { multiple, activePartsClone, highlightActiveParts } = this;

    /**
     * When setting the active parts, it is possible
     * to set invalid data. For example,
     * when updating January 31 to February,
     * February 31 does not exist. As a result
     * we need to validate the active parts and
     * ensure that we are only setting valid dates.
     * Additionally, we need to update the working parts
     * too in the event that the validated parts are different.
     */
    const validatedParts = validateParts(parts);
    this.setWorkingParts(validatedParts);

    if (multiple) {
      /**
       * We read from activePartsClone here because valueChanged() only updates that,
       * so it's the more reliable source of truth. If we read from activeParts, then
       * if you click July 1, manually set the value to July 2, and then click July 3,
       * the new value would be [July 1, July 3], ignoring the value set.
       *
       * We can then pass the new value to activeParts (rather than activePartsClone)
       * since the clone will be updated automatically by activePartsChanged().
       */
      const activePartsArray = Array.isArray(activePartsClone) ? activePartsClone : [activePartsClone];
      if (removeDate) {
        this.activeParts = activePartsArray.filter((p) => !isSameDay(p, validatedParts));
      } else if (highlightActiveParts) {
        this.activeParts = [...activePartsArray, validatedParts];