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

Improve logic for when to normalize date in DateInput #5942

Merged
merged 8 commits into from Feb 24, 2022

Conversation

taysea
Copy link
Collaborator

@taysea taysea commented Feb 10, 2022

What does this PR do?

When DateInput value starts as undefined, the onChange logic should be in UTC relative to the local timezone of the user. In these instances, we don't want to perform the subsequent normalization logic. This PR introduces a state variable in dateinput that is passed ot the normalization functions. When it is true, we proceed with normalization. When it is false, we don't normalize because the date is already in UTC with respect to the timezone.

Where should the reviewer start?

DateInput.js

What testing has been done on this PR?

Format Inline story in timezones before UTC and after (for example, pacific time and eastern european.

How should this be manually tested?

With FormatInline story in various timezones.

Do Jest tests follow these best practices?

N/A did not touch tests aside from fixing a test that did not have defaultValue in ISO8601 format.

  • screen is used for querying.
  • The correct query is used. (Refer to this list of queries)
  • userEvent is used in place of fireEvent.
  • asFragment() is used for snapshot testing.

Any background context you want to provide?

What are the relevant issues?

Closes #5920

Screenshots (if appropriate)

Do the grommet docs need to be updated?

No.

Should this PR be mentioned in the release notes?

Yes.

Is this change backwards compatible or is it a breaking change?

Backwards compatible.

Copy link
Member

@ericsoderberghp ericsoderberghp left a comment

Choose a reason for hiding this comment

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

The basic direction seems to be holding up. It does feel a bit complicated, but I'm not sure how to simplify it.

src/js/components/DateInput/DateInput.js Show resolved Hide resolved
src/js/components/DateInput/DateInput.js Show resolved Hide resolved
Copy link
Collaborator

@MikeKingdom MikeKingdom left a comment

Choose a reason for hiding this comment

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

I think it looks good. I'm trying to think of how to simplify this in general but it's hard to. I'd rather see the normalize flag not go so deep through so many calls and isolate it more to the initial look at defaultValue and value.

Really it feels like the crux of the problem is caring about timezone at all when all we're trying to do is choose a day/month/year. That seems to boil down to how we accept an iso8601 string with all that info in it and try to maintain that format through the api even though we don't really use the time aspect or intentionally convert between timezones. Changing that would probably be breaking.

src/js/components/Calendar/utils.js Show resolved Hide resolved
@taysea taysea marked this pull request as draft February 18, 2022 20:39
@taysea taysea marked this pull request as ready for review February 18, 2022 23:07
Copy link
Member

@ericsoderberghp ericsoderberghp left a comment

Choose a reason for hiding this comment

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

Am I right that this set of changes is just carrying into Calendar the sorts of things we were working on within DateInput already?

Just a few comments, nothing major.

src/js/components/Calendar/Calendar.js Show resolved Hide resolved
src/js/components/Calendar/Calendar.js Show resolved Hide resolved
} else if (date && Array.isArray(date)) {
setDate(nextDates);
}
setActive(new Date(selectedDate));
if (onSelect) {
// output date with no timestamp if that's how user provided it
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 move all of this conversion logic into a separate utility function? I think that would make this callback code a bit easier to follow.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I separated this out into its own function. Additionally, I was able to remove blocks of this logic that were never being entered (confirmed via manual testing and coverage analysis in jest).

src/js/components/DateInput/DateInput.js Outdated Show resolved Hide resolved
src/js/components/DateInput/DateInput.js Outdated Show resolved Hide resolved
@taysea
Copy link
Collaborator Author

taysea commented Feb 21, 2022

Am I right that this set of changes is just carrying into Calendar the sorts of things we were working on within DateInput already?

Yes, you are exactly correct.

Copy link
Collaborator

@MikeKingdom MikeKingdom left a comment

Choose a reason for hiding this comment

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

Looks great. Thanks!

Copy link
Member

@ericsoderberghp ericsoderberghp left a comment

Choose a reason for hiding this comment

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

nice improvements!

@ericsoderberghp ericsoderberghp merged commit 0d5b9dc into grommet:master Feb 24, 2022
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.

DateInput selects previous Day on timezone UTC+1
3 participants