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

Fix null reference error for invalid times #371

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

herrkoch
Copy link

Prevents null reference error in parsedTime.toISOTime().replace() if parsedTime is invalid.

Fixes #349

Prevents null reference error in parsedTime.toISOTime().replace() if parsedTime is invalid
@@ -25,7 +25,9 @@ export class TimeAdapter {
}
const {format} = opts;
const parsedTime = TimeAdapter.parseTime(time, opts).setLocale(TimeAdapter.DEFAULT_LOCALE);

if (parsedTime.invalid) {
return null;
Copy link
Author

Choose a reason for hiding this comment

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

I'd like to point out that I prefer null here over 'Invalid Time', otherwise the invalid value entered by the user will be replaced with 'Invalid Time' in the input field, which is not nice as the user won't be able to correct his/her mistake. I'd leave it to the developer to put form validation on the input field.

herrkoch and others added 2 commits October 16, 2020 17:37
invalid is not a public field of the luxon.DateTime class, instead isValid should be used
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants