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

change format date view #2640

Conversation

vibros68
Copy link
Contributor

@vibros68 vibros68 commented Oct 26, 2021

Closes #2634

This diff change the date view format of proposal from 9/8/2021 to
08 Sep 2021
Screenshot from 2021-10-26 11-08-13

@vibros68
Copy link
Contributor Author

@lukebp ready for review

Copy link
Member

@lukebp lukebp left a comment

Choose a reason for hiding this comment

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

UX tACK on firefox.

Needs code approval from @tiagoalvesdulce.

Copy link
Member

@victorgcramos victorgcramos left a comment

Choose a reason for hiding this comment

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

Hey vibros, thanks for the PR. Looking good and working as expected. Left some minor inline suggestions. Would be nice if you add some tests for the formatDateView method.

Also, I'm not a big fan of formatDateView naming... It doesn't give much information about what this method does, and how can it be used. Maybe something like getInternationalDateString as it is described on #2634.

PS: You pointed your PR to the wrong issue number 😅

@@ -47,20 +48,21 @@ const DatePickerField = ({
};

const formattedValue = () => {
console.log(value);
Copy link
Member

Choose a reason for hiding this comment

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

log

src/helpers.js Outdated
@@ -619,3 +620,8 @@ export const calculateAuthorUpdateTree = (authorUpdateId, comments) => {
}
return allTreeComments;
};

export const formatDateView = (value) => {
Copy link
Member

Choose a reason for hiding this comment

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

can we add unit tests for this helper? Please make sure this method works for falsy values (undefined, null...). What if value has no day prop? And what if no month prop? Will the retuned string behave correctly if an unexpected argument is passed?

IMO, value is not a good name. Maybe you can use prop destruction to make the arguments more readable and control the default values.

Suggested change
export const formatDateView = (value) => {
export const formatDateView = ({ day, month, year }) => {

Also, could you please add a more descriptive documentation for this method? Like the ones we already have on our src/helpers for other methods?

src/helpers.js Outdated
@@ -619,3 +620,8 @@ export const calculateAuthorUpdateTree = (authorUpdateId, comments) => {
}
return allTreeComments;
};

export const formatDateView = (value) => {
const dayView = ("0" + value.day).slice(-2);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const dayView = ("0" + value.day).slice(-2);
const dayView = `0${value.day}`.slice(-2);

template strings 😁

Copy link
Member

@victorgcramos victorgcramos left a comment

Choose a reason for hiding this comment

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

ACK!

@lukebp
Copy link
Member

lukebp commented Oct 28, 2021

Needs approval from @tiagoalvesdulce.

Copy link
Member

@tiagoalvesdulce tiagoalvesdulce left a comment

Choose a reason for hiding this comment

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

I left a comment.

src/helpers.js Outdated
* @returns {string}
*/
export const getInternationalDateString = ({ day, month, year }) => {
if (day >= 1 && day <= 31 && month >= 1 && month <= 12 && year >= 1) {
Copy link
Member

Choose a reason for hiding this comment

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

This isn't a good way to validate date formats. You are not accounting leap years, that February doesn't have more than 29 days, etc. This should be fine because we can assume startDate, endDate as well as the dates from the DatePicker are always valid. But poor validation is confusing and we can improve it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. I have been thinking about this problem. May be we should avoid to convert the date value from the inconsistent values of day, month and year and use the timestamp as the input of the function. How do you think @tiagoalvesdulce ?

Copy link
Member

Choose a reason for hiding this comment

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

I think that's overkill, we would have to convert the date object 2 times. You can:

  1. Rename this function to formatDateToInternationalString. Format is better than get because you are just formatting the date the way you would like to show it.
  2. Do not validate day and year. Remember, you are just formatting what the user wants to see in the screen.
  3. Validate month because you are using MONTHS_LABELS so you don't want to access an out-of-range index and crash the application.
  4. This function is only to show the day, year and month in the desired format. All values should've been validated before (in the DatePicker or in the BE).
  5. Explain why you are not validating the values in the function documentation.

As an alternative, if you want to do the values validation, do it completely, like: https://stackoverflow.com/a/6178341/8903047

Copy link
Member

@tiagoalvesdulce tiagoalvesdulce left a comment

Choose a reason for hiding this comment

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

LGTM

@tiagoalvesdulce tiagoalvesdulce merged commit 6611139 into decred:master Nov 1, 2021
@vibros68 vibros68 mentioned this pull request Nov 18, 2021
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.

International date format for start and end dates
4 participants