Skip to content

Commit ad365f4

Browse files
authored
refactor(ui5-daterange-picker): rename first/lastDateValue (#3397)
Part of #3107 (comment) BREAKING_CHANGE: The readonly properties `firstDateValue` and `lastDateValue` have been renamed to `startDateValue` and `endDateValue`.
1 parent e591e04 commit ad365f4

File tree

2 files changed

+26
-26
lines changed

2 files changed

+26
-26
lines changed

packages/main/src/DateRangePicker.js

+18-18
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ class DateRangePicker extends DatePicker {
8484
return [DatePicker.styles, DateRangePickerCss];
8585
}
8686

87-
get _firstDateTimestamp() {
87+
get _startDateTimestamp() {
8888
return this._extractFirstTimestamp(this.value);
8989
}
9090

91-
get _lastDateTimestamp() {
91+
get _endDateTimestamp() {
9292
return this._extractLastTimestamp(this.value);
9393
}
9494

@@ -109,7 +109,7 @@ class DateRangePicker extends DatePicker {
109109
* @override
110110
*/
111111
get _calendarTimestamp() {
112-
return this._tempTimestamp || this._firstDateTimestamp || getTodayUTCTimestamp(this._primaryCalendarType);
112+
return this._tempTimestamp || this._startDateTimestamp || getTodayUTCTimestamp(this._primaryCalendarType);
113113
}
114114

115115
/**
@@ -127,25 +127,25 @@ class DateRangePicker extends DatePicker {
127127
}
128128

129129
/**
130-
* Currently selected first date represented as JavaScript Date instance.
130+
* Returns the start date of the currently selected range as JavaScript Date instance.
131131
*
132132
* @readonly
133133
* @type { Date }
134134
* @public
135135
*/
136-
get firstDateValue() {
137-
return CalendarDate.fromTimestamp(this._firstDateTimestamp * 1000).toLocalJSDate();
136+
get startDateValue() {
137+
return CalendarDate.fromTimestamp(this._startDateTimestamp * 1000).toLocalJSDate();
138138
}
139139

140140
/**
141-
* Currently selected last date represented as JavaScript Date instance.
141+
* Returns the end date of the currently selected range as JavaScript Date instance.
142142
*
143143
* @readonly
144144
* @type { Date }
145145
* @public
146146
*/
147-
get lastDateValue() {
148-
return CalendarDate.fromTimestamp(this._lastDateTimestamp * 1000).toLocalJSDate();
147+
get endDateValue() {
148+
return CalendarDate.fromTimestamp(this._endDateTimestamp * 1000).toLocalJSDate();
149149
}
150150

151151
/**
@@ -231,7 +231,7 @@ class DateRangePicker extends DatePicker {
231231
* @override
232232
*/
233233
async _modifyDateValue(amount, unit) {
234-
if (!this._lastDateTimestamp) { // If empty or only one date -> treat as datepicker entirely
234+
if (!this._endDateTimestamp) { // If empty or only one date -> treat as datepicker entirely
235235
return super._modifyDateValue(amount, unit);
236236
}
237237

@@ -240,17 +240,17 @@ class DateRangePicker extends DatePicker {
240240
let newValue;
241241

242242
if (caretPos <= this.value.indexOf(this._effectiveDelimiter)) { // The user is focusing the first date -> change it and keep the seoond date
243-
const firstDateModified = modifyDateBy(CalendarDate.fromTimestamp(this._firstDateTimestamp * 1000), amount, unit, this._minDate, this._maxDate);
244-
const newFirstDateTimestamp = firstDateModified.valueOf() / 1000;
245-
if (newFirstDateTimestamp > this._lastDateTimestamp) { // dates flipped -> move the caret to the same position but on the last date
243+
const startDateModified = modifyDateBy(CalendarDate.fromTimestamp(this._startDateTimestamp * 1000), amount, unit, this._minDate, this._maxDate);
244+
const newStartDateTimestamp = startDateModified.valueOf() / 1000;
245+
if (newStartDateTimestamp > this._endDateTimestamp) { // dates flipped -> move the caret to the same position but on the last date
246246
caretPos += Math.ceil(this.value.length / 2);
247247
}
248-
newValue = this._buildValue(newFirstDateTimestamp, this._lastDateTimestamp); // the value will be normalized so we don't try to order them here
248+
newValue = this._buildValue(newStartDateTimestamp, this._endDateTimestamp); // the value will be normalized so we don't try to order them here
249249
} else {
250-
const lastDateModified = modifyDateBy(CalendarDate.fromTimestamp(this._lastDateTimestamp * 1000), amount, unit, this._minDate, this._maxDate);
251-
const newLastDateTimestamp = lastDateModified.valueOf() / 1000;
252-
newValue = this._buildValue(this._firstDateTimestamp, newLastDateTimestamp); // the value will be normalized so we don't try to order them here
253-
if (newLastDateTimestamp < this._firstDateTimestamp) { // dates flipped -> move the caret to the same position but on the first date
250+
const endDateModified = modifyDateBy(CalendarDate.fromTimestamp(this._endDateTimestamp * 1000), amount, unit, this._minDate, this._maxDate);
251+
const newEndDateTimestamp = endDateModified.valueOf() / 1000;
252+
newValue = this._buildValue(this._startDateTimestamp, newEndDateTimestamp); // the value will be normalized so we don't try to order them here
253+
if (newEndDateTimestamp < this._startDateTimestamp) { // dates flipped -> move the caret to the same position but on the first date
254254
caretPos -= Math.ceil(this.value.length / 2);
255255
}
256256
}

packages/main/test/specs/DateRangePicker.spec.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe("DateRangePicker general interaction", () => {
4141
assert.strictEqual(daterangepicker.getProperty("delimiter"), "@", "The delimiter is set to @");
4242
});
4343

44-
it("firstDateValue and lastDateValue getter", () => {
44+
it("startDateValue and endDateValue getter", () => {
4545
browser.url(`http://localhost:${PORT}/test-resources/pages/DateRangePicker.html`);
4646
const daterangepicker = browser.$("#daterange-picker4");
4747

@@ -51,28 +51,28 @@ describe("DateRangePicker general interaction", () => {
5151

5252
const res = browser.execute(() => {
5353
const myDRP = document.getElementById("daterange-picker4");
54-
const firstDateValue = myDRP.firstDateValue;
55-
const lastDateValue = myDRP.lastDateValue;
54+
const startDateValue = myDRP.startDateValue;
55+
const endDateValue = myDRP.endDateValue;
5656

57-
return {firstDateValue, lastDateValue};
57+
return {startDateValue, endDateValue};
5858
});
5959

60-
assert.deepEqual(new Date(res.firstDateValue), new Date(2019, 8, 27), "The first date is in JS Date format");
61-
assert.deepEqual(new Date(res.lastDateValue), new Date(2019, 9, 10), "The last date is JS Date format");
60+
assert.deepEqual(new Date(res.startDateValue), new Date(2019, 8, 27), "The first date is in JS Date format");
61+
assert.deepEqual(new Date(res.endDateValue), new Date(2019, 9, 10), "The last date is JS Date format");
6262
});
6363

6464
it("Initially setting the same date as first & last is possible", () => {
6565
const daterangepicker = browser.$("#daterange-picker5");
6666

67-
assert.strictEqual(daterangepicker.getProperty("firstDateValue"), daterangepicker.getProperty("lastDateValue"), "Initially properties are set correctly");
67+
assert.strictEqual(daterangepicker.getProperty("startDateValue"), daterangepicker.getProperty("endDateValue"), "Initially properties are set correctly");
6868
});
6969

7070
it("Setting the same date as first & last is possible", () => {
7171
const daterangepicker = browser.$("#daterange-picker5");
7272

7373
daterangepicker.setProperty("value", "Aug 5, 2020 - Aug 5, 2020");
7474

75-
assert.strictEqual(daterangepicker.getProperty("firstDateValue"), daterangepicker.getProperty("lastDateValue"), "Properties are set correctly");
75+
assert.strictEqual(daterangepicker.getProperty("startDateValue"), daterangepicker.getProperty("endDateValue"), "Properties are set correctly");
7676
})
7777

7878
it("Change event fired once", () => {

0 commit comments

Comments
 (0)