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

feat(material/datepicker): add getValidDateOrNull method #19915

Merged
merged 1 commit into from
Jul 29, 2020

Conversation

swseverance
Copy link
Contributor

Several components have identical implementations of a _getValidDateOrNull method. This PR reduces code duplication by adding a getValidDateOrNull to the DateAdapter class for the components to use instead.

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Jul 8, 2020
Copy link
Contributor

@mmalerba mmalerba left a comment

Choose a reason for hiding this comment

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

Nice, thanks for the cleanup!

@mmalerba mmalerba added lgtm action: merge The PR is ready for merge by the caretaker target: minor This PR is targeted for the next minor release labels Jul 8, 2020
@mmalerba
Copy link
Contributor

mmalerba commented Jul 8, 2020

@swseverance can you update the API golden by running yarn bazel run //tools/public_api_guard:material/core.d.ts_api.accept

@swseverance
Copy link
Contributor Author

swseverance commented Jul 8, 2020

@mmalerba done. Thanks

Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

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

The prefix for this commit should be feat(material/datepicker)

* @param obj The object to check.
* @returns The given object if it is both a date instance and valid, otherwise null.
*/
getValidDateOrNull(obj: any): D | null {
Copy link
Member

Choose a reason for hiding this comment

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

I believe this should be unknown instead of any
(unknown didn't exist back when we first made the DateAdapter)

@@ -203,6 +203,14 @@ export abstract class DateAdapter<D> {
*/
abstract invalid(): D;

/**
Copy link
Member

Choose a reason for hiding this comment

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

In addition to @param and @returns, this method should have a description, something like

 /**
  * Given a potential date object, returns that same date object if it is
  * a valid date, or `null` if it's not a valid date.
  * @param ...
  * @returns ...
  */

it('should provide a method to return a valid date or null', () => {
let d = new Date();
expect(adapter.getValidDateOrNull(d)).toBe(d);
expect(adapter.getValidDateOrNull(new Date(NaN))).toBeNull();
Copy link
Member

Choose a reason for hiding this comment

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

I would probably also add cases for null, undefined, '', 0, a date string, and a timestamp just to be comprehensive.

@jelbourn jelbourn removed the action: merge The PR is ready for merge by the caretaker label Jul 8, 2020
Several components have identical implementations of a `_getValidDateOrNull` method. This PR reduces code duplication by adding a `getValidDateOrNull` method to the `DateAdapter` class for the components to use instead.
@swseverance
Copy link
Contributor Author

@jelbourn I made the requested changes.

@swseverance swseverance changed the title refactor(date-adapter): add getValidDateOrNull method feat(material/datepicker): add getValidDateOrNull method Jul 9, 2020
@mmalerba mmalerba added the action: merge The PR is ready for merge by the caretaker label Jul 9, 2020
Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

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

LGTM

@jelbourn jelbourn merged commit f0e56f0 into angular:master Jul 29, 2020
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Aug 29, 2020
@swseverance swseverance deleted the refactor/date-adapter branch August 29, 2020 12:50
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants