-
Notifications
You must be signed in to change notification settings - Fork 6.7k
fix(datepicker): min-date/max-date: parse fix for literals #4841
Conversation
c999d16
to
e0673b0
Compare
e0673b0
to
be83344
Compare
Fix formatting - an easy way to see what is off is to rebase off of current |
var date = parseDate(value); | ||
if(!date) { | ||
var tryDate = new Date(value); | ||
if(angular.isDate(tryDate) && !isNaN(tryDate)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens when isNaN(tryDate)
is true
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
undefined
gets set.... this is to cover for an invalid attribute; example: a scope variable that doesn't exist.
be83344
to
f2c1906
Compare
Not sure what formatting needs fixing. I rebased and ran |
As a rule of thumb, the code should look like the surrounding code - the whitespace differences are pretty stark in this case, or lack of whitespace. |
Thinking about this problem for a bit, I am not sure we want to support this date format in the long run - it would be much better if it required a date object from the user's side as a breaking change, which would prevent the timezone issue, and allow the user the flexibility to specify the timezone of the min date. |
9b425ab
to
5cef4c8
Compare
if (!date) { | ||
date = new Date(value); | ||
if (angular.isDate(date) && !isNaN(date)) { | ||
var dateArray = date.toISOString().split('T')[0].split('-'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One can get the information from the date via this mechanism:
var year = date.getFullYear(),
month = date.getMonth(),
day = date.getDate();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the reason I'm using the toISOString()
(I plan to switch to equivalent toJSON()
next commit) is to get the UTC version of the date, otherwise there is the same timezone issue we are seeing in #3437... the date for EST looks something like 9PM the day before, and the date becomes off by 1.
5cef4c8
to
495e91f
Compare
if (!date) { | ||
date = new Date(value); | ||
if (angular.isDate(date) && !isNaN(date)) { | ||
var dateArray = date.toJSON().split('T')[0].split('-'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As stated prior, one can get the information from the date via this mechanism:
var year = date.getFullYear(),
month = date.getMonth(),
day = date.getDate();
This is a better way of getting the date information
9fb5910
to
910654a
Compare
c5cf4d4
to
84d6137
Compare
Changed the code to simply parse dates:
This fixes the underlying problem in issue #3437, which is that javascript parses |
8aaa918
to
96f36d0
Compare
Just realized that the concepts of display format and alt-input-formats does not exist for the datepicker itself. So, this would still be an issue for the datepicker proper; and, the different behavior of min-date/max-date would be confusing. |
96f36d0
to
a449598
Compare
a449598
to
8a7eb90
Compare
8a7eb90
to
07e0970
Compare
OK. Switched to using |
@wesleycho would you re-review? |
Only thing I hesitate on is the assumption of the |
The medium format is an internal format picked "at random"... Any format that indicates all the possible date information would do the trick. It doesn't impact the parse work. |
Guess I'm fine with it - LGTM then |
fixes #3437
original plunker, with pr code: http://plnkr.co/edit/jsfOVBZj51yajpZYkC9N?p=preview
maintainer plunker, with pr code: http://plnkr.co/edit/buQXUxndajMYFOZorzq9?p=preview