-
Notifications
You must be signed in to change notification settings - Fork 6.8k
fix(datepicker): allow ISO 8601 strings as inputs #7091
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
Conversation
| * @returns The ISO date string date string. | ||
| */ | ||
| abstract getISODateString(date: D): string; | ||
| abstract toISODateString(date: D): string; |
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.
Since you're changing this anyway, toIsoDateString?
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.
How opposed would you be to making these toIso8601 and fromIso8601?
| } | ||
|
|
||
| fromISODateString(iso8601String: string): Date | null { | ||
| if (iso8601String.match(ISO_8601_REGEX)) { |
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.
Why do you need to do the check first? (comment?)
src/lib/datepicker/calendar.ts
Outdated
| * Attempts to coerce a property to a date by parsing it as a ISO 8601 string. If not a valid | ||
| * ISO 8601 string, returns the original vlaue. | ||
| */ | ||
| private _coerceDateProperty(value: any): any { |
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.
Should this return D?
src/lib/datepicker/calendar.ts
Outdated
| @Input() startAt: D; | ||
| @Input() | ||
| get startAt(): D { return this._startAt; } | ||
| set startAt(value: D) { this._startAt = this._coerceDateProperty(value); } |
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.
Is it weird that the user could do
picker.startAt = '1985-04-12T23:20:50.52Z';
console.log(picker.startAt); // is a different type?
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.
Kind of? but its the same idea as all of the boolean and number properties that we coerce
| ].join('-'); | ||
| } | ||
|
|
||
| fromISODateString(iso8601String: string): Date | null { |
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.
Why isn't this captured as part of the normal parse function?
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.
This is more of a deserialization than parsing user input
src/lib/datepicker/datepicker.ts
Outdated
| * Attempts to coerce a property to a date by parsing it as a ISO 8601 string. If not a valid | ||
| * ISO 8601 string, returns the original vlaue. | ||
| */ | ||
| private _coerceDateProperty(value: any): any { |
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.
Could we avoid repeating this code?
| * @returns The ISO date string date string. | ||
| */ | ||
| abstract getISODateString(date: D): string; | ||
| abstract toISODateString(date: D): string; |
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.
How opposed would you be to making these toIso8601 and fromIso8601?
| } | ||
|
|
||
| fromISODateString(iso8601String: string): Date | null { | ||
| if (iso8601String.match(ISO_8601_REGEX)) { |
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.
Use either String.prototype.search or RegExp.prototype.test rather than match
027be57 to
9a5df88
Compare
|
comments addressed, PTAL |
jelbourn
left a comment
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.
LGTM
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
This is useful for apps that load a bunch of JSON data and want to stuff it into a form
fixes #6265
BREAKING CHANGES:
DateAdapter.getISODateStringis nowDateAdapter.toIso8601DateAdapternow has a new abstract methodDateAdapter.fromIso8601