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

[DateRangeInput] Add allowSingleDayRange prop #861

Merged
merged 6 commits into from
Mar 21, 2017

Conversation

cmslewis
Copy link
Contributor

@cmslewis cmslewis commented Mar 17, 2017

Addresses #805

Checklist

  • Include tests
  • Update documentation

Changes proposed in this pull request:

  • Add allowSingleDayRange prop to DateRangeInput
  • Add unit tests
  • Add toggle to example

Reviewers should focus on

  • Tricky date comparison logic that needs to ignore hours/minutes/seconds/millis.
  • Modified overlapping-dates logic.

Screenshot

2017-03-17 16 16 38

@cmslewis cmslewis mentioned this pull request Mar 17, 2017
8 tasks
@blueprint-bot
Copy link

Add toggle to DateRangeInput example

Preview: docs
Coverage: core | datetime

Copy link
Contributor

@giladgray giladgray 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 we have this util already? DateUtils.areSameDay

return [startDate, (startDate >= endDate) ? null : endDate] as DateRange;
const selectedRange = this.props.allowSingleDayRange
? [startDate, (clearTime(startDate) > clearTime(endDate)) ? null : endDate]
: [startDate, (clearTime(startDate) >= clearTime(endDate)) ? null : endDate];
Copy link
Contributor

Choose a reason for hiding this comment

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

what about DateUtils.areSameDay? that's what DateRangePicker uses to implement this prop.

Copy link
Contributor

Choose a reason for hiding this comment

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

wait but actually... why does this get reimplemented here? can we not rely on DRP's own allowSingleDayRange prop implementation?

Copy link
Contributor Author

@cmslewis cmslewis Mar 18, 2017

Choose a reason for hiding this comment

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

Yeah there's a little duplication between the implementation for the next-selected dates on click and the next focused fields on click (and still more duplication/logic overlap for validation).

But you're right: the basic way to check this is !DateUtils.areSameDay(startDate, endDate) && startDate > endDate. Will edit.


// deselect current end date
getDayElement(END_DAY).simulate("click");

Copy link
Contributor

Choose a reason for hiding this comment

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

such whitespace. i mean whatever, but i like keeping blocks of interaction between asserts together.

@cmslewis cmslewis force-pushed the cl/dri-allow-single-day-range branch from 055a7a9 to d869942 Compare March 20, 2017 23:17
@cmslewis
Copy link
Contributor Author

@giladgray ready for re-review

@blueprint-bot
Copy link

Delete now-unused clearUtils function

Preview: docs | table
Coverage: core | datetime


// this helper function checks if the provided boundary date *would* overlap the selected
// other boundary date. providing the already-selected start date simply tells us if we're
// currently in an overlapping state.
Copy link
Contributor

Choose a reason for hiding this comment

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

nits: should the comment go here, or with the method? also, sentence casing

Copy link
Contributor Author

@cmslewis cmslewis Mar 21, 2017

Choose a reason for hiding this comment

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

This is a special usage of the helper function, so I think it makes sense to keep the comment only here.

We don't do sentence casing in comments AFAIK, unless it's a prop-description comment.

@giladgray giladgray merged commit a9667a3 into master Mar 21, 2017
@giladgray giladgray deleted the cl/dri-allow-single-day-range branch March 21, 2017 22:30
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.

4 participants