Skip to content

Commit

Permalink
feat: swap from and to if not chronological
Browse files Browse the repository at this point in the history
  • Loading branch information
kptdobe committed Sep 23, 2024
1 parent f65dd9d commit f2d37d5
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions tools/rum/elements/daterange-picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,18 +279,26 @@ export default class TimeRangePicker extends HTMLElement {

dropdownElement.hidden = true;

let dateFrom = new Date(from);
let dateTo = new Date(to);
if (dateFrom > dateTo) {
// swap the 2 dates
dateFrom = new Date(to);
dateTo = new Date(from);
}

if (from) {
fromElement.value = toDateString(new Date(from));
fromElement.value = toDateString(dateFrom);
}

if (to) {
toElement.value = toDateString(new Date(to));
toElement.value = toDateString(dateTo);
}

this.updateTimeframe({
value,
from,
to,
from: this.fromElement.value,
to: this.toElement.value,
});

this.dispatchEvent(new Event('change', {
Expand Down

0 comments on commit f2d37d5

Please sign in to comment.