-
Notifications
You must be signed in to change notification settings - Fork 24
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
base: main
Are you sure you want to change the base?
Conversation
@denniskigen this is the fix for incorrect date format that has been noticed recently by one of the user |
There was a problem hiding this 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}" |
There was a problem hiding this comment.
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.
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}`; |
There was a problem hiding this comment.
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.
@denniskigen @ibacher PR updated. Can you take a look? |
@ibacher @denniskigen PR corrected, can you take a look? |
Selected values in date parameters in the report were automatically treated as incorrect format.