Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ui5-daterange-picker): working with format pattern containing the delimiter #2873

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion packages/main/src/DateRangePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,18 @@ class DateRangePicker extends DatePicker {
}

_splitValueByDelimiter(value) {
return value.split(this._effectiveDelimiter).map(date => date.trim()); // just split by delimiter and trim spaces
let valuesArray = [];

if (this.getFormat().oFormatOptions.pattern.indexOf(this._effectiveDelimiter) >= 0) {
const midIndex = Math.round(value.length / 2);

valuesArray[0] = value.slice(0, midIndex).split(this._effectiveDelimiter).join("").trim();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.split(this._effectiveDelimiter).join("") -> this will remove all "-"s from the first part
same for the second part
Try running the function with "2020/01/01 - 2021/02/02" f.e.
You'll end up with "20200101" and "20210202" respectively.

IMO just get the mid index, everything from 0 to midIndex - 1 is the first part, and after mid index the second.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is done, because "2020/01/01 -" can't be formatted with our formatter, but 20200101 can. That's why i am removing the symbols that are breaking the formatting.

valuesArray[1] = value.slice(midIndex, value.length).split(this._effectiveDelimiter).join("").trim();
} else {
valuesArray = value.split(this._effectiveDelimiter).map(date => date.trim()); // just split by delimiter and trim spaces;
}

return valuesArray;
}

/**
Expand Down
6 changes: 4 additions & 2 deletions packages/main/test/pages/DateRangePicker.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ <h3>daterange-picker in Compact</h3>
<ui5-daterange-picker id="daterange-picker5" delimiter="@"></ui5-daterange-picker>
</div>
</section>

<h3>daterange-picker with format pattern yyyy-MM-ddy</h3>
<ui5-daterange-picker id="daterange-picker6" format-pattern="yyyy-MM-dd"></ui5-daterange-picker>
<h3>DateRange Picker with one date selected as first & last</h3>
<ui5-daterange-picker id="daterange-picker5" value="Aug 20, 2020 - Aug 20, 2020"></ui5-daterange-picker>
<ui5-daterange-picker id="daterange-picker7" value="Aug 20, 2020 - Aug 20, 2020"></ui5-daterange-picker>

</div>
<script>
document.getElementById('daterange-picker1').addEventListener('ui5-change', function(e) {
Expand Down
11 changes: 11 additions & 0 deletions packages/main/test/specs/DateRangePicker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,15 @@ describe("DateRangePicker general interaction", () => {
assert.strictEqual(dateRangePicker.getAttribute("value"), "Jul 16, 2020 @ Jul 17, 2020");
});

it("Delimiter is part of the format pattern", () => {
browser.url("http://localhost:8080/test-resources/pages/DateRangePicker.html");
const daterangepicker = browser.$("#daterange-picker6");

daterangepicker.click();
daterangepicker.keys("09-09-2020 - 10-10-2020");
daterangepicker.keys("Enter");

assert.strictEqual(daterangepicker.shadow$("ui5-input").getProperty("valueState"), "None", "The value state is on none");
});

});