Skip to content

O3-1494: Fixed invalid format in date parameters #66

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

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