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: wrong date depending on timezone #668

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Changes from all 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
30 changes: 10 additions & 20 deletions tools/rum/elements/daterange-picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,8 @@ function debounce(func, wait) {
};
}

// date management
function pad(number) {
return number.toString().padStart(2, '0');
}

function toDateString(date) {
// convert date
const year = date.getFullYear();
const month = pad(date.getMonth() + 1);
const day = pad(date.getDate());

return `${year}-${month}-${day}`;
return date.toISOString().split('T')[0];
}

const STYLES = `
Expand Down Expand Up @@ -304,20 +294,20 @@ export default class TimeRangePicker extends HTMLElement {

dropdownElement.hidden = true;

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

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

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

this.updateTimeframe({
Expand Down
Loading