MCPcopy Create free account
hub / github.com/UI5/webcomponents / _modifyDateValue

Method _modifyDateValue

packages/main/src/DateRangePicker.ts:496–523  ·  view source on GitHub ↗

* @override

(amount: number, unit: string, preserveDate?: boolean)

Source from the content-addressed store, hash-verified

494 * @override
495 */
496 async _modifyDateValue(amount: number, unit: string, preserveDate?: boolean) {
497 if (!this._endDateTimestamp) { // If empty or only one date -> treat as datepicker entirely
498 return super._modifyDateValue(amount, unit, preserveDate);
499 }
500
501 let caretPos: number = this._dateTimeInput.getCaretPosition()!; // caret position is always number for input of type text;
502 let newValue: string;
503
504 if (caretPos <= this.value.indexOf(this._effectiveDelimiter)) { // The user is focusing the first date -> change it and keep the second date
505 const startDateModified = modifyDateBy(CalendarDate.fromTimestamp(this._startDateTimestamp! * 1000), amount, unit, preserveDate, this._minDate, this._maxDate);
506 const newStartDateTimestamp = startDateModified.valueOf() / 1000;
507 if (newStartDateTimestamp > this._endDateTimestamp) { // dates flipped -> move the caret to the same position but on the last date
508 caretPos += Math.ceil(this.value.length / 2);
509 }
510 newValue = this._buildValue(newStartDateTimestamp, this._endDateTimestamp); // the value will be normalized so we don't try to order them here
511 } else {
512 const endDateModified = modifyDateBy(CalendarDate.fromTimestamp(this._endDateTimestamp * 1000), amount, unit, preserveDate, this._minDate, this._maxDate);
513 const newEndDateTimestamp = endDateModified.valueOf() / 1000;
514 newValue = this._buildValue(this._startDateTimestamp, newEndDateTimestamp); // the value will be normalized so we don't try to order them here
515 if (newEndDateTimestamp < this._startDateTimestamp!) { // dates flipped -> move the caret to the same position but on the first date
516 caretPos -= Math.ceil(this.value.length / 2);
517 }
518 }
519 this._updateValueAndFireEvents(newValue, true, ["change", "value-changed"]);
520
521 await renderFinished();
522 this._dateTimeInput.setCaretPosition(caretPos); // Return the caret to the previous (or the adjusted, if dates flipped) position after rendering
523 }
524
525 get _effectiveDelimiter(): string {
526 return this.delimiter || DEFAULT_DELIMITER;

Callers

nothing calls this directly

Calls 8

_buildValueMethod · 0.95
modifyDateByFunction · 0.85
renderFinishedFunction · 0.85
getCaretPositionMethod · 0.80
fromTimestampMethod · 0.80
valueOfMethod · 0.80
setCaretPositionMethod · 0.80

Tested by

no test coverage detected