Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

feat(timepicker): Added min/max attributes to timepicker.#4019

Closed
mikeknoll wants to merge 5 commits intoangular-ui:masterfrom
mikeknoll:master
Closed

feat(timepicker): Added min/max attributes to timepicker.#4019
mikeknoll wants to merge 5 commits intoangular-ui:masterfrom
mikeknoll:master

Conversation

@mikeknoll
Copy link
Contributor

Adds attributes for timepicker's min and max time.

@wesleycho
Copy link
Contributor

That is what min-date and max-date are for.

@wesleycho
Copy link
Contributor

I apologize, this is for a different component than I thought - I will review this.

@wesleycho wesleycho self-assigned this Jul 27, 2015
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any reason why newDate can't just get returned? It should already be an independent reference.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Date.setHours() returns an int, not a Date for some reason. I returned new Date( newDate ) to convert the int back into a Date.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I see now.

It would likely be more efficient to do

var newDate = new Date( date.getTime() + minutes * 60000 );
newDate.setHours( dt.getHours(), dt.getMinutes() );
return newDate;

The dt date existed as a temporary structure to figure out how to modify the existing selected date, but now we can just return the date of interest

@wesleycho
Copy link
Contributor

Thanks for this, this is mostly solid work - I do have two comments that should be addressed before this is merged.

@wesleycho wesleycho added this to the Backlog milestone Jul 30, 2015
@wesleycho wesleycho removed their assignment Jul 31, 2015
@mikeknoll
Copy link
Contributor Author

I believe I addressed your concerns. I was able to remove an instance of Date in addMinutes(), slightly different than your suggest because it needs to "rollover" from 11:59PM to 12:00AM on the same day, not the next.

I removed the unnecessary conditionals on $attrs.min/max.

Copy link
Contributor

Choose a reason for hiding this comment

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

So what I meant was more return (max && incrementedSelected > max) || incrementedSelected < selected;, and so on.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The logic is a bit different than that. incrementedSelected > max is catching the common case, increasing the time would exceed the max. If max is undefined, incrementedSelected > max will be false, which is what we want(to allow the increase).

The other part, (min && incrementedSelected < selected) was intended to disable the increment/decrement if the time would rollover(at midnight) if the opposite direction's wouldn't be allowed. For example, if it is 11:30pm, you cannot increase to 12:30am if the minimum is 1:00am.

This code isn't quite there though. This just prevents a rollover if the minimum/maximum is defined. For example, if it is 11:30pm, you cannot increase to 12:30am if the minimum is 12:01am. This should be allowed, as the updated time is still later than the minimum.

I believe the correct code will be return incrementedSelected > max || (incrementedSelected < selected && incrementedSelected < min);. I've manually tested it. I'll write up some unit tests and submit it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto

@wesleycho
Copy link
Contributor

Once these changes are in, this is good to go.

@wesleycho wesleycho modified the milestones: 0.13.x, Backlog Aug 5, 2015
@mikeknoll
Copy link
Contributor Author

I updated the style, and changed the noIncremenentHours() etc... to disable the time step in a direction if when time rolls over, the result exceeds the limit for movement in the opposite direction.

@wesleycho
Copy link
Contributor

LGTM - merging shortly with documentation & code style fixes.

@wesleycho wesleycho closed this in 6c0010b Aug 7, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants