Skip to content

Conversation

@druchniewicz
Copy link
Contributor

Selected values in date parameters in the report were automatically treated as incorrect format.

@druchniewicz
Copy link
Contributor Author

@denniskigen this is the fix for incorrect date format that has been noticed recently by one of the user

@denniskigen denniskigen requested a review from ibacher March 13, 2025 13:39
Copy link
Member

@ibacher ibacher left a comment

Choose a reason for hiding this comment

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

Thanks @druchniewicz! Couple of suggestions for how to do this.

name={parameter.name}
labelText={parameter.label}
type="text"
pattern="\d{4}-\d{2}-\d{2}"
Copy link
Member

Choose a reason for hiding this comment

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

Strongly prefer that we don't try to enforce a pattern here at all.

Comment on lines 133 to 143
const formattedDate = formatLocalDateToString(dateValue);
setReportParameters((state) => ({ ...state, [fieldName]: formattedDate }));
}

function formatLocalDateToString(dateValue) {
const date = new Date(dateValue);
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');

return `${year}-${month}-${day}`;
Copy link
Member

Choose a reason for hiding this comment

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

We tend to prefer using dayjs, which makes this relatively easy, but for preference, we should be using the functions built into the framework such as formatDate to avoid hard-coding date formats and calendars where they are not appropriate.

@druchniewicz
Copy link
Contributor Author

@denniskigen @ibacher PR updated. Can you take a look?

@druchniewicz
Copy link
Contributor Author

@ibacher @denniskigen

@druchniewicz
Copy link
Contributor Author

@ibacher @denniskigen PR corrected, can you take a look?

@druchniewicz
Copy link
Contributor Author

@ibacher @denniskigen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants