Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

feat(datepicker): allow date strings as the source for ng-model #9554

Merged
merged 1 commit into from Feb 22, 2017

Conversation

crisbeto
Copy link
Member

@crisbeto crisbeto commented Sep 8, 2016

This change adds the ability to have a date string (e.g. "2016-01-02") as the source for the datepicker. Until now only Date objects were allowed.

Fixes #6253.
Fixes #9535.

@crisbeto crisbeto added the needs: review This PR is waiting on review from the team label Sep 8, 2016
var parsedValue = angular.isDefined(value) ? Date.parse(value) : null;

if (parsedValue) {
value = self.dateLocale.parseDate(parsedValue);
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this redundant with Date.parse(value) above? Also, mdDateLocaleProvider.parseDate should expect a string as well, and we're passing a Date Number object here.

Copy link
Member Author

@crisbeto crisbeto Sep 8, 2016

Choose a reason for hiding this comment

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

The difference between Date.parse and new Date is that parse is a little more strict about what it accepts. E.g. the constructor will parse null, false, etc. into January 1st 1970, whereas parse will consider them invalid. Also parse returns the time since epoch, which is why it needs to be passed through parseDate.

As for the reason why it's not doing the logic in parseDate, it's because this should only be done when something, different from the directive, modifies the model.

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, I see. If it isn't too much trouble, since you're making a change for L#407, perhaps you can renamed the variable as parsedNumber to explain that a number is expected to return. I didn't realize Date.parse returned a Number the first time I saw it. That makes more sense knowing that L#408 will convert the Number object into a Date object.

Copy link
Member Author

Choose a reason for hiding this comment

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

Just did as a part of the change to the comparison.

@crisbeto crisbeto force-pushed the 9535/date-string branch 3 times, most recently from 85c3528 to f1c92cb Compare September 8, 2016 22:32
@ThomasBurleson
Copy link
Contributor

@topherfangio - plz review.

'Currently the model is a: ' + (typeof value));
throw Error(
'The ng-model for md-datepicker must be a Date instance or a value ' +
'that can be parsed into a date. Currently the model is a: ' + typeof value
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: Change Currently the model is a to Current model: because if it's an Array it should be an instead of a.

@ThomasBurleson
Copy link
Contributor

@crisbeto - please confirm this PR is still valid/needed. And rebase to lastest in master.
Thank you.

@ThomasBurleson ThomasBurleson added needs: rebase This PR needs to be rebased on the latest commits from master and conflicts need to be resolved and removed needs: review This PR is waiting on review from the team labels Jan 1, 2017
@ThomasBurleson ThomasBurleson modified the milestone: 1.1.3 Jan 1, 2017
This change adds the ability to have a date string (e.g. "2016-01-02") as the source for the datepicker. Until now only Date objects were allowed.

Fixes angular#6253.
Fixes angular#9535.
@googlebot googlebot added the cla: yes PR author has signed Google's CLA: https://opensource.google.com/docs/cla/ label Jan 1, 2017
@crisbeto
Copy link
Member Author

crisbeto commented Jan 1, 2017

Rebased @ThomasBurleson.

@crisbeto crisbeto added needs: review This PR is waiting on review from the team and removed needs: rebase This PR needs to be rebased on the latest commits from master and conflicts need to be resolved labels Jan 1, 2017
@ThomasBurleson ThomasBurleson modified the milestones: 1.1.3, 1.2.0 Jan 3, 2017
Copy link
Contributor

@AdriVanHoudt AdriVanHoudt left a comment

Choose a reason for hiding this comment

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

LGTM

@ThomasBurleson ThomasBurleson modified the milestones: 1.1.3, 1.2.0 Jan 6, 2017
@ThomasBurleson ThomasBurleson added needs: presubmit and removed needs: review This PR is waiting on review from the team labels Jan 6, 2017
@ThomasBurleson
Copy link
Contributor

LGTM

@ThomasBurleson ThomasBurleson modified the milestones: 1.1.3, 1.1.4 Feb 4, 2017
@mmalerba mmalerba merged commit e7de21d into angular:master Feb 22, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes PR author has signed Google's CLA: https://opensource.google.com/docs/cla/
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants